1EVP_DIGESTSIGNINIT(3ossl)           OpenSSL          EVP_DIGESTSIGNINIT(3ossl)
2
3
4

NAME

6       EVP_DigestSignInit_ex, EVP_DigestSignInit, EVP_DigestSignUpdate,
7       EVP_DigestSignFinal, EVP_DigestSign - EVP signing functions
8

SYNOPSIS

10        #include <openssl/evp.h>
11
12        int EVP_DigestSignInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
13                                  const char *mdname, OSSL_LIB_CTX *libctx,
14                                  const char *props, EVP_PKEY *pkey,
15                                  const OSSL_PARAM params[]);
16        int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
17                               const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
18        int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
19        int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen);
20
21        int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret,
22                           size_t *siglen, const unsigned char *tbs,
23                           size_t tbslen);
24

DESCRIPTION

26       The EVP signature routines are a high-level interface to digital
27       signatures.  Input data is digested first before the signing takes
28       place.
29
30       EVP_DigestSignInit_ex() sets up signing context ctx to use a digest
31       with the name mdname and private key pkey. The name of the digest to be
32       used is passed to the provider of the signature algorithm in use. How
33       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 signing operation will be
52       written to *pctx: this can be used to set alternative signing options.
53       Note that any existing value in *pctx is overwritten. The EVP_PKEY_CTX
54       value returned must not be freed directly by the application if ctx is
55       not assigned an EVP_PKEY_CTX value before being passed to
56       EVP_DigestSignInit_ex() (which means the EVP_PKEY_CTX is created inside
57       EVP_DigestSignInit_ex() and it will be freed automatically when the
58       EVP_MD_CTX is freed). If the EVP_PKEY_CTX to be used is created by
59       EVP_DigestSignInit_ex then it will use the OSSL_LIB_CTX specified in
60       libctx and the property query string specified in props.
61
62       The digest mdname may be NULL if the signing algorithm supports it. The
63       props argument can always be NULL.
64
65       No EVP_PKEY_CTX will be created by EVP_DigestSignInit_ex() if the
66       passed ctx has already been assigned one via
67       EVP_MD_CTX_set_pkey_ctx(3).  See also SM2(7).
68
69       Only EVP_PKEY types that support signing can be used with these
70       functions. This includes MAC algorithms where the MAC generation is
71       considered as a form of "signing". Built-in EVP_PKEY types supported by
72       these functions are CMAC, Poly1305, DSA, ECDSA, HMAC, RSA, SipHash,
73       Ed25519 and Ed448.
74
75       Not all digests can be used for all key types. The following
76       combinations apply.
77
78       DSA Supports SHA1, SHA224, SHA256, SHA384 and SHA512
79
80       ECDSA
81           Supports SHA1, SHA224, SHA256, SHA384, SHA512 and SM3
82
83       RSA with no padding
84           Supports no digests (the digest type must be NULL)
85
86       RSA with X931 padding
87           Supports SHA1, SHA256, SHA384 and SHA512
88
89       All other RSA padding types
90           Support SHA1, SHA224, SHA256, SHA384, SHA512, MD5, MD5_SHA1, MD2,
91           MD4, MDC2, SHA3-224, SHA3-256, SHA3-384, SHA3-512
92
93       Ed25519 and Ed448
94           Support no digests (the digest type must be NULL)
95
96       HMAC
97           Supports any digest
98
99       CMAC, Poly1305 and SipHash
100           Will ignore any digest provided.
101
102       If RSA-PSS is used and restrictions apply then the digest must match.
103
104       EVP_DigestSignInit() works in the same way as EVP_DigestSignInit_ex()
105       except that the mdname parameter will be inferred from the supplied
106       digest type, and props will be NULL. Where supplied the ENGINE e will
107       be used for the signing and digest algorithm implementations. e may be
108       NULL.
109
110       EVP_DigestSignUpdate() hashes cnt bytes of data at d into the signature
111       context ctx. This function can be called several times on the same ctx
112       to include additional data.
113
114       Unless sig is NULL EVP_DigestSignFinal() signs the data in ctx and
115       places the signature in sig.  Otherwise the maximum necessary size of
116       the output buffer is written to the siglen parameter. If sig is not
117       NULL then before the call the siglen parameter should contain the
118       length of the sig buffer. If the call is successful the signature is
119       written to sig and the amount of data written to siglen.
120
121       EVP_DigestSign() signs tbslen bytes of data at tbs and places the
122       signature in sig and its length in siglen in a similar way to
123       EVP_DigestSignFinal(). In the event of a failure EVP_DigestSign()
124       cannot be called again without reinitialising the EVP_MD_CTX. If sig is
125       NULL before the call then siglen will be populated with the required
126       size for the sig buffer. If sig is non-NULL before the call then siglen
127       should contain the length of the sig buffer.
128

RETURN VALUES

130       EVP_DigestSignInit(), EVP_DigestSignUpdate(), EVP_DigestSignFinal() and
131       EVP_DigestSign() return 1 for success and 0 for failure.
132
133       The error codes can be obtained from ERR_get_error(3).
134

NOTES

136       The EVP interface to digital signatures should almost always be used in
137       preference to the low-level interfaces. This is because the code then
138       becomes transparent to the algorithm used and much more flexible.
139
140       EVP_DigestSign() is a one shot operation which signs a single block of
141       data in one function. For algorithms that support streaming it is
142       equivalent to calling EVP_DigestSignUpdate() and EVP_DigestSignFinal().
143       For algorithms which do not support streaming (e.g. PureEdDSA) it is
144       the only way to sign data.
145
146       In previous versions of OpenSSL there was a link between message digest
147       types and public key algorithms. This meant that "clone" digests such
148       as EVP_dss1() needed to be used to sign using SHA1 and DSA. This is no
149       longer necessary and the use of clone digest is now discouraged.
150
151       For some key types and parameters the random number generator must be
152       seeded.  If the automatic seeding or reseeding of the OpenSSL CSPRNG
153       fails due to external circumstances (see RAND(7)), the operation will
154       fail.
155
156       The call to EVP_DigestSignFinal() internally finalizes a copy of the
157       digest context. This means that calls to EVP_DigestSignUpdate() and
158       EVP_DigestSignFinal() can be called later to digest and sign additional
159       data.
160
161       EVP_DigestSignInit() and EVP_DigestSignInit_ex() functions can be
162       called multiple times on a context and the parameters set by previous
163       calls should be preserved if the pkey parameter is NULL. The call then
164       just resets the state of the ctx.
165
166       The use of EVP_PKEY_get_size() with these functions is discouraged
167       because some signature operations may have a signature length which
168       depends on the parameters set. As a result EVP_PKEY_get_size() would
169       have to return a value which indicates the maximum possible signature
170       for any set of parameters.
171

SEE ALSO

173       EVP_DigestVerifyInit(3), EVP_DigestInit(3), evp(7), HMAC(3), MD2(3),
174       MD5(3), MDC2(3), RIPEMD160(3), SHA1(3), openssl-dgst(1), RAND(7)
175

HISTORY

177       EVP_DigestSignInit(), EVP_DigestSignUpdate() and EVP_DigestSignFinal()
178       were added in OpenSSL 1.0.0.
179
180       EVP_DigestSignInit_ex() was added in OpenSSL 3.0.
181
182       EVP_DigestSignUpdate() was converted from a macro to a function in
183       OpenSSL 3.0.
184
186       Copyright 2006-2022 The OpenSSL Project Authors. All Rights Reserved.
187
188       Licensed under the Apache License 2.0 (the "License").  You may not use
189       this file except in compliance with the License.  You can obtain a copy
190       in the file LICENSE in the source distribution or at
191       <https://www.openssl.org/source/license.html>.
192
193
194
1953.0.5                             2022-07-05         EVP_DIGESTSIGNINIT(3ossl)
Impressum