EVP_DigestVerifyInit.3ossl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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_DIGESTVERIFYINIT 3ossl"
  58. .TH EVP_DIGESTVERIFYINIT 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_DigestVerifyInit_ex, EVP_DigestVerifyInit, EVP_DigestVerifyUpdate,
  65. EVP_DigestVerifyFinal, EVP_DigestVerify \- EVP signature verification functions
  66. .SH SYNOPSIS
  67. .IX Header "SYNOPSIS"
  68. .Vb 1
  69. \& #include <openssl/evp.h>
  70. \&
  71. \& int EVP_DigestVerifyInit_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_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
  76. \& const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
  77. \& int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
  78. \& int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
  79. \& size_t siglen);
  80. \& int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sig,
  81. \& size_t siglen, const unsigned char *tbs, size_t tbslen);
  82. .Ve
  83. .SH DESCRIPTION
  84. .IX Header "DESCRIPTION"
  85. The EVP signature routines are a high-level interface to digital signatures.
  86. Input data is digested first before the signature verification takes place.
  87. .PP
  88. \&\fBEVP_DigestVerifyInit_ex()\fR sets up verification context \fBctx\fR to use a
  89. digest with the name \fBmdname\fR and public key \fBpkey\fR. The name of the digest to
  90. be used is passed to the provider of the signature algorithm in use. How that
  91. provider interprets the digest name is provider specific. The provider may
  92. implement that digest directly itself or it may (optionally) choose to fetch it
  93. (which could result in a digest from a different provider being selected). If
  94. the provider supports fetching the digest then it may use the \fBprops\fR argument
  95. for the properties to be used during the fetch. Finally, the passed parameters
  96. \&\fIparams\fR, if not NULL, are set on the context before returning.
  97. .PP
  98. The \fIpkey\fR algorithm is used to fetch a \fBEVP_SIGNATURE\fR method implicitly, to
  99. be used for the actual signing. See "Implicit fetch" in \fBprovider\fR\|(7) for
  100. more information about implicit fetches.
  101. .PP
  102. The OpenSSL default and legacy providers support fetching digests and can fetch
  103. those digests from any available provider. The OpenSSL FIPS provider also
  104. supports fetching digests but will only fetch digests that are themselves
  105. implemented inside the FIPS provider.
  106. .PP
  107. \&\fBctx\fR must be created with \fBEVP_MD_CTX_new()\fR before calling this function. If
  108. \&\fBpctx\fR is not NULL, the EVP_PKEY_CTX of the verification operation will be
  109. written to \fB*pctx\fR: this can be used to set alternative verification options.
  110. Note that any existing value in \fB*pctx\fR is overwritten. The EVP_PKEY_CTX value
  111. returned must not be freed directly by the application if \fBctx\fR is not assigned
  112. an EVP_PKEY_CTX value before being passed to \fBEVP_DigestVerifyInit_ex()\fR
  113. (which means the EVP_PKEY_CTX is created inside
  114. \&\fBEVP_DigestVerifyInit_ex()\fR and it will be freed automatically when the
  115. EVP_MD_CTX is freed). If the EVP_PKEY_CTX to be used is created by
  116. EVP_DigestVerifyInit_ex then it will use the \fBOSSL_LIB_CTX\fR specified
  117. in \fIlibctx\fR and the property query string specified in \fIprops\fR.
  118. .PP
  119. No \fBEVP_PKEY_CTX\fR will be created by \fBEVP_DigestVerifyInit_ex()\fR if the
  120. passed \fBctx\fR has already been assigned one via \fBEVP_MD_CTX_set_pkey_ctx\fR\|(3).
  121. See also \fBSM2\fR\|(7).
  122. .PP
  123. Not all digests can be used for all key types. The following combinations apply.
  124. .IP DSA 4
  125. .IX Item "DSA"
  126. Supports SHA1, SHA224, SHA256, SHA384 and SHA512
  127. .IP ECDSA 4
  128. .IX Item "ECDSA"
  129. Supports SHA1, SHA224, SHA256, SHA384, SHA512 and SM3
  130. .IP "RSA with no padding" 4
  131. .IX Item "RSA with no padding"
  132. Supports no digests (the digest \fBtype\fR must be NULL)
  133. .IP "RSA with X931 padding" 4
  134. .IX Item "RSA with X931 padding"
  135. Supports SHA1, SHA256, SHA384 and SHA512
  136. .IP "All other RSA padding types" 4
  137. .IX Item "All other RSA padding types"
  138. Support SHA1, SHA224, SHA256, SHA384, SHA512, MD5, MD5_SHA1, MD2, MD4, MDC2,
  139. SHA3\-224, SHA3\-256, SHA3\-384, SHA3\-512
  140. .IP "Ed25519 and Ed448" 4
  141. .IX Item "Ed25519 and Ed448"
  142. Support no digests (the digest \fBtype\fR must be NULL)
  143. .IP HMAC 4
  144. .IX Item "HMAC"
  145. Supports any digest
  146. .IP "CMAC, Poly1305 and Siphash" 4
  147. .IX Item "CMAC, Poly1305 and Siphash"
  148. Will ignore any digest provided.
  149. .PP
  150. If RSA-PSS is used and restrictions apply then the digest must match.
  151. .PP
  152. \&\fBEVP_DigestVerifyInit()\fR works in the same way as
  153. \&\fBEVP_DigestVerifyInit_ex()\fR except that the \fBmdname\fR parameter will be
  154. inferred from the supplied digest \fBtype\fR, and \fBprops\fR will be NULL. Where
  155. supplied the ENGINE \fBe\fR will be used for the signature verification and digest
  156. algorithm implementations. \fBe\fR may be NULL.
  157. .PP
  158. \&\fBEVP_DigestVerifyUpdate()\fR hashes \fBcnt\fR bytes of data at \fBd\fR into the
  159. verification context \fBctx\fR. This function can be called several times on the
  160. same \fBctx\fR to include additional data.
  161. .PP
  162. \&\fBEVP_DigestVerifyFinal()\fR verifies the data in \fBctx\fR against the signature in
  163. \&\fBsig\fR of length \fBsiglen\fR.
  164. .PP
  165. \&\fBEVP_DigestVerify()\fR verifies \fBtbslen\fR bytes at \fBtbs\fR against the signature
  166. in \fBsig\fR of length \fBsiglen\fR.
  167. .SH "RETURN VALUES"
  168. .IX Header "RETURN VALUES"
  169. \&\fBEVP_DigestVerifyInit()\fR and \fBEVP_DigestVerifyUpdate()\fR return 1 for success and 0
  170. for failure.
  171. .PP
  172. \&\fBEVP_DigestVerifyFinal()\fR and \fBEVP_DigestVerify()\fR return 1 for success; any other
  173. value indicates failure. A return value of zero indicates that the signature
  174. did not verify successfully (that is, \fBtbs\fR did not match the original data or
  175. the signature had an invalid form), while other values indicate a more serious
  176. error (and sometimes also indicate an invalid signature form).
  177. .PP
  178. The error codes can be obtained from \fBERR_get_error\fR\|(3).
  179. .SH NOTES
  180. .IX Header "NOTES"
  181. The \fBEVP\fR interface to digital signatures should almost always be used in
  182. preference to the low-level interfaces. This is because the code then becomes
  183. transparent to the algorithm used and much more flexible.
  184. .PP
  185. \&\fBEVP_DigestVerify()\fR is a one shot operation which verifies a single block of
  186. data in one function. For algorithms that support streaming it is equivalent
  187. to calling \fBEVP_DigestVerifyUpdate()\fR and \fBEVP_DigestVerifyFinal()\fR. For
  188. algorithms which do not support streaming (e.g. PureEdDSA) it is the only way
  189. to verify data.
  190. .PP
  191. In previous versions of OpenSSL there was a link between message digest types
  192. and public key algorithms. This meant that "clone" digests such as \fBEVP_dss1()\fR
  193. needed to be used to sign using SHA1 and DSA. This is no longer necessary and
  194. the use of clone digest is now discouraged.
  195. .PP
  196. For some key types and parameters the random number generator must be seeded.
  197. If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
  198. external circumstances (see \fBRAND\fR\|(7)), the operation will fail.
  199. .PP
  200. The call to \fBEVP_DigestVerifyFinal()\fR internally finalizes a copy of the digest
  201. context. This means that \fBEVP_VerifyUpdate()\fR and \fBEVP_VerifyFinal()\fR can
  202. be called later to digest and verify additional data. Applications may disable
  203. this behavior by setting the EVP_MD_CTX_FLAG_FINALISE context flag via
  204. \&\fBEVP_MD_CTX_set_flags\fR\|(3).
  205. .PP
  206. Note that not all providers support continuation, in case the selected
  207. provider does not allow to duplicate contexts \fBEVP_DigestVerifyFinal()\fR will
  208. finalize the digest context and attempting to process additional data via
  209. \&\fBEVP_DigestVerifyUpdate()\fR will result in an error.
  210. .PP
  211. \&\fBEVP_DigestVerifyInit()\fR and \fBEVP_DigestVerifyInit_ex()\fR functions can be called
  212. multiple times on a context and the parameters set by previous calls should be
  213. preserved if the \fIpkey\fR parameter is NULL. The call then just resets the state
  214. of the \fIctx\fR.
  215. .PP
  216. \&\fBEVP_DigestVerify()\fR can only be called once, and cannot be used again without
  217. reinitialising the \fBEVP_MD_CTX\fR by calling \fBEVP_DigestVerifyInit_ex()\fR.
  218. .PP
  219. Ignoring failure returns of \fBEVP_DigestVerifyInit()\fR and \fBEVP_DigestVerifyInit_ex()\fR
  220. functions can lead to subsequent undefined behavior when calling
  221. \&\fBEVP_DigestVerifyUpdate()\fR, \fBEVP_DigestVerifyFinal()\fR, or \fBEVP_DigestVerify()\fR.
  222. .SH "SEE ALSO"
  223. .IX Header "SEE ALSO"
  224. \&\fBEVP_DigestSignInit\fR\|(3),
  225. \&\fBEVP_DigestInit\fR\|(3),
  226. \&\fBevp\fR\|(7), \fBHMAC\fR\|(3), \fBMD2\fR\|(3),
  227. \&\fBMD5\fR\|(3), \fBMDC2\fR\|(3), \fBRIPEMD160\fR\|(3),
  228. \&\fBSHA1\fR\|(3), \fBopenssl\-dgst\fR\|(1),
  229. \&\fBRAND\fR\|(7)
  230. .SH HISTORY
  231. .IX Header "HISTORY"
  232. \&\fBEVP_DigestVerifyInit()\fR, \fBEVP_DigestVerifyUpdate()\fR and \fBEVP_DigestVerifyFinal()\fR
  233. were added in OpenSSL 1.0.0.
  234. .PP
  235. \&\fBEVP_DigestVerifyInit_ex()\fR was added in OpenSSL 3.0.
  236. .PP
  237. \&\fBEVP_DigestVerifyUpdate()\fR was converted from a macro to a function in OpenSSL
  238. 3.0.
  239. .SH COPYRIGHT
  240. .IX Header "COPYRIGHT"
  241. Copyright 2006\-2024 The OpenSSL Project Authors. All Rights Reserved.
  242. .PP
  243. Licensed under the Apache License 2.0 (the "License"). You may not use
  244. this file except in compliance with the License. You can obtain a copy
  245. in the file LICENSE in the source distribution or at
  246. <https://www.openssl.org/source/license.html>.