1 1.1 christos =pod 2 1.1 christos 3 1.1 christos =head1 NAME 4 1.1 christos 5 1.1.1.7 christos EVP_DigestVerifyInit_ex, EVP_DigestVerifyInit, EVP_DigestVerifyUpdate, 6 1.1.1.7 christos EVP_DigestVerifyFinal, EVP_DigestVerify - EVP signature verification functions 7 1.1 christos 8 1.1 christos =head1 SYNOPSIS 9 1.1 christos 10 1.1 christos #include <openssl/evp.h> 11 1.1 christos 12 1.1.1.7 christos int EVP_DigestVerifyInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, 13 1.1.1.7 christos const char *mdname, OSSL_LIB_CTX *libctx, 14 1.1.1.7 christos const char *props, EVP_PKEY *pkey, 15 1.1.1.7 christos const OSSL_PARAM params[]); 16 1.1 christos int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, 17 1.1 christos const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey); 18 1.1 christos int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt); 19 1.1 christos int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig, 20 1.1 christos size_t siglen); 21 1.1 christos int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret, 22 1.1 christos size_t siglen, const unsigned char *tbs, size_t tbslen); 23 1.1 christos 24 1.1 christos =head1 DESCRIPTION 25 1.1 christos 26 1.1.1.6 christos The EVP signature routines are a high-level interface to digital signatures. 27 1.1.1.7 christos Input data is digested first before the signature verification takes place. 28 1.1 christos 29 1.1.1.7 christos EVP_DigestVerifyInit_ex() sets up verification context B<ctx> to use a 30 1.1.1.7 christos digest with the name B<mdname> and public key B<pkey>. The name of the digest to 31 1.1.1.7 christos be used is passed to the provider of the signature algorithm in use. How that 32 1.1.1.7 christos provider interprets the digest name is provider specific. The provider may 33 1.1.1.7 christos implement that digest directly itself or it may (optionally) choose to fetch it 34 1.1.1.7 christos (which could result in a digest from a different provider being selected). If 35 1.1.1.7 christos the provider supports fetching the digest then it may use the B<props> argument 36 1.1.1.7 christos for the properties to be used during the fetch. Finally, the passed parameters 37 1.1.1.7 christos I<params>, if not NULL, are set on the context before returning. 38 1.1 christos 39 1.1.1.7 christos The I<pkey> algorithm is used to fetch a B<EVP_SIGNATURE> method implicitly, to 40 1.1.1.7 christos be used for the actual signing. See L<provider(7)/Implicit fetch> for 41 1.1.1.7 christos more information about implicit fetches. 42 1.1.1.7 christos 43 1.1.1.7 christos The OpenSSL default and legacy providers support fetching digests and can fetch 44 1.1.1.7 christos those digests from any available provider. The OpenSSL FIPS provider also 45 1.1.1.7 christos supports fetching digests but will only fetch digests that are themselves 46 1.1.1.7 christos implemented inside the FIPS provider. 47 1.1.1.7 christos 48 1.1.1.7 christos B<ctx> must be created with EVP_MD_CTX_new() before calling this function. If 49 1.1.1.7 christos B<pctx> is not NULL, the EVP_PKEY_CTX of the verification operation will be 50 1.1.1.7 christos written to B<*pctx>: this can be used to set alternative verification options. 51 1.1.1.7 christos Note that any existing value in B<*pctx> is overwritten. The EVP_PKEY_CTX value 52 1.1.1.7 christos returned must not be freed directly by the application if B<ctx> is not assigned 53 1.1.1.7 christos an EVP_PKEY_CTX value before being passed to EVP_DigestVerifyInit_ex() 54 1.1.1.7 christos (which means the EVP_PKEY_CTX is created inside 55 1.1.1.7 christos EVP_DigestVerifyInit_ex() and it will be freed automatically when the 56 1.1.1.7 christos EVP_MD_CTX is freed). If the EVP_PKEY_CTX to be used is created by 57 1.1.1.7 christos EVP_DigestVerifyInit_ex then it will use the B<OSSL_LIB_CTX> specified 58 1.1.1.7 christos in I<libctx> and the property query string specified in I<props>. 59 1.1.1.7 christos 60 1.1.1.7 christos No B<EVP_PKEY_CTX> will be created by EVP_DigestVerifyInit_ex() if the 61 1.1.1.7 christos passed B<ctx> has already been assigned one via L<EVP_MD_CTX_set_pkey_ctx(3)>. 62 1.1.1.7 christos See also L<SM2(7)>. 63 1.1.1.7 christos 64 1.1.1.7 christos Not all digests can be used for all key types. The following combinations apply. 65 1.1.1.7 christos 66 1.1.1.7 christos =over 4 67 1.1.1.7 christos 68 1.1.1.7 christos =item DSA 69 1.1.1.7 christos 70 1.1.1.7 christos Supports SHA1, SHA224, SHA256, SHA384 and SHA512 71 1.1.1.7 christos 72 1.1.1.7 christos =item ECDSA 73 1.1.1.7 christos 74 1.1.1.7 christos Supports SHA1, SHA224, SHA256, SHA384, SHA512 and SM3 75 1.1.1.7 christos 76 1.1.1.7 christos =item RSA with no padding 77 1.1.1.7 christos 78 1.1.1.7 christos Supports no digests (the digest B<type> must be NULL) 79 1.1.1.7 christos 80 1.1.1.7 christos =item RSA with X931 padding 81 1.1.1.7 christos 82 1.1.1.7 christos Supports SHA1, SHA256, SHA384 and SHA512 83 1.1.1.7 christos 84 1.1.1.7 christos =item All other RSA padding types 85 1.1.1.7 christos 86 1.1.1.7 christos Support SHA1, SHA224, SHA256, SHA384, SHA512, MD5, MD5_SHA1, MD2, MD4, MDC2, 87 1.1.1.7 christos SHA3-224, SHA3-256, SHA3-384, SHA3-512 88 1.1.1.7 christos 89 1.1.1.7 christos =item Ed25519 and Ed448 90 1.1.1.7 christos 91 1.1.1.7 christos Support no digests (the digest B<type> must be NULL) 92 1.1.1.7 christos 93 1.1.1.7 christos =item HMAC 94 1.1.1.7 christos 95 1.1.1.7 christos Supports any digest 96 1.1.1.7 christos 97 1.1.1.7 christos =item CMAC, Poly1305 and Siphash 98 1.1.1.7 christos 99 1.1.1.7 christos Will ignore any digest provided. 100 1.1.1.7 christos 101 1.1.1.7 christos =back 102 1.1.1.7 christos 103 1.1.1.7 christos If RSA-PSS is used and restrictions apply then the digest must match. 104 1.1.1.7 christos 105 1.1.1.7 christos EVP_DigestVerifyInit() works in the same way as 106 1.1.1.7 christos EVP_DigestVerifyInit_ex() except that the B<mdname> parameter will be 107 1.1.1.7 christos inferred from the supplied digest B<type>, and B<props> will be NULL. Where 108 1.1.1.7 christos supplied the ENGINE B<e> will be used for the signature verification and digest 109 1.1.1.7 christos algorithm implementations. B<e> may be NULL. 110 1.1 christos 111 1.1 christos EVP_DigestVerifyUpdate() hashes B<cnt> bytes of data at B<d> into the 112 1.1 christos verification context B<ctx>. This function can be called several times on the 113 1.1.1.7 christos same B<ctx> to include additional data. 114 1.1 christos 115 1.1 christos EVP_DigestVerifyFinal() verifies the data in B<ctx> against the signature in 116 1.1 christos B<sig> of length B<siglen>. 117 1.1 christos 118 1.1 christos EVP_DigestVerify() verifies B<tbslen> bytes at B<tbs> against the signature 119 1.1 christos in B<sig> of length B<siglen>. 120 1.1 christos 121 1.1 christos =head1 RETURN VALUES 122 1.1 christos 123 1.1 christos EVP_DigestVerifyInit() and EVP_DigestVerifyUpdate() return 1 for success and 0 124 1.1 christos for failure. 125 1.1 christos 126 1.1 christos EVP_DigestVerifyFinal() and EVP_DigestVerify() return 1 for success; any other 127 1.1 christos value indicates failure. A return value of zero indicates that the signature 128 1.1 christos did not verify successfully (that is, B<tbs> did not match the original data or 129 1.1 christos the signature had an invalid form), while other values indicate a more serious 130 1.1 christos error (and sometimes also indicate an invalid signature form). 131 1.1 christos 132 1.1 christos The error codes can be obtained from L<ERR_get_error(3)>. 133 1.1 christos 134 1.1 christos =head1 NOTES 135 1.1 christos 136 1.1 christos The B<EVP> interface to digital signatures should almost always be used in 137 1.1.1.6 christos preference to the low-level interfaces. This is because the code then becomes 138 1.1 christos transparent to the algorithm used and much more flexible. 139 1.1 christos 140 1.1 christos EVP_DigestVerify() is a one shot operation which verifies a single block of 141 1.1 christos data in one function. For algorithms that support streaming it is equivalent 142 1.1 christos to calling EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal(). For 143 1.1 christos algorithms which do not support streaming (e.g. PureEdDSA) it is the only way 144 1.1 christos to verify data. 145 1.1 christos 146 1.1 christos In previous versions of OpenSSL there was a link between message digest types 147 1.1 christos and public key algorithms. This meant that "clone" digests such as EVP_dss1() 148 1.1 christos needed to be used to sign using SHA1 and DSA. This is no longer necessary and 149 1.1 christos the use of clone digest is now discouraged. 150 1.1 christos 151 1.1.1.4 christos For some key types and parameters the random number generator must be seeded. 152 1.1.1.4 christos If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to 153 1.1.1.4 christos external circumstances (see L<RAND(7)>), the operation will fail. 154 1.1 christos 155 1.1 christos The call to EVP_DigestVerifyFinal() internally finalizes a copy of the digest 156 1.1 christos context. This means that EVP_VerifyUpdate() and EVP_VerifyFinal() can 157 1.1 christos be called later to digest and verify additional data. 158 1.1 christos 159 1.1.1.7 christos EVP_DigestVerifyInit() and EVP_DigestVerifyInit_ex() functions can be called 160 1.1.1.7 christos multiple times on a context and the parameters set by previous calls should be 161 1.1.1.7 christos preserved if the I<pkey> parameter is NULL. The call then just resets the state 162 1.1.1.7 christos of the I<ctx>. 163 1.1.1.7 christos 164 1.1.1.7 christos Ignoring failure returns of EVP_DigestVerifyInit() and EVP_DigestVerifyInit_ex() 165 1.1.1.7 christos functions can lead to subsequent undefined behavior when calling 166 1.1.1.7 christos EVP_DigestVerifyUpdate(), EVP_DigestVerifyFinal(), or EVP_DigestVerify(). 167 1.1 christos 168 1.1 christos =head1 SEE ALSO 169 1.1 christos 170 1.1 christos L<EVP_DigestSignInit(3)>, 171 1.1 christos L<EVP_DigestInit(3)>, 172 1.1 christos L<evp(7)>, L<HMAC(3)>, L<MD2(3)>, 173 1.1 christos L<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>, 174 1.1.1.7 christos L<SHA1(3)>, L<openssl-dgst(1)>, 175 1.1.1.4 christos L<RAND(7)> 176 1.1 christos 177 1.1 christos =head1 HISTORY 178 1.1 christos 179 1.1 christos EVP_DigestVerifyInit(), EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal() 180 1.1.1.2 christos were added in OpenSSL 1.0.0. 181 1.1 christos 182 1.1.1.7 christos EVP_DigestVerifyInit_ex() was added in OpenSSL 3.0. 183 1.1.1.7 christos 184 1.1.1.7 christos EVP_DigestVerifyUpdate() was converted from a macro to a function in OpenSSL 185 1.1.1.7 christos 3.0. 186 1.1.1.7 christos 187 1.1 christos =head1 COPYRIGHT 188 1.1 christos 189 1.1.1.7 christos Copyright 2006-2023 The OpenSSL Project Authors. All Rights Reserved. 190 1.1 christos 191 1.1.1.7 christos Licensed under the Apache License 2.0 (the "License"). You may not use 192 1.1 christos this file except in compliance with the License. You can obtain a copy 193 1.1 christos in the file LICENSE in the source distribution or at 194 1.1 christos L<https://www.openssl.org/source/license.html>. 195 1.1 christos 196 1.1 christos =cut 197