EVP_SIGNINIT(3ossl)
π EVP_SIGNINIT β bestie edition π
okay so you opened the EVP_SignInit man page from the OpenSSL crew (that's 3ossl, the whole family of pages) and you're like "what is this". don't worry, i got you. sit down, hydrate, let's talk about signing things. β¨
β¨ NAME β¨
EVP_SignInit, EVP_SignInit_ex, EVP_SignUpdate, EVP_SignFinal_ex, EVP_SignFinal β the EVP signing girlies. digital signatures, high level, no drama. π«Ά
π 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 πΈ
The EVP signature routines are a high-level interface to digital signatures. like, the glow-up version. the main character version. π₯
EVP_SignInit_ex()β sets up signing contextctxto use digesttypefromENGINEimpl. lowkey important:ctxmust be created withEVP_MD_CTX_new()before you call this. no context, no vibes.EVP_SignUpdate()β hashescntbytes of data atdinto the signature contextctx. you can call this multiple times on the samectxto keep adding more data. it's giving "keep going bestie". πEVP_SignFinal_ex()β signs the data inctxusing the private keypkeyand puts the signature insig. the library contextlibctxand property querypropqget used when creating a context to use with the keypkey.sigmust be at leastEVP_PKEY_get_size(pkey)bytes in size.sis an OUT parameter β not used as an IN parameter, okay? don't put anything in there expecting it to matter. the number of bytes of data written (i.e. the length of the signature) gets written to the integer ats, and at mostEVP_PKEY_get_size(pkey)bytes will be written. β¨EVP_SignFinal()β same asEVP_SignFinal_ex()but it uses default values ofNULLfor the library contextlibctxand the property querypropq. the "just use the defaults, it's fine" option. π¦EVP_SignInit()β initializes a signing contextctxto use the default implementation of digesttype.
π 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. β
/β
The error codes can be obtained by ERR_get_error(3). go read that one if something went wrong, it will tell you what. π
π§ NOTES π§
The EVP interface to digital signatures should almost always be used in preference to the low-level interfaces. why? because your code then becomes transparent to the algorithm used and much more flexible. it's called being adaptable, bestie. π
When signing with some private key types the random number generator must be seeded. If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to external circumstances (see RAND(7)), the operation will fail. π (not your fault, but still. the operation will fail.)
The call to EVP_SignFinal() internally finalizes a copy of the digest context. this means that calls to EVP_SignUpdate() and EVP_SignFinal() can be called later to digest and sign additional data.cApplications may disable this behavior by setting the EVP_MD_CTX_FLAG_FINALISE context flag via EVP_MD_CTX_set_flags(3). π
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() or a memory leak will occur. not the cute kind of leak. clean up after yourself, babe. π
Note that not all providers support continuation. in case the selected provider does not allow to duplicate contexts, EVP_SignFinal() will finalize the digest context and attempting to process additional data via EVP_SignUpdate() will result in an error. iykyk. π
π BUGS π
Older versions of this documentation wrongly stated that calls to EVP_SignUpdate() could not be made after calling EVP_SignFinal(). they lied. moving on. π
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(). like, you do all the work and then it tells you no. brutal. π
It is not possible to change the signing parameters using these functions. periodt.
The previous two bugs are fixed in the newer EVP_DigestSign*() functions. slay. go use those if you can. π
π¦ 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)
β HISTORY β
The function EVP_SignFinal_ex() was added in OpenSSL 3.0. newer, shinier, iconic. β¨
π 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>.
and that's the whole page, bestie!! π no cap, you now know more about EVP_SignInit than most of the internet. this was OpenSSL 3.5.9, dated 2026-09-29 β love that for us. now go forth and sign things responsibly. mwah. ππ
π«Ά
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms