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