113d40330Schristos=pod 213d40330Schristos 313d40330Schristos=head1 NAME 413d40330Schristos 5*b0d17251SchristosEVP_DigestVerifyInit_ex, EVP_DigestVerifyInit, EVP_DigestVerifyUpdate, 6*b0d17251SchristosEVP_DigestVerifyFinal, EVP_DigestVerify - EVP signature verification functions 713d40330Schristos 813d40330Schristos=head1 SYNOPSIS 913d40330Schristos 1013d40330Schristos #include <openssl/evp.h> 1113d40330Schristos 12*b0d17251Schristos int EVP_DigestVerifyInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, 13*b0d17251Schristos const char *mdname, OSSL_LIB_CTX *libctx, 14*b0d17251Schristos const char *props, EVP_PKEY *pkey, 15*b0d17251Schristos const OSSL_PARAM params[]); 1613d40330Schristos int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, 1713d40330Schristos const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey); 1813d40330Schristos int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt); 1913d40330Schristos int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig, 2013d40330Schristos size_t siglen); 2113d40330Schristos int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret, 2213d40330Schristos size_t siglen, const unsigned char *tbs, size_t tbslen); 2313d40330Schristos 2413d40330Schristos=head1 DESCRIPTION 2513d40330Schristos 26f30e0929SchristosThe EVP signature routines are a high-level interface to digital signatures. 27*b0d17251SchristosInput data is digested first before the signature verification takes place. 2813d40330Schristos 29*b0d17251SchristosEVP_DigestVerifyInit_ex() sets up verification context B<ctx> to use a 30*b0d17251Schristosdigest with the name B<mdname> and public key B<pkey>. The name of the digest to 31*b0d17251Schristosbe used is passed to the provider of the signature algorithm in use. How that 32*b0d17251Schristosprovider interprets the digest name is provider specific. The provider may 33*b0d17251Schristosimplement that digest directly itself or it may (optionally) choose to fetch it 34*b0d17251Schristos(which could result in a digest from a different provider being selected). If 35*b0d17251Schristosthe provider supports fetching the digest then it may use the B<props> argument 36*b0d17251Schristosfor the properties to be used during the fetch. Finally, the passed parameters 37*b0d17251SchristosI<params>, if not NULL, are set on the context before returning. 3813d40330Schristos 39*b0d17251SchristosThe I<pkey> algorithm is used to fetch a B<EVP_SIGNATURE> method implicitly, to 40*b0d17251Schristosbe used for the actual signing. See L<provider(7)/Implicit fetch> for 41*b0d17251Schristosmore information about implicit fetches. 42*b0d17251Schristos 43*b0d17251SchristosThe OpenSSL default and legacy providers support fetching digests and can fetch 44*b0d17251Schristosthose digests from any available provider. The OpenSSL FIPS provider also 45*b0d17251Schristossupports fetching digests but will only fetch digests that are themselves 46*b0d17251Schristosimplemented inside the FIPS provider. 47*b0d17251Schristos 48*b0d17251SchristosB<ctx> must be created with EVP_MD_CTX_new() before calling this function. If 49*b0d17251SchristosB<pctx> is not NULL, the EVP_PKEY_CTX of the verification operation will be 50*b0d17251Schristoswritten to B<*pctx>: this can be used to set alternative verification options. 51*b0d17251SchristosNote that any existing value in B<*pctx> is overwritten. The EVP_PKEY_CTX value 52*b0d17251Schristosreturned must not be freed directly by the application if B<ctx> is not assigned 53*b0d17251Schristosan EVP_PKEY_CTX value before being passed to EVP_DigestVerifyInit_ex() 54*b0d17251Schristos(which means the EVP_PKEY_CTX is created inside 55*b0d17251SchristosEVP_DigestVerifyInit_ex() and it will be freed automatically when the 56*b0d17251SchristosEVP_MD_CTX is freed). If the EVP_PKEY_CTX to be used is created by 57*b0d17251SchristosEVP_DigestVerifyInit_ex then it will use the B<OSSL_LIB_CTX> specified 58*b0d17251Schristosin I<libctx> and the property query string specified in I<props>. 59*b0d17251Schristos 60*b0d17251SchristosNo B<EVP_PKEY_CTX> will be created by EVP_DigestVerifyInit_ex() if the 61*b0d17251Schristospassed B<ctx> has already been assigned one via L<EVP_MD_CTX_set_pkey_ctx(3)>. 62*b0d17251SchristosSee also L<SM2(7)>. 63*b0d17251Schristos 64*b0d17251SchristosNot all digests can be used for all key types. The following combinations apply. 65*b0d17251Schristos 66*b0d17251Schristos=over 4 67*b0d17251Schristos 68*b0d17251Schristos=item DSA 69*b0d17251Schristos 70*b0d17251SchristosSupports SHA1, SHA224, SHA256, SHA384 and SHA512 71*b0d17251Schristos 72*b0d17251Schristos=item ECDSA 73*b0d17251Schristos 74*b0d17251SchristosSupports SHA1, SHA224, SHA256, SHA384, SHA512 and SM3 75*b0d17251Schristos 76*b0d17251Schristos=item RSA with no padding 77*b0d17251Schristos 78*b0d17251SchristosSupports no digests (the digest B<type> must be NULL) 79*b0d17251Schristos 80*b0d17251Schristos=item RSA with X931 padding 81*b0d17251Schristos 82*b0d17251SchristosSupports SHA1, SHA256, SHA384 and SHA512 83*b0d17251Schristos 84*b0d17251Schristos=item All other RSA padding types 85*b0d17251Schristos 86*b0d17251SchristosSupport SHA1, SHA224, SHA256, SHA384, SHA512, MD5, MD5_SHA1, MD2, MD4, MDC2, 87*b0d17251SchristosSHA3-224, SHA3-256, SHA3-384, SHA3-512 88*b0d17251Schristos 89*b0d17251Schristos=item Ed25519 and Ed448 90*b0d17251Schristos 91*b0d17251SchristosSupport no digests (the digest B<type> must be NULL) 92*b0d17251Schristos 93*b0d17251Schristos=item HMAC 94*b0d17251Schristos 95*b0d17251SchristosSupports any digest 96*b0d17251Schristos 97*b0d17251Schristos=item CMAC, Poly1305 and Siphash 98*b0d17251Schristos 99*b0d17251SchristosWill ignore any digest provided. 100*b0d17251Schristos 101*b0d17251Schristos=back 102*b0d17251Schristos 103*b0d17251SchristosIf RSA-PSS is used and restrictions apply then the digest must match. 104*b0d17251Schristos 105*b0d17251SchristosEVP_DigestVerifyInit() works in the same way as 106*b0d17251SchristosEVP_DigestVerifyInit_ex() except that the B<mdname> parameter will be 107*b0d17251Schristosinferred from the supplied digest B<type>, and B<props> will be NULL. Where 108*b0d17251Schristossupplied the ENGINE B<e> will be used for the signature verification and digest 109*b0d17251Schristosalgorithm implementations. B<e> may be NULL. 11013d40330Schristos 11113d40330SchristosEVP_DigestVerifyUpdate() hashes B<cnt> bytes of data at B<d> into the 11213d40330Schristosverification context B<ctx>. This function can be called several times on the 113*b0d17251Schristossame B<ctx> to include additional data. 11413d40330Schristos 11513d40330SchristosEVP_DigestVerifyFinal() verifies the data in B<ctx> against the signature in 11613d40330SchristosB<sig> of length B<siglen>. 11713d40330Schristos 11813d40330SchristosEVP_DigestVerify() verifies B<tbslen> bytes at B<tbs> against the signature 11913d40330Schristosin B<sig> of length B<siglen>. 12013d40330Schristos 12113d40330Schristos=head1 RETURN VALUES 12213d40330Schristos 12313d40330SchristosEVP_DigestVerifyInit() and EVP_DigestVerifyUpdate() return 1 for success and 0 12413d40330Schristosfor failure. 12513d40330Schristos 12613d40330SchristosEVP_DigestVerifyFinal() and EVP_DigestVerify() return 1 for success; any other 12713d40330Schristosvalue indicates failure. A return value of zero indicates that the signature 12813d40330Schristosdid not verify successfully (that is, B<tbs> did not match the original data or 12913d40330Schristosthe signature had an invalid form), while other values indicate a more serious 13013d40330Schristoserror (and sometimes also indicate an invalid signature form). 13113d40330Schristos 13213d40330SchristosThe error codes can be obtained from L<ERR_get_error(3)>. 13313d40330Schristos 13413d40330Schristos=head1 NOTES 13513d40330Schristos 13613d40330SchristosThe B<EVP> interface to digital signatures should almost always be used in 137f30e0929Schristospreference to the low-level interfaces. This is because the code then becomes 13813d40330Schristostransparent to the algorithm used and much more flexible. 13913d40330Schristos 14013d40330SchristosEVP_DigestVerify() is a one shot operation which verifies a single block of 14113d40330Schristosdata in one function. For algorithms that support streaming it is equivalent 14213d40330Schristosto calling EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal(). For 14313d40330Schristosalgorithms which do not support streaming (e.g. PureEdDSA) it is the only way 14413d40330Schristosto verify data. 14513d40330Schristos 14613d40330SchristosIn previous versions of OpenSSL there was a link between message digest types 14713d40330Schristosand public key algorithms. This meant that "clone" digests such as EVP_dss1() 14813d40330Schristosneeded to be used to sign using SHA1 and DSA. This is no longer necessary and 14913d40330Schristosthe use of clone digest is now discouraged. 15013d40330Schristos 1514ce06407SchristosFor some key types and parameters the random number generator must be seeded. 1524ce06407SchristosIf the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to 1534ce06407Schristosexternal circumstances (see L<RAND(7)>), the operation will fail. 15413d40330Schristos 15513d40330SchristosThe call to EVP_DigestVerifyFinal() internally finalizes a copy of the digest 15613d40330Schristoscontext. This means that EVP_VerifyUpdate() and EVP_VerifyFinal() can 15713d40330Schristosbe called later to digest and verify additional data. 15813d40330Schristos 159*b0d17251SchristosEVP_DigestVerifyInit() and EVP_DigestVerifyInit_ex() functions can be called 160*b0d17251Schristosmultiple times on a context and the parameters set by previous calls should be 161*b0d17251Schristospreserved if the I<pkey> parameter is NULL. The call then just resets the state 162*b0d17251Schristosof the I<ctx>. 163*b0d17251Schristos 164*b0d17251SchristosIgnoring failure returns of EVP_DigestVerifyInit() and EVP_DigestVerifyInit_ex() 165*b0d17251Schristosfunctions can lead to subsequent undefined behavior when calling 166*b0d17251SchristosEVP_DigestVerifyUpdate(), EVP_DigestVerifyFinal(), or EVP_DigestVerify(). 16713d40330Schristos 16813d40330Schristos=head1 SEE ALSO 16913d40330Schristos 17013d40330SchristosL<EVP_DigestSignInit(3)>, 17113d40330SchristosL<EVP_DigestInit(3)>, 17213d40330SchristosL<evp(7)>, L<HMAC(3)>, L<MD2(3)>, 17313d40330SchristosL<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>, 174*b0d17251SchristosL<SHA1(3)>, L<openssl-dgst(1)>, 1754ce06407SchristosL<RAND(7)> 17613d40330Schristos 17713d40330Schristos=head1 HISTORY 17813d40330Schristos 17913d40330SchristosEVP_DigestVerifyInit(), EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal() 180b88c74d5Schristoswere added in OpenSSL 1.0.0. 18113d40330Schristos 182*b0d17251SchristosEVP_DigestVerifyInit_ex() was added in OpenSSL 3.0. 183*b0d17251Schristos 184*b0d17251SchristosEVP_DigestVerifyUpdate() was converted from a macro to a function in OpenSSL 185*b0d17251Schristos3.0. 186*b0d17251Schristos 18713d40330Schristos=head1 COPYRIGHT 18813d40330Schristos 189*b0d17251SchristosCopyright 2006-2023 The OpenSSL Project Authors. All Rights Reserved. 19013d40330Schristos 191*b0d17251SchristosLicensed under the Apache License 2.0 (the "License"). You may not use 19213d40330Schristosthis file except in compliance with the License. You can obtain a copy 19313d40330Schristosin the file LICENSE in the source distribution or at 19413d40330SchristosL<https://www.openssl.org/source/license.html>. 19513d40330Schristos 19613d40330Schristos=cut 197