2
0

EVP_DigestVerifyInit.pod 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. =pod
  2. =head1 NAME
  3. EVP_DigestVerifyInit_ex, EVP_DigestVerifyInit, EVP_DigestVerifyUpdate,
  4. EVP_DigestVerifyFinal, EVP_DigestVerify - EVP signature verification functions
  5. =head1 SYNOPSIS
  6. #include <openssl/evp.h>
  7. int EVP_DigestVerifyInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
  8. const char *mdname, OSSL_LIB_CTX *libctx,
  9. const char *props, EVP_PKEY *pkey,
  10. const OSSL_PARAM params[]);
  11. int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
  12. const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
  13. int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
  14. int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
  15. size_t siglen);
  16. int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sig,
  17. size_t siglen, const unsigned char *tbs, size_t tbslen);
  18. =head1 DESCRIPTION
  19. The EVP signature routines are a high-level interface to digital signatures.
  20. Input data is digested first before the signature verification takes place.
  21. EVP_DigestVerifyInit_ex() sets up verification context B<ctx> to use a
  22. digest with the name B<mdname> and public key B<pkey>. The name of the digest to
  23. be used is passed to the provider of the signature algorithm in use. How that
  24. provider interprets the digest name is provider specific. The provider may
  25. implement that digest directly itself or it may (optionally) choose to fetch it
  26. (which could result in a digest from a different provider being selected). If
  27. the provider supports fetching the digest then it may use the B<props> argument
  28. for the properties to be used during the fetch. Finally, the passed parameters
  29. I<params>, if not NULL, are set on the context before returning.
  30. The I<pkey> algorithm is used to fetch a B<EVP_SIGNATURE> method implicitly, to
  31. be used for the actual signing. See L<provider(7)/Implicit fetch> for
  32. more information about implicit fetches.
  33. The OpenSSL default and legacy providers support fetching digests and can fetch
  34. those digests from any available provider. The OpenSSL FIPS provider also
  35. supports fetching digests but will only fetch digests that are themselves
  36. implemented inside the FIPS provider.
  37. B<ctx> must be created with EVP_MD_CTX_new() before calling this function. If
  38. B<pctx> is not NULL, the EVP_PKEY_CTX of the verification operation will be
  39. written to B<*pctx>: this can be used to set alternative verification options.
  40. Note that any existing value in B<*pctx> is overwritten. The EVP_PKEY_CTX value
  41. returned must not be freed directly by the application if B<ctx> is not assigned
  42. an EVP_PKEY_CTX value before being passed to EVP_DigestVerifyInit_ex()
  43. (which means the EVP_PKEY_CTX is created inside
  44. EVP_DigestVerifyInit_ex() and it will be freed automatically when the
  45. EVP_MD_CTX is freed). If the EVP_PKEY_CTX to be used is created by
  46. EVP_DigestVerifyInit_ex then it will use the B<OSSL_LIB_CTX> specified
  47. in I<libctx> and the property query string specified in I<props>.
  48. No B<EVP_PKEY_CTX> will be created by EVP_DigestVerifyInit_ex() if the
  49. passed B<ctx> has already been assigned one via L<EVP_MD_CTX_set_pkey_ctx(3)>.
  50. See also L<SM2(7)>.
  51. Not all digests can be used for all key types. The following combinations apply.
  52. =over 4
  53. =item DSA
  54. Supports SHA1, SHA224, SHA256, SHA384 and SHA512
  55. =item ECDSA
  56. Supports SHA1, SHA224, SHA256, SHA384, SHA512 and SM3
  57. =item RSA with no padding
  58. Supports no digests (the digest B<type> must be NULL)
  59. =item RSA with X931 padding
  60. Supports SHA1, SHA256, SHA384 and SHA512
  61. =item All other RSA padding types
  62. Support SHA1, SHA224, SHA256, SHA384, SHA512, MD5, MD5_SHA1, MD2, MD4, MDC2,
  63. SHA3-224, SHA3-256, SHA3-384, SHA3-512
  64. =item Ed25519 and Ed448
  65. Support no digests (the digest B<type> must be NULL)
  66. =item HMAC
  67. Supports any digest
  68. =item CMAC, Poly1305 and Siphash
  69. Will ignore any digest provided.
  70. =back
  71. If RSA-PSS is used and restrictions apply then the digest must match.
  72. EVP_DigestVerifyInit() works in the same way as
  73. EVP_DigestVerifyInit_ex() except that the B<mdname> parameter will be
  74. inferred from the supplied digest B<type>, and B<props> will be NULL. Where
  75. supplied the ENGINE B<e> will be used for the signature verification and digest
  76. algorithm implementations. B<e> may be NULL.
  77. EVP_DigestVerifyUpdate() hashes B<cnt> bytes of data at B<d> into the
  78. verification context B<ctx>. This function can be called several times on the
  79. same B<ctx> to include additional data.
  80. EVP_DigestVerifyFinal() verifies the data in B<ctx> against the signature in
  81. B<sig> of length B<siglen>.
  82. EVP_DigestVerify() verifies B<tbslen> bytes at B<tbs> against the signature
  83. in B<sig> of length B<siglen>.
  84. =head1 RETURN VALUES
  85. EVP_DigestVerifyInit() and EVP_DigestVerifyUpdate() return 1 for success and 0
  86. for failure.
  87. EVP_DigestVerifyFinal() and EVP_DigestVerify() return 1 for success; any other
  88. value indicates failure. A return value of zero indicates that the signature
  89. did not verify successfully (that is, B<tbs> did not match the original data or
  90. the signature had an invalid form), while other values indicate a more serious
  91. error (and sometimes also indicate an invalid signature form).
  92. The error codes can be obtained from L<ERR_get_error(3)>.
  93. =head1 NOTES
  94. The B<EVP> interface to digital signatures should almost always be used in
  95. preference to the low-level interfaces. This is because the code then becomes
  96. transparent to the algorithm used and much more flexible.
  97. EVP_DigestVerify() is a one shot operation which verifies a single block of
  98. data in one function. For algorithms that support streaming it is equivalent
  99. to calling EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal(). For
  100. algorithms which do not support streaming (e.g. PureEdDSA) it is the only way
  101. to verify data.
  102. In previous versions of OpenSSL there was a link between message digest types
  103. and public key algorithms. This meant that "clone" digests such as EVP_dss1()
  104. needed to be used to sign using SHA1 and DSA. This is no longer necessary and
  105. the use of clone digest is now discouraged.
  106. For some key types and parameters the random number generator must be seeded.
  107. If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
  108. external circumstances (see L<RAND(7)>), the operation will fail.
  109. The call to EVP_DigestVerifyFinal() internally finalizes a copy of the digest
  110. context. This means that EVP_VerifyUpdate() and EVP_VerifyFinal() can
  111. be called later to digest and verify additional data. Applications may disable
  112. this behavior by setting the EVP_MD_CTX_FLAG_FINALISE context flag via
  113. L<EVP_MD_CTX_set_flags(3)>.
  114. Note that not all providers support continuation, in case the selected
  115. provider does not allow to duplicate contexts EVP_DigestVerifyFinal() will
  116. finalize the digest context and attempting to process additional data via
  117. EVP_DigestVerifyUpdate() will result in an error.
  118. EVP_DigestVerifyInit() and EVP_DigestVerifyInit_ex() functions can be called
  119. multiple times on a context and the parameters set by previous calls should be
  120. preserved if the I<pkey> parameter is NULL. The call then just resets the state
  121. of the I<ctx>.
  122. EVP_DigestVerify() can only be called once, and cannot be used again without
  123. reinitialising the B<EVP_MD_CTX> by calling EVP_DigestVerifyInit_ex().
  124. Ignoring failure returns of EVP_DigestVerifyInit() and EVP_DigestVerifyInit_ex()
  125. functions can lead to subsequent undefined behavior when calling
  126. EVP_DigestVerifyUpdate(), EVP_DigestVerifyFinal(), or EVP_DigestVerify().
  127. =head1 SEE ALSO
  128. L<EVP_DigestSignInit(3)>,
  129. L<EVP_DigestInit(3)>,
  130. L<evp(7)>, L<HMAC(3)>, L<MD2(3)>,
  131. L<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>,
  132. L<SHA1(3)>, L<openssl-dgst(1)>,
  133. L<RAND(7)>
  134. =head1 HISTORY
  135. EVP_DigestVerifyInit(), EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal()
  136. were added in OpenSSL 1.0.0.
  137. EVP_DigestVerifyInit_ex() was added in OpenSSL 3.0.
  138. EVP_DigestVerifyUpdate() was converted from a macro to a function in OpenSSL
  139. 3.0.
  140. =head1 COPYRIGHT
  141. Copyright 2006-2023 The OpenSSL Project Authors. All Rights Reserved.
  142. Licensed under the Apache License 2.0 (the "License"). You may not use
  143. this file except in compliance with the License. You can obtain a copy
  144. in the file LICENSE in the source distribution or at
  145. L<https://www.openssl.org/source/license.html>.
  146. =cut