1EVP_DIGESTSIGNINIT(3) OpenSSL EVP_DIGESTSIGNINIT(3)
2
3
4
6 EVP_DigestSignInit, EVP_DigestSignUpdate, EVP_DigestSignFinal,
7 EVP_DigestSign - EVP signing functions
8
10 #include <openssl/evp.h>
11
12 int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
13 const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
14 int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
15 int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen);
16
17 int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret,
18 size_t *siglen, const unsigned char *tbs,
19 size_t tbslen);
20
22 The EVP signature routines are a high-level interface to digital
23 signatures.
24
25 EVP_DigestSignInit() sets up signing context ctx to use digest type
26 from ENGINE e and private key pkey. ctx must be created with
27 EVP_MD_CTX_new() before calling this function. If pctx is not NULL, the
28 EVP_PKEY_CTX of the signing operation will be written to *pctx: this
29 can be used to set alternative signing options. Note that any existing
30 value in *pctx is overwritten. The EVP_PKEY_CTX value returned must not
31 be freed directly by the application if ctx is not assigned an
32 EVP_PKEY_CTX value before being passed to EVP_DigestSignInit() (which
33 means the EVP_PKEY_CTX is created inside EVP_DigestSignInit() and it
34 will be freed automatically when the EVP_MD_CTX is freed).
35
36 The digest type may be NULL if the signing algorithm supports it.
37
38 No EVP_PKEY_CTX will be created by EVP_DigestSignInit() if the passed
39 ctx has already been assigned one via EVP_MD_CTX_set_pkey_ctx(3). See
40 also SM2(7).
41
42 Only EVP_PKEY types that support signing can be used with these
43 functions. This includes MAC algorithms where the MAC generation is
44 considered as a form of "signing". Built-in EVP_PKEY types supported by
45 these functions are CMAC, Poly1305, DSA, ECDSA, HMAC, RSA, SipHash,
46 Ed25519 and Ed448.
47
48 Not all digests can be used for all key types. The following
49 combinations apply.
50
51 DSA Supports SHA1, SHA224, SHA256, SHA384 and SHA512
52
53 ECDSA
54 Supports SHA1, SHA224, SHA256, SHA384, SHA512 and SM3
55
56 RSA with no padding
57 Supports no digests (the digest type must be NULL)
58
59 RSA with X931 padding
60 Supports SHA1, SHA256, SHA384 and SHA512
61
62 All other RSA padding types
63 Support SHA1, SHA224, SHA256, SHA384, SHA512, MD5, MD5_SHA1, MD2,
64 MD4, MDC2, SHA3-224, SHA3-256, SHA3-384, SHA3-512
65
66 Ed25519 and Ed448
67 Support no digests (the digest type must be NULL)
68
69 HMAC
70 Supports any digest
71
72 CMAC, Poly1305 and SipHash
73 Will ignore any digest provided.
74
75 If RSA-PSS is used and restrictions apply then the digest must match.
76
77 EVP_DigestSignUpdate() hashes cnt bytes of data at d into the signature
78 context ctx. This function can be called several times on the same ctx
79 to include additional data. This function is currently implemented
80 using a macro.
81
82 EVP_DigestSignFinal() signs the data in ctx and places the signature in
83 sig. If sig is NULL then the maximum size of the output buffer is
84 written to the siglen parameter. If sig is not NULL then before the
85 call the siglen parameter should contain the length of the sig buffer.
86 If the call is successful the signature is written to sig and the
87 amount of data written to siglen.
88
89 EVP_DigestSign() signs tbslen bytes of data at tbs and places the
90 signature in sig and its length in siglen in a similar way to
91 EVP_DigestSignFinal().
92
94 EVP_DigestSignInit(), EVP_DigestSignUpdate(), EVP_DigestSignFinal() and
95 EVP_DigestSign() return 1 for success and 0 for failure.
96
97 The error codes can be obtained from ERR_get_error(3).
98
100 The EVP interface to digital signatures should almost always be used in
101 preference to the low-level interfaces. This is because the code then
102 becomes transparent to the algorithm used and much more flexible.
103
104 EVP_DigestSign() is a one shot operation which signs a single block of
105 data in one function. For algorithms that support streaming it is
106 equivalent to calling EVP_DigestSignUpdate() and EVP_DigestSignFinal().
107 For algorithms which do not support streaming (e.g. PureEdDSA) it is
108 the only way to sign data.
109
110 In previous versions of OpenSSL there was a link between message digest
111 types and public key algorithms. This meant that "clone" digests such
112 as EVP_dss1() needed to be used to sign using SHA1 and DSA. This is no
113 longer necessary and the use of clone digest is now discouraged.
114
115 For some key types and parameters the random number generator must be
116 seeded. If the automatic seeding or reseeding of the OpenSSL CSPRNG
117 fails due to external circumstances (see RAND(7)), the operation will
118 fail.
119
120 The call to EVP_DigestSignFinal() internally finalizes a copy of the
121 digest context. This means that calls to EVP_DigestSignUpdate() and
122 EVP_DigestSignFinal() can be called later to digest and sign additional
123 data.
124
125 Since only a copy of the digest context is ever finalized, the context
126 must be cleaned up after use by calling EVP_MD_CTX_free() or a memory
127 leak will occur.
128
129 The use of EVP_PKEY_size() with these functions is discouraged because
130 some signature operations may have a signature length which depends on
131 the parameters set. As a result EVP_PKEY_size() would have to return a
132 value which indicates the maximum possible signature for any set of
133 parameters.
134
136 EVP_DigestVerifyInit(3), EVP_DigestInit(3), evp(7), HMAC(3), MD2(3),
137 MD5(3), MDC2(3), RIPEMD160(3), SHA1(3), dgst(1), RAND(7)
138
140 EVP_DigestSignInit(), EVP_DigestSignUpdate() and EVP_DigestSignFinal()
141 were added in OpenSSL 1.0.0.
142
144 Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved.
145
146 Licensed under the OpenSSL license (the "License"). You may not use
147 this file except in compliance with the License. You can obtain a copy
148 in the file LICENSE in the source distribution or at
149 <https://www.openssl.org/source/license.html>.
150
151
152
1531.1.1l 2021-09-15 EVP_DIGESTSIGNINIT(3)