EVP_DIGESTVERIFYINIT(3SSL)
π EVP_DigestVerifyInit π
okay bestie, gather round, because today we're learning about the EVP signature verification girlies in OpenSSL β yes, the <openssl/evp.h> ones. Manual page EVP_DigestVerifyInit(3SSL), and it's giving "I check signatures so you don't have to" energy. π
β¨ NAME β¨
EVP_DigestVerifyInit_ex, EVP_DigestVerifyInit, EVP_DigestVerifyUpdate, EVP_DigestVerifyFinal, EVP_DigestVerify β the EVP signature verification functions. That's the whole squad. π
πΈ SYNOPSIS πΈ
#include <openssl/evp.h>
int EVP_DigestVerifyInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
const char *mdname, OSSL_LIB_CTX *libctx,
const char *props, EVP_PKEY *pkey,
const OSSL_PARAM params[]);
int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
size_t siglen);
int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sig,
size_t siglen, const unsigned char *tbs, size_t tbslen);
π¦ DESCRIPTION π¦
So the EVP signature routines are basically the high-level, main-character interface to digital signatures. The vibe is simple: your input data gets digested first, and then the signature verification happens. Digest first, verify second, no cap. β¨
EVP_DigestVerifyInit_ex()
This one sets up your verification context ctx to use a digest with the name mdname plus the public key pkey. And here's the tea: the name of the digest gets handed off to the provider of the signature algorithm in use. How that provider interprets the digest name is β you guessed it β provider specific. π
The provider might:
- implement that digest directly itself, or
- (optionally) choose to fetch it β which could end up selecting a digest from a different provider π
If the provider supports fetching the digest, then it may use the props argument for the properties to be used during the fetch. And finally, the passed parameters params, if not NULL, get set on the context before returning.
The pkey algorithm is used to fetch an EVP_SIGNATURE method implicitly, and that's what gets used for the actual signing. Want the full lore on implicit fetches? Go read "Implicit fetch" in provider(7). π
Now the provider gossip:
- The
OpenSSLdefault and legacy providers support fetching digests, and they can fetch those digests from any available provider. - The
OpenSSLFIPS provider also supports fetching digests, but it will only fetch digests that are themselves implemented inside the FIPS provider. Picky! π
ctx must be created with EVP_MD_CTX_new() before you call this function. Do not skip that step, bestie.
If pctx is not NULL, the EVP_PKEY_CTX of the verification operation gets written to *pctx β super handy, because that's how you set alternative verification options.
β οΈ Heads up: any existing value in *pctx is overwritten. Gone. Poof. π«Ά
Also, the EVP_PKEY_CTX value returned must not be freed directly by the application if ctx is not assigned an EVP_PKEY_CTX value before being passed to EVP_DigestVerifyInit_ex() β which basically means the EVP_PKEY_CTX is created inside EVP_DigestVerifyInit_ex() and it will be freed automatically when the EVP_MD_CTX is freed. So don't you dare free it yourself. π€
And if the EVP_PKEY_CTX to be used is created by EVP_DigestVerifyInit_ex, then it'll use the OSSL_LIB_CTX specified in libctx and the property query string specified in props.
No EVP_PKEY_CTX will be created by EVP_DigestVerifyInit_ex() if the passed ctx has already been assigned one via EVP_MD_CTX_set_pkey_ctx(3). See also SM2(7). π
π§ Which digests can go with which key types π§
Not all digests can be used for all key types, bestie. The following combinations apply:
- DSA β Supports
SHA1,SHA224,SHA256,SHA384andSHA512 - ECDSA β Supports
SHA1,SHA224,SHA256,SHA384,SHA512andSM3 - RSA with no padding β Supports no digests (the digest type must be
NULL) - RSA with X931 padding β Supports
SHA1,SHA256,SHA384andSHA512 - All other RSA padding types β Support
SHA1,SHA224,SHA256,SHA384,SHA512,MD5,MD5_SHA1,MD2,MD4,MDC2,SHA3-224,SHA3-256,SHA3-384,SHA3-512 - Ed25519 and Ed448 β Support no digests (the digest type must be
NULL) - HMAC β Supports any digest
- CMAC, Poly1305 and Siphash β Will ignore any digest provided. Ignoring. As they should. π
Also, if RSA-PSS is used and restrictions apply, then the digest must match. No mixing and matching, babe.
EVP_DigestVerifyInit()
Works the exact same way as EVP_DigestVerifyInit_ex(), except: the mdname parameter gets inferred from the supplied digest type, and props will be NULL. Oh, and e must be NULL. That's it, that's the whole difference. π
EVP_DigestVerifyUpdate()
Hashes cnt bytes of data at d into the verification context ctx. You can call this several times on the same ctx to pile on additional data. Feed it, feed it, feed it. π
EVP_DigestVerifyFinal()
Verifies the data in ctx against the signature in sig of length siglen. The moment of truth. β
EVP_DigestVerify()
Verifies tbslen bytes at tbs against the signature in sig of length siglen. One shot, done. π₯
π RETURN VALUES π
EVP_DigestVerifyInit() and EVP_DigestVerifyUpdate() return 1 for success and 0 for failure. Simple. Clean.
EVP_DigestVerifyFinal() and EVP_DigestVerify() return 1 for success; any other value indicates failure. And here's the nuance bestie, don't skip this:
- A return value of zero means the signature did not verify successfully β that is,
tbsdid not match the original data, or the signature had an invalid form. - Other values indicate a more serious error (and sometimes they also indicate an invalid signature form).
The error codes can be obtained from 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 so much more flexible. It's giving glow-up. β¨
EVP_DigestVerify() is a one shot operation β it verifies a single block of data in one function. For algorithms that support streaming, it's equivalent to calling EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal(). But for algorithms that don't support streaming (e.g. PureEdDSA), it's the only way to verify data. The one and only. π
In previous versions of OpenSSL there was a link between message digest types and public key algorithms. That meant "clone" digests such as EVP_dss1() needed to be used to sign using SHA1 and DSA. This is no longer necessary, and the use of clone digest is now discouraged. We don't do that anymore, babe. π
For some key types and parameters 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. Not us being dramatic, that's just how it is. π
The call to EVP_DigestVerifyFinal() internally finalizes a copy of the digest context. This means that EVP_VerifyUpdate() and EVP_VerifyFinal() can be called later to digest and verify additional data. Applications may disable this behavior by setting the EVP_MD_CTX_FLAG_FINALISE context flag via EVP_MD_CTX_set_flags(3).
β οΈ But wait β not all providers support continuation! If the selected provider does not allow duplicating contexts,EVP_DigestVerifyFinal()will finalize the digest context, and attempting to process additional data viaEVP_DigestVerifyUpdate()will result in an error.
EVP_DigestVerifyInit() and EVP_DigestVerifyInit_ex() functions can be called multiple times on a context, and the parameters set by previous calls should be preserved if the pkey parameter is NULL. The call then just resets the state of the ctx. Reset era. π
EVP_DigestVerify() can only be called once, and cannot be used again without reinitialising the EVP_MD_CTX by calling EVP_DigestVerifyInit_ex(). One and done, no reruns.
π Real talk: ignoring failure returns ofEVP_DigestVerifyInit()andEVP_DigestVerifyInit_ex()functions can lead to subsequent undefined behavior when callingEVP_DigestVerifyUpdate(),EVP_DigestVerifyFinal(), orEVP_DigestVerify(). Check your return values, bestie. Please. For me.
π SEE ALSO π
EVP_DigestSignInit(3), EVP_DigestInit(3), evp(7), HMAC(3), MD2(3), MD5(3), MDC2(3), RIPEMD160(3), SHA1(3), openssl-dgst(1), RAND(7)
β HISTORY β
EVP_DigestVerifyInit(),EVP_DigestVerifyUpdate()andEVP_DigestVerifyFinal()were added inOpenSSL 1.0.0.EVP_DigestVerifyInit_ex()was added inOpenSSL 3.0.EVP_DigestVerifyUpdate()was converted from a macro to a function inOpenSSL 3.0. Glow-up arc complete. π
π COPYRIGHT π
Copyright 2006-2024 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>.
okay that's the whole page bestie, you ate that π«Ά this was OpenSSL version 4.0.3, dated 2026-09-29, page EVP_DIGESTVERIFYINIT(3SSL) β stan a signature verification icon, periodt. πΈβ¨π¦
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms