EVP_SIGNINIT(3ossl)
π EVP_SIGNINIT β like, the signing girlies of OpenSSL π
okay bestie, so this is the EVP_SIGNINIT(3ossl) page from the OpenSSL manual β yes, that OpenSSL, the one your whole internet runs on β¨ β and today we're learning about the EVP signing functions. it's giving "high-level crypto but make it cute". let's go π
β¨ NAME β¨
EVP_SignInit, EVP_SignInit_ex, EVP_SignUpdate, EVP_SignFinal_ex, EVP_SignFinal β the whole EVP signing squad, together at last π«Ά
πΈ SYNOPSIS πΈ
#include <openssl/evp.h>
int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
int EVP_SignFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s,
EVP_PKEY *pkey, OSSL_LIB_CTX *libctx, const char *propq);
int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sig, unsigned int *s,
EVP_PKEY *pkey);
void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type);
π DESCRIPTION π
so the EVP signature routines are, like, the high-level interface to digital signatures. main character energy only, no cap π
EVP_SignInit_ex() sets up the signing context ctx to use digest type from ENGINE impl. and bestie, listen β ctx must be created with EVP_MD_CTX_new() before you call this. no context, no signing, periodt.
EVP_SignUpdate() hashes cnt bytes of data at d into the signature context ctx. and the slay part? you can call this several times on the same ctx to keep adding more data. feed the girl data, she eats π₯
EVP_SignFinal_ex() signs the data in ctx using the private key pkey and drops the signature into sig. the library context libctx and property query propq are used when creating a context to use with the key pkey. sig must be at least EVP_PKEY_get_size(pkey) bytes in size (no squeezing, she needs room π«Ά). s is an OUT parameter and it is not used as an IN parameter β literally out only, do not put stuff in there. the number of bytes of data written (i.e. the length of the signature) gets written to the integer at s, and at most EVP_PKEY_get_size(pkey) bytes will be written.
EVP_SignFinal() is the same vibe as EVP_SignFinal_ex() but it uses the default values of NULL for the library context libctx and the property query propq. lowkey the chill version π
EVP_SignInit() initializes a signing context ctx to use the default implementation of digest type.
π¦ RETURN VALUES π¦
EVP_SignInit_ex(), EVP_SignUpdate(), EVP_SignFinal_ex() and EVP_SignFinal() return 1 for success and 0 for failure. that's it, that's the whole vibe check π
and if you wanna know why it flopped, the error codes can be obtained by ERR_get_error(3).
π§ NOTES π§
the EVP interface to digital signatures should almost always be used in preference to the low-level interfaces. why? because the code then becomes transparent to the algorithm used and much more flexible. she's adaptable, she's iconic, she's serving range π
when signing with some private key types, the random number generator must be seeded. and if the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to external circumstances (see RAND(7)), the operation will fail. no seeds, no signature, sorry babe π
the call to EVP_SignFinal() internally finalizes a copy of the digest context. this means calls to EVP_SignUpdate() and EVP_SignFinal() can be called later to digest and sign additional data. applications may disable this behavior by setting the EVP_MD_CTX_FLAG_FINALISE context flag via EVP_MD_CTX_set_flags(3).
π¨ and since only a copy of the digest context is ever finalized, the context must be cleaned up after use by calling EVP_MD_CTX_free() β otherwise you get a memory leak. clean up after yourself, bestie, it's basic hygiene π
also note: not all providers support continuation. if the selected provider does not allow duplicating contexts, EVP_SignFinal() will finalize the digest context, and attempting to process additional data via EVP_SignUpdate() will result in an error. read the room, basically π
π BUGS π
older versions of this documentation wrongly stated that calls to EVP_SignUpdate() could not be made after calling EVP_SignFinal(). that was a lie, we don't stan misinformation β
since the private key is passed in the call to EVP_SignFinal(), any error relating to the private key (for example an unsuitable key and digest combination) will not be indicated until after potentially large amounts of data have been passed through EVP_SignUpdate(). so likeβ¦ you find out late. awkward π¬
it is not possible to change the signing parameters using these functions. nope, no take-backs.
and the good news: the previous two bugs are fixed in the newer EVP_DigestSign*() functions. glow-up achieved β¨
π SEE ALSO π
EVP_PKEY_get_size(3), EVP_PKEY_get_bits(3), EVP_PKEY_get_security_bits(3), EVP_VerifyInit(3), EVP_DigestInit(3), evp(7), HMAC(3), MD2(3), MD5(3), MDC2(3), RIPEMD160(3), SHA1(3), openssl-dgst(1) β go read the whole friend group, they all ate π
β HISTORY β
the function EVP_SignFinal_ex() was added in OpenSSL 3.0. new entry, fresh on the scene π
π COPYRIGHT π
Copyright 2000-2023 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
aaaand that's the page!! π«Ά this was version 3.5.0, dated 2026-09-25, straight from the OpenSSL girlies themselves β thanks for reading bestie, go sign something gorgeous πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms