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