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, const char *props,
14 EVP_PKEY *pkey, OPENSSL_CTX *libctx);
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 digest
29 with the name B<mdname> and public key B<pkey>. The name of the digest to be
30 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() (which
52 means the EVP_PKEY_CTX is created inside EVP_DigestVerifyInit_ex() and it will
53 be freed automatically when the EVP_MD_CTX is freed). If the EVP_PKEY_CTX to be
54 used is created by EVP_DigestVerifyInit_ex then it will use the B<OPENSSL_CTX>
55 specified in I<libctx> and the property query string specified in I<props>.
57 No B<EVP_PKEY_CTX> will be created by EVP_DigestSignInit_ex() if the passed
58 B<ctx> has already been assigned one via L<EVP_MD_CTX_set_pkey_ctx(3)>. See also
61 Not all digests can be used for all key types. The following combinations apply.
67 Supports SHA1, SHA224, SHA256, SHA384 and SHA512
71 Supports SHA1, SHA224, SHA256, SHA384, SHA512 and SM3
73 =item RSA with no padding
75 Supports no digests (the digest B<type> must be NULL)
77 =item RSA with X931 padding
79 Supports SHA1, SHA256, SHA384 and SHA512
81 =item All other RSA padding types
83 Support SHA1, SHA224, SHA256, SHA384, SHA512, MD5, MD5_SHA1, MD2, MD4, MDC2,
84 SHA3-224, SHA3-256, SHA3-384, SHA3-512
86 =item Ed25519 and Ed448
88 Support no digests (the digest B<type> must be NULL)
94 =item CMAC, Poly1305 and SipHash
96 Will ignore any digest provided.
100 If RSA-PSS is used and restrictions apply then the digest must match.
102 EVP_DigestVerifyInit() works in the same way as EVP_DigestVerifyInit_ex() except
103 that the B<mdname> parameter will be inferred from the supplied digest B<type>,
104 and B<props> will be NULL. Where supplied the ENGINE B<e> will be used for the
105 signature verification and digest algorithm implementations. B<e> may be NULL.
107 EVP_DigestVerifyUpdate() hashes B<cnt> bytes of data at B<d> into the
108 verification context B<ctx>. This function can be called several times on the
109 same B<ctx> to include additional data.
111 EVP_DigestVerifyFinal() verifies the data in B<ctx> against the signature in
112 B<sig> of length B<siglen>.
114 EVP_DigestVerify() verifies B<tbslen> bytes at B<tbs> against the signature
115 in B<sig> of length B<siglen>.
119 EVP_DigestVerifyInit() and EVP_DigestVerifyUpdate() return 1 for success and 0
122 EVP_DigestVerifyFinal() and EVP_DigestVerify() return 1 for success; any other
123 value indicates failure. A return value of zero indicates that the signature
124 did not verify successfully (that is, B<tbs> did not match the original data or
125 the signature had an invalid form), while other values indicate a more serious
126 error (and sometimes also indicate an invalid signature form).
128 The error codes can be obtained from L<ERR_get_error(3)>.
132 The B<EVP> interface to digital signatures should almost always be used in
133 preference to the low-level interfaces. This is because the code then becomes
134 transparent to the algorithm used and much more flexible.
136 EVP_DigestVerify() is a one shot operation which verifies a single block of
137 data in one function. For algorithms that support streaming it is equivalent
138 to calling EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal(). For
139 algorithms which do not support streaming (e.g. PureEdDSA) it is the only way
142 In previous versions of OpenSSL there was a link between message digest types
143 and public key algorithms. This meant that "clone" digests such as EVP_dss1()
144 needed to be used to sign using SHA1 and DSA. This is no longer necessary and
145 the use of clone digest is now discouraged.
147 For some key types and parameters the random number generator must be seeded.
148 If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
149 external circumstances (see L<RAND(7)>), the operation will fail.
151 The call to EVP_DigestVerifyFinal() internally finalizes a copy of the digest
152 context. This means that EVP_VerifyUpdate() and EVP_VerifyFinal() can
153 be called later to digest and verify additional data.
155 Since only a copy of the digest context is ever finalized, the context must
156 be cleaned up after use by calling EVP_MD_CTX_free() or a memory leak
161 L<EVP_DigestSignInit(3)>,
162 L<EVP_DigestInit(3)>,
163 L<evp(7)>, L<HMAC(3)>, L<MD2(3)>,
164 L<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>,
165 L<SHA1(3)>, L<openssl-dgst(1)>,
170 EVP_DigestVerifyInit(), EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal()
171 were added in OpenSSL 1.0.0.
173 EVP_DigestVerifyInit_ex() was added in OpenSSL 3.0.
175 EVP_DigestVerifyUpdate() was converted from a macro to a function in OpenSSL
180 Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved.
182 Licensed under the Apache License 2.0 (the "License"). You may not use
183 this file except in compliance with the License. You can obtain a copy
184 in the file LICENSE in the source distribution or at
185 L<https://www.openssl.org/source/license.html>.