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_ctx(3). See also
40 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_DigestSignaFinal()
95 and EVP_DigestSign() return 1 for success and 0 or a negative value for
96 failure. In particular, a return value of -2 indicates the operation is
97 not supported by the public key algorithm.
98
99 The error codes can be obtained from ERR_get_error(3).
100
102 The EVP interface to digital signatures should almost always be used in
103 preference to the low level interfaces. This is because the code then
104 becomes transparent to the algorithm used and much more flexible.
105
106 EVP_DigestSign() is a one shot operation which signs a single block of
107 data in one function. For algorithms that support streaming it is
108 equivalent to calling EVP_DigestSignUpdate() and EVP_DigestSignFinal().
109 For algorithms which do not support streaming (e.g. PureEdDSA) it is
110 the only way to sign data.
111
112 In previous versions of OpenSSL there was a link between message digest
113 types and public key algorithms. This meant that "clone" digests such
114 as EVP_dss1() needed to be used to sign using SHA1 and DSA. This is no
115 longer necessary and the use of clone digest is now discouraged.
116
117 For some key types and parameters the random number generator must be
118 seeded. If the automatic seeding or reseeding of the OpenSSL CSPRNG
119 fails due to external circumstances (see RAND(7)), the operation will
120 fail.
121
122 The call to EVP_DigestSignFinal() internally finalizes a copy of the
123 digest context. This means that calls to EVP_DigestSignUpdate() and
124 EVP_DigestSignFinal() can be called later to digest and sign additional
125 data.
126
127 Since only a copy of the digest context is ever finalized, the context
128 must be cleaned up after use by calling EVP_MD_CTX_free() or a memory
129 leak will occur.
130
131 The use of EVP_PKEY_size() with these functions is discouraged because
132 some signature operations may have a signature length which depends on
133 the parameters set. As a result EVP_PKEY_size() would have to return a
134 value which indicates the maximum possible signature for any set of
135 parameters.
136
138 EVP_DigestVerifyInit(3), EVP_DigestInit(3), evp(7), HMAC(3), MD2(3),
139 MD5(3), MDC2(3), RIPEMD160(3), SHA1(3), dgst(1), RAND(7)
140
142 EVP_DigestSignInit(), EVP_DigestSignUpdate() and EVP_DigestSignFinal()
143 were added in OpenSSL 1.0.0.
144
146 Copyright 2006-2019 The OpenSSL Project Authors. All Rights Reserved.
147
148 Licensed under the OpenSSL license (the "License"). You may not use
149 this file except in compliance with the License. You can obtain a copy
150 in the file LICENSE in the source distribution or at
151 <https://www.openssl.org/source/license.html>.
152
153
154
1551.1.1d 2019-10-03 EVP_DIGESTSIGNINIT(3)