EVP_DigestVerifyInit.pod 7.1 KB

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