EVP_SIGNINIT(3)
π EVP_SIGNINIT(3) β Library Functions Manual π
okay bestie, welcome to the Library Functions Manual page for EVP_SignInit_ex, EVP_SignUpdate, EVP_SignFinal and EVP_SignInit β the whole little friend group of EVP signing functions π«Ά pull up a chair, we're signing things today.
β¨ NAME β¨
EVP_SignInit_ex, EVP_SignUpdate, EVP_SignFinal, EVP_SignInit β the EVP signing functions, no cap π
πΈ SYNOPSIS πΈ
calling all libcrypto girlies β library βlibcryptoβ
#include <openssl/evp.h>
int
EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *engine);
int
EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
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 literally a high-level interface to digital signatures. main character energy only, we don't do low-level here π
EVP_SignInit_ex() sets up the signing context ctx to use the digest type. but listen β before you call this, you gotta obtain ctx from EVP_MD_CTX_new(3) or call EVP_MD_CTX_reset(3) on it first, that's the vibe check. the engine argument is always ignored (yes, always, not even kidding) and passing NULL is the recommended move β¨
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 include additional data β feed it data in lil chunks, it eats π
EVP_SignFinal() signs the data in ctx using the private key pkey and places the signature in sig. important: sig must be at least EVP_PKEY_size(3) bytes big, don't be out here with a tiny buffer π s is an OUT parameter, and it's not used as an IN parameter β so don't put anything in it expecting it to matter. 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_size(3) bytes will be written. periodt.
EVP_SignInit() initializes a signing context ctx to use the default implementation of digest type.
real talk though: the EVP interface to digital signatures should almost always be used in preference to the low-level interfaces. why? because your code becomes transparent to the algorithm used and is much more flexible β iconic behaviour only π
okay this next bit is the detail nobody clocks: the call to EVP_SignFinal() internally finalizes a copy of the digest context. which means calls to EVP_SignUpdate() and EVP_SignFinal() can be made later to digest and sign additional data. so you're not locked out after the first final β love that for you π
β οΈ but bestie, since only a copy of the digest context is ever finalized, you must clean up the context after use by calling EVP_MD_CTX_free(3) β otherwise a memory leak happens and we do NOT want that energy π
and one more thing: EVP_SignInit_ex(), EVP_SignUpdate(), and EVP_SignInit() are implemented as macros. iykyk π
β RETURN VALUES β
EVP_SignInit_ex(),EVP_SignUpdate(), andEVP_SignFinal()return1for success and0for failure. simple as that, no plot twist π
if you need the error codes, get them with ERR_get_error(3) β that's where the receipts live π§Ύ
π SEE ALSO π
go read those next, you'll thank me π
π HISTORY π
EVP_SignInit(), EVP_SignUpdate(), and EVP_SignFinal() first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4. vintage icons fr fr π°οΈ
EVP_SignInit_ex() first appeared in OpenSSL 0.9.7 and has been available since OpenBSD 3.2. the newer sibling, also iconic π
π BUGS π
- okay so older versions of this documentation wrongly stated that calls to
EVP_SignUpdate()could not be made after callingEVP_SignFinal(). that was a lie, we've moved on π - because 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 throughEVP_SignUpdate(). so you could push a whole lotta data through and then find out π - it is not possible to change the signing parameters using these functions. nope. can't do it.
π‘ good news though β the previous two bugs are fixed in the newer EVP_DigestSign* function. slay for progress π¦
and that's the whole page bestie!! mwah π this little gem lives in the Debian build of the page, dated June 8, 2025, filed under EVP_SIGNINIT(3) β go sign something cute, and don't forget to EVP_MD_CTX_free(3) π«Άβ¨
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2000-2002, 2005, 2006, 2014-2016 The OpenSSL Project
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms