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