EVP_DigestSignInit.3ossl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "EVP_DIGESTSIGNINIT 3ossl"
  58. .TH EVP_DIGESTSIGNINIT 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. EVP_DigestSignInit_ex, EVP_DigestSignInit, EVP_DigestSignUpdate,
  65. EVP_DigestSignFinal, EVP_DigestSign \- EVP signing functions
  66. .SH SYNOPSIS
  67. .IX Header "SYNOPSIS"
  68. .Vb 1
  69. \& #include <openssl/evp.h>
  70. \&
  71. \& int EVP_DigestSignInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
  72. \& const char *mdname, OSSL_LIB_CTX *libctx,
  73. \& const char *props, EVP_PKEY *pkey,
  74. \& const OSSL_PARAM params[]);
  75. \& int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
  76. \& const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
  77. \& int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
  78. \& int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen);
  79. \&
  80. \& int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sig,
  81. \& size_t *siglen, const unsigned char *tbs,
  82. \& size_t tbslen);
  83. .Ve
  84. .SH DESCRIPTION
  85. .IX Header "DESCRIPTION"
  86. The EVP signature routines are a high-level interface to digital signatures.
  87. Input data is digested first before the signing takes place.
  88. .PP
  89. \&\fBEVP_DigestSignInit_ex()\fR sets up signing context \fIctx\fR to use a digest
  90. with the name \fImdname\fR and private key \fIpkey\fR. The name of the digest to be
  91. used is passed to the provider of the signature algorithm in use. How that
  92. provider interprets the digest name is provider specific. The provider may
  93. implement that digest directly itself or it may (optionally) choose to fetch it
  94. (which could result in a digest from a different provider being selected). If the
  95. provider supports fetching the digest then it may use the \fIprops\fR argument for
  96. the properties to be used during the fetch. Finally, the passed parameters
  97. \&\fIparams\fR, if not NULL, are set on the context before returning.
  98. .PP
  99. The \fIpkey\fR algorithm is used to fetch a \fBEVP_SIGNATURE\fR method implicitly, to
  100. be used for the actual signing. See "Implicit fetch" in \fBprovider\fR\|(7) for
  101. more information about implicit fetches.
  102. .PP
  103. The OpenSSL default and legacy providers support fetching digests and can fetch
  104. those digests from any available provider. The OpenSSL FIPS provider also
  105. supports fetching digests but will only fetch digests that are themselves
  106. implemented inside the FIPS provider.
  107. .PP
  108. \&\fIctx\fR must be created with \fBEVP_MD_CTX_new()\fR before calling this function. If
  109. \&\fIpctx\fR is not NULL, the EVP_PKEY_CTX of the signing operation will be written
  110. to \fI*pctx\fR: this can be used to set alternative signing options. Note that any
  111. existing value in \fI*pctx\fR is overwritten. The EVP_PKEY_CTX value returned must
  112. not be freed directly by the application if \fIctx\fR is not assigned an
  113. EVP_PKEY_CTX value before being passed to \fBEVP_DigestSignInit_ex()\fR
  114. (which means the EVP_PKEY_CTX is created inside \fBEVP_DigestSignInit_ex()\fR
  115. and it will be freed automatically when the EVP_MD_CTX is freed). If the
  116. EVP_PKEY_CTX to be used is created by EVP_DigestSignInit_ex then it
  117. will use the \fBOSSL_LIB_CTX\fR specified in \fIlibctx\fR and the property query string
  118. specified in \fIprops\fR.
  119. .PP
  120. The digest \fImdname\fR may be NULL if the signing algorithm supports it. The
  121. \&\fIprops\fR argument can always be NULL.
  122. .PP
  123. No \fBEVP_PKEY_CTX\fR will be created by \fBEVP_DigestSignInit_ex()\fR if the
  124. passed \fIctx\fR has already been assigned one via \fBEVP_MD_CTX_set_pkey_ctx\fR\|(3).
  125. See also \fBSM2\fR\|(7).
  126. .PP
  127. Only EVP_PKEY types that support signing can be used with these functions. This
  128. includes MAC algorithms where the MAC generation is considered as a form of
  129. "signing". Built-in EVP_PKEY types supported by these functions are CMAC,
  130. Poly1305, DSA, ECDSA, HMAC, RSA, SipHash, Ed25519 and Ed448.
  131. .PP
  132. Not all digests can be used for all key types. The following combinations apply.
  133. .IP DSA 4
  134. .IX Item "DSA"
  135. Supports SHA1, SHA224, SHA256, SHA384 and SHA512
  136. .IP ECDSA 4
  137. .IX Item "ECDSA"
  138. Supports SHA1, SHA224, SHA256, SHA384, SHA512 and SM3
  139. .IP "RSA with no padding" 4
  140. .IX Item "RSA with no padding"
  141. Supports no digests (the digest \fItype\fR must be NULL)
  142. .IP "RSA with X931 padding" 4
  143. .IX Item "RSA with X931 padding"
  144. Supports SHA1, SHA256, SHA384 and SHA512
  145. .IP "All other RSA padding types" 4
  146. .IX Item "All other RSA padding types"
  147. Support SHA1, SHA224, SHA256, SHA384, SHA512, MD5, MD5_SHA1, MD2, MD4, MDC2,
  148. SHA3\-224, SHA3\-256, SHA3\-384, SHA3\-512
  149. .IP "Ed25519 and Ed448" 4
  150. .IX Item "Ed25519 and Ed448"
  151. Support no digests (the digest \fItype\fR must be NULL)
  152. .IP HMAC 4
  153. .IX Item "HMAC"
  154. Supports any digest
  155. .IP "CMAC, Poly1305 and SipHash" 4
  156. .IX Item "CMAC, Poly1305 and SipHash"
  157. Will ignore any digest provided.
  158. .PP
  159. If RSA-PSS is used and restrictions apply then the digest must match.
  160. .PP
  161. \&\fBEVP_DigestSignInit()\fR works in the same way as \fBEVP_DigestSignInit_ex()\fR
  162. except that the \fImdname\fR parameter will be inferred from the supplied
  163. digest \fItype\fR, and \fIprops\fR will be NULL. Where supplied the ENGINE \fIe\fR will
  164. be used for the signing and digest algorithm implementations. \fIe\fR may be NULL.
  165. .PP
  166. \&\fBEVP_DigestSignUpdate()\fR hashes \fIcnt\fR bytes of data at \fId\fR into the
  167. signature context \fIctx\fR. This function can be called several times on the
  168. same \fIctx\fR to include additional data.
  169. .PP
  170. Unless \fIsig\fR is NULL \fBEVP_DigestSignFinal()\fR signs the data in \fIctx\fR
  171. and places the signature in \fIsig\fR.
  172. Otherwise the maximum necessary size of the output buffer is written to
  173. the \fIsiglen\fR parameter. If \fIsig\fR is not NULL then before the call the
  174. \&\fIsiglen\fR parameter should contain the length of the \fIsig\fR buffer. If the
  175. call is successful the signature is written to \fIsig\fR and the amount of data
  176. written to \fIsiglen\fR.
  177. .PP
  178. \&\fBEVP_DigestSign()\fR is similar to a single call to \fBEVP_DigestSignUpdate()\fR and
  179. \&\fBEVP_DigestSignFinal()\fR.
  180. Unless \fIsig\fR is NULL, \fBEVP_DigestSign()\fR signs the data \fItbs\fR of length \fItbslen\fR
  181. bytes and places the signature in a buffer \fIsig\fR of size \fIsiglen\fR.
  182. If \fIsig\fR is NULL, the maximum necessary size of the signature buffer is written
  183. to the \fIsiglen\fR parameter.
  184. .SH "RETURN VALUES"
  185. .IX Header "RETURN VALUES"
  186. \&\fBEVP_DigestSignInit()\fR, \fBEVP_DigestSignUpdate()\fR, \fBEVP_DigestSignFinal()\fR and
  187. \&\fBEVP_DigestSign()\fR return 1 for success and 0 for failure.
  188. .PP
  189. The error codes can be obtained from \fBERR_get_error\fR\|(3).
  190. .SH NOTES
  191. .IX Header "NOTES"
  192. The \fBEVP\fR interface to digital signatures should almost always be used in
  193. preference to the low-level interfaces. This is because the code then becomes
  194. transparent to the algorithm used and much more flexible.
  195. .PP
  196. \&\fBEVP_DigestSign()\fR is a one shot operation which signs a single block of data
  197. in one function. For algorithms that support streaming it is equivalent to
  198. calling \fBEVP_DigestSignUpdate()\fR and \fBEVP_DigestSignFinal()\fR. For algorithms which
  199. do not support streaming (e.g. PureEdDSA) it is the only way to sign data.
  200. .PP
  201. In previous versions of OpenSSL there was a link between message digest types
  202. and public key algorithms. This meant that "clone" digests such as \fBEVP_dss1()\fR
  203. needed to be used to sign using SHA1 and DSA. This is no longer necessary and
  204. the use of clone digest is now discouraged.
  205. .PP
  206. For some key types and parameters the random number generator must be seeded.
  207. If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
  208. external circumstances (see \fBRAND\fR\|(7)), the operation will fail.
  209. .PP
  210. The call to \fBEVP_DigestSignFinal()\fR internally finalizes a copy of the digest
  211. context. This means that calls to \fBEVP_DigestSignUpdate()\fR and
  212. \&\fBEVP_DigestSignFinal()\fR can be called later to digest and sign additional data.
  213. Applications may disable this behavior by setting the EVP_MD_CTX_FLAG_FINALISE
  214. context flag via \fBEVP_MD_CTX_set_flags\fR\|(3).
  215. .PP
  216. Note that not all providers support continuation, in case the selected
  217. provider does not allow to duplicate contexts \fBEVP_DigestSignFinal()\fR will
  218. finalize the digest context and attempting to process additional data via
  219. \&\fBEVP_DigestSignUpdate()\fR will result in an error.
  220. .PP
  221. \&\fBEVP_DigestSignInit()\fR and \fBEVP_DigestSignInit_ex()\fR functions can be called
  222. multiple times on a context and the parameters set by previous calls should be
  223. preserved if the \fIpkey\fR parameter is NULL. The call then just resets the state
  224. of the \fIctx\fR.
  225. .PP
  226. \&\fBEVP_DigestSign()\fR can not be called again, once a signature is generated (by
  227. passing \fIsig\fR as non NULL), unless the \fBEVP_MD_CTX\fR is reinitialised by
  228. calling \fBEVP_DigestSignInit_ex()\fR.
  229. .PP
  230. Ignoring failure returns of \fBEVP_DigestSignInit()\fR and \fBEVP_DigestSignInit_ex()\fR
  231. functions can lead to subsequent undefined behavior when calling
  232. \&\fBEVP_DigestSignUpdate()\fR, \fBEVP_DigestSignFinal()\fR, or \fBEVP_DigestSign()\fR.
  233. .PP
  234. The use of \fBEVP_PKEY_get_size()\fR with these functions is discouraged because some
  235. signature operations may have a signature length which depends on the
  236. parameters set. As a result \fBEVP_PKEY_get_size()\fR would have to return a value
  237. which indicates the maximum possible signature for any set of parameters.
  238. .SH "SEE ALSO"
  239. .IX Header "SEE ALSO"
  240. \&\fBEVP_DigestVerifyInit\fR\|(3),
  241. \&\fBEVP_DigestInit\fR\|(3),
  242. \&\fBevp\fR\|(7), \fBHMAC\fR\|(3), \fBMD2\fR\|(3),
  243. \&\fBMD5\fR\|(3), \fBMDC2\fR\|(3), \fBRIPEMD160\fR\|(3),
  244. \&\fBSHA1\fR\|(3), \fBopenssl\-dgst\fR\|(1),
  245. \&\fBRAND\fR\|(7)
  246. .SH HISTORY
  247. .IX Header "HISTORY"
  248. \&\fBEVP_DigestSignInit()\fR, \fBEVP_DigestSignUpdate()\fR and \fBEVP_DigestSignFinal()\fR
  249. were added in OpenSSL 1.0.0.
  250. .PP
  251. \&\fBEVP_DigestSignInit_ex()\fR was added in OpenSSL 3.0.
  252. .PP
  253. \&\fBEVP_DigestSignUpdate()\fR was converted from a macro to a function in OpenSSL 3.0.
  254. .SH COPYRIGHT
  255. .IX Header "COPYRIGHT"
  256. Copyright 2006\-2024 The OpenSSL Project Authors. All Rights Reserved.
  257. .PP
  258. Licensed under the Apache License 2.0 (the "License"). You may not use
  259. this file except in compliance with the License. You can obtain a copy
  260. in the file LICENSE in the source distribution or at
  261. <https://www.openssl.org/source/license.html>.