5 EVP_DigestVerifyInit_ex, EVP_DigestVerifyInit, EVP_DigestVerifyUpdate,
6 EVP_DigestVerifyFinal, EVP_DigestVerify - EVP signature verification functions
10 #include <openssl/evp.h>
12 int EVP_DigestVerifyInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
13 const char *mdname, OPENSSL_CTX *libctx,
14 const char *props, EVP_PKEY *pkey);
15 int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
16 const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
17 int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
18 int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
20 int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret,
21 size_t siglen, const unsigned char *tbs, size_t tbslen);
25 The EVP signature routines are a high-level interface to digital signatures.
26 Input data is digested first before the signature verification takes place.
28 EVP_DigestVerifyInit_ex() sets up verification context B<ctx> to use a
29 digest with the name B<mdname> and public key B<pkey>. The name of the digest to
30 be used is passed to the provider of the signature algorithm in use. How that
31 provider interprets the digest name is provider specific. The provider may
32 implement that digest directly itself or it may (optionally) choose to fetch it
33 (which could result in a digest from a different provider being selected). If
34 the provider supports fetching the digest then it may use the B<props> argument
35 for the properties to be used during the fetch.
37 The I<pkey> algorithm is used to fetch a B<EVP_SIGNATURE> method implicitly, to
38 be used for the actual signing. See L<provider(7)/Implicit fetch> for
39 more information about implicit fetches.
41 The OpenSSL default and legacy providers support fetching digests and can fetch
42 those digests from any available provider. The OpenSSL fips provider also
43 supports fetching digests but will only fetch digests that are themselves
44 implemented inside the fips provider.
46 B<ctx> must be created with EVP_MD_CTX_new() before calling this function. If
47 B<pctx> is not NULL, the EVP_PKEY_CTX of the verification operation will be
48 written to B<*pctx>: this can be used to set alternative verification options.
49 Note that any existing value in B<*pctx> is overwritten. The EVP_PKEY_CTX value
50 returned must not be freed directly by the application if B<ctx> is not assigned
51 an EVP_PKEY_CTX value before being passed to EVP_DigestVerifyInit_ex()
52 (which means the EVP_PKEY_CTX is created inside
53 EVP_DigestVerifyInit_ex() and it will be freed automatically when the
54 EVP_MD_CTX is freed). If the EVP_PKEY_CTX to be used is created by
55 EVP_DigestVerifyInit_ex then it will use the B<OPENSSL_CTX> specified
56 in I<libctx> and the property query string specified in I<props>.
58 No B<EVP_PKEY_CTX> will be created by EVP_DigestSignInit_ex() if the
59 passed B<ctx> has already been assigned one via L<EVP_MD_CTX_set_pkey_ctx(3)>.
62 Not all digests can be used for all key types. The following combinations apply.
68 Supports SHA1, SHA224, SHA256, SHA384 and SHA512
72 Supports SHA1, SHA224, SHA256, SHA384, SHA512 and SM3
74 =item RSA with no padding
76 Supports no digests (the digest B<type> must be NULL)
78 =item RSA with X931 padding
80 Supports SHA1, SHA256, SHA384 and SHA512
82 =item All other RSA padding types
84 Support SHA1, SHA224, SHA256, SHA384, SHA512, MD5, MD5_SHA1, MD2, MD4, MDC2,
85 SHA3-224, SHA3-256, SHA3-384, SHA3-512
87 =item Ed25519 and Ed448
89 Support no digests (the digest B<type> must be NULL)
95 =item CMAC, Poly1305 and Siphash
97 Will ignore any digest provided.
101 If RSA-PSS is used and restrictions apply then the digest must match.
103 EVP_DigestVerifyInit() works in the same way as
104 EVP_DigestVerifyInit_ex() except that the B<mdname> parameter will be
105 inferred from the supplied digest B<type>, and B<props> will be NULL. Where
106 supplied the ENGINE B<e> will be used for the signature verification and digest
107 algorithm implementations. B<e> may be NULL.
109 EVP_DigestVerifyUpdate() hashes B<cnt> bytes of data at B<d> into the
110 verification context B<ctx>. This function can be called several times on the
111 same B<ctx> to include additional data.
113 EVP_DigestVerifyFinal() verifies the data in B<ctx> against the signature in
114 B<sig> of length B<siglen>.
116 EVP_DigestVerify() verifies B<tbslen> bytes at B<tbs> against the signature
117 in B<sig> of length B<siglen>.
121 EVP_DigestVerifyInit() and EVP_DigestVerifyUpdate() return 1 for success and 0
124 EVP_DigestVerifyFinal() and EVP_DigestVerify() return 1 for success; any other
125 value indicates failure. A return value of zero indicates that the signature
126 did not verify successfully (that is, B<tbs> did not match the original data or
127 the signature had an invalid form), while other values indicate a more serious
128 error (and sometimes also indicate an invalid signature form).
130 The error codes can be obtained from L<ERR_get_error(3)>.
134 The B<EVP> interface to digital signatures should almost always be used in
135 preference to the low-level interfaces. This is because the code then becomes
136 transparent to the algorithm used and much more flexible.
138 EVP_DigestVerify() is a one shot operation which verifies a single block of
139 data in one function. For algorithms that support streaming it is equivalent
140 to calling EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal(). For
141 algorithms which do not support streaming (e.g. PureEdDSA) it is the only way
144 In previous versions of OpenSSL there was a link between message digest types
145 and public key algorithms. This meant that "clone" digests such as EVP_dss1()
146 needed to be used to sign using SHA1 and DSA. This is no longer necessary and
147 the use of clone digest is now discouraged.
149 For some key types and parameters the random number generator must be seeded.
150 If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
151 external circumstances (see L<RAND(7)>), the operation will fail.
153 The call to EVP_DigestVerifyFinal() internally finalizes a copy of the digest
154 context. This means that EVP_VerifyUpdate() and EVP_VerifyFinal() can
155 be called later to digest and verify additional data.
157 Since only a copy of the digest context is ever finalized, the context must
158 be cleaned up after use by calling EVP_MD_CTX_free() or a memory leak
163 L<EVP_DigestSignInit(3)>,
164 L<EVP_DigestInit(3)>,
165 L<evp(7)>, L<HMAC(3)>, L<MD2(3)>,
166 L<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>,
167 L<SHA1(3)>, L<openssl-dgst(1)>,
172 EVP_DigestVerifyInit(), EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal()
173 were added in OpenSSL 1.0.0.
175 EVP_DigestVerifyInit_ex() was added in OpenSSL 3.0.
177 EVP_DigestVerifyUpdate() was converted from a macro to a function in OpenSSL
182 Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved.
184 Licensed under the Apache License 2.0 (the "License"). You may not use
185 this file except in compliance with the License. You can obtain a copy
186 in the file LICENSE in the source distribution or at
187 L<https://www.openssl.org/source/license.html>.