EVP_VERIFYINIT(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’– EVP_VERIFYINIT(3) πŸ’–

okay so this is the libcrypto manual page β€” yes, the crypto library one, from the Library Functions Manual squad β€” and it's all about the EVP signature verification girlies. buckle up bestie, we're checking signatures πŸ”₯


✨ NAME ✨

EVP_VerifyInit_ex, EVP_VerifyUpdate, EVP_VerifyFinal, EVP_VerifyInit β€” the EVP signature verification functions. literally the whole friend group 🫢


🌸 SYNOPSIS 🌸

library β€œlibcrypto” #include <openssl/evp.h>

int
EVP_VerifyInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *engine);

int
EVP_VerifyUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);

int
EVP_VerifyFinal(EVP_MD_CTX *ctx, unsigned char *sigbuf,
    unsigned int siglen, EVP_PKEY *pkey);

int
EVP_VerifyInit(EVP_MD_CTX *ctx, const EVP_MD *type);

πŸ¦‹ DESCRIPTION πŸ¦‹

The EVP signature verification routines are a high-level interface to digital signatures. high-level!! we love not touching the low-level machinery directly πŸ’…

  • EVP_VerifyInit_ex() β€” sets up the verification context ctx to use the digest type. Before you call this, you gotta obtain ctx from EVP_MD_CTX_new(3) or call EVP_MD_CTX_reset(3) on it. and the engine argument? it's always ignored, so passing NULL is what's recommended. that param is giving background character energy ngl πŸ™ˆ
  • EVP_VerifyUpdate() β€” hashes cnt bytes of data at d into the verification context ctx. you can call this several times on the same ctx to include additional data β€” yes, multiple times, go off, feed it more πŸ“
  • EVP_VerifyFinal() β€” verifies the data in ctx using the public key pkey, and against the siglen bytes at sigbuf. the final boss check πŸ‘‘
  • EVP_VerifyInit() β€” initializes a verification context ctx to use the default implementation of digest type.

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. it's giving main character energy, fr fr ✨

The call to EVP_VerifyFinal() internally finalizes a copy of the digest context. which means calls to EVP_VerifyUpdate() and EVP_VerifyFinal() can be called later to digest and verify additional data. copy, not the original β€” that's the whole trick, iykyk πŸ’œ

⚠️ 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(3), or a memory leak will occur. not a leak bestie, a whole situation 😭 clean up after yourself!!

also important: EVP_VerifyInit_ex(), EVP_VerifyUpdate(), and EVP_VerifyInit() are implemented as macros. so don't be weird about taking their address or whatever πŸŽ€


🌈 RETURN VALUES 🌈

  • EVP_VerifyInit_ex() and EVP_VerifyUpdate() β€” return 1 for success and 0 for failure. simple girlie pop logic πŸ’–
  • EVP_VerifyFinal() β€” returns 1 for a correct signature, 0 for failure, and -1 if some other error occurred. three whole moods πŸ’€

The error codes can be obtained by ERR_get_error(3). go read them, they'll tell you what's up ⭐


🧚 SEE ALSO 🧚

evp(3), EVP_DigestInit(3), EVP_SignInit(3) β€” the rest of the friend group, go say hi 🫢


πŸ‘‘ HISTORY πŸ‘‘

EVP_VerifyInit(), EVP_VerifyUpdate(), and EVP_VerifyFinal() first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4. ancient icons, genuinely πŸ›οΈ

EVP_VerifyInit_ex() first appeared in OpenSSL 0.9.7 and has been available since OpenBSD 3.2. the newer sibling, still lowkey vintage 🌸


πŸ’€ BUGS πŸ’€

Older versions of this documentation wrongly stated that calls to EVP_VerifyUpdate() could not be made after calling EVP_VerifyFinal(). wrong!! the docs were lying to you, and this page is the correction 🩹

Since the public key is passed in the call to EVP_SignFinal(3), 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(3). so like... you do all this work and then it tells you the key was bad. brutal 😭

It is not possible to change the signing parameters using these functions. nope, no take-backs, no edits πŸ™ˆ

The previous two bugs are fixed in the newer functions of the EVP_DigestVerifyInit(3) family. so if you want the fixed-up glow-up versions, that's where they're at πŸ”₯


and that's the page bestie!! πŸ’…βœ¨ this one shipped in the Debian edition, dated June 8, 2025 β€” so go verify some signatures responsibly, and remember: free your context when you're done with it. mwah πŸŽ€πŸ’–

πŸ“¦ where this page comes from