EVP_DigestVerifyInit.pod 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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, const char *props,
  9. EVP_PKEY *pkey, EVP_SIGNATURE *signature);
  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 digest
  21. with the name B<mdname> and public key B<pkey>. The signature algorithm
  22. B<signature> will be used for the actual signature verification which must be
  23. compatible with the public key. The name of the digest to be used is passed to
  24. the provider of the signature algorithm in use. How that provider interprets the
  25. digest name is provider specific. The provider may implement that digest
  26. directly itself or it may (optionally) choose to fetch it (which could result in
  27. a digest from a different provider being selected). If the provider supports
  28. fetching the digest then it may use the B<props> argument for the properties to
  29. be used during the fetch.
  30. The B<signature> parameter may be NULL in which case a suitable signature
  31. algorithm implementation will be implicitly fetched based on the type of key in
  32. use. See L<provider(7)> for further information about providers and fetching
  33. algorithms.
  34. The OpenSSL default and legacy providers support fetching digests and can fetch
  35. those digests from any available provider. The OpenSSL fips provider also
  36. supports fetching digests but will only fetch digests that are themselves
  37. implemented inside the fips provider.
  38. B<ctx> must be created with EVP_MD_CTX_new() before calling this function. If
  39. B<pctx> is not NULL, the EVP_PKEY_CTX of the verification operation will be
  40. written to B<*pctx>: this can be used to set alternative verification options.
  41. Note that any existing value in B<*pctx> is overwritten. The EVP_PKEY_CTX value
  42. returned must not be freed directly by the application if B<ctx> is not assigned
  43. an EVP_PKEY_CTX value before being passed to EVP_DigestVerifyInit_ex() (which
  44. means the EVP_PKEY_CTX is created inside EVP_DigestVerifyInit_ex() and it will
  45. be freed automatically when the EVP_MD_CTX is freed).
  46. No B<EVP_PKEY_CTX> will be created by EVP_DigestSignInit_ex() if the passed
  47. B<ctx> has already been assigned one via L<EVP_MD_CTX_set_pkey_ctx(3)>. See also
  48. 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 EVP_DigestVerifyInit_ex() except
  71. that the B<mdname> parameter will be inferred from the supplied digest B<type>,
  72. and B<props> will be NULL. Where supplied the ENGINE B<e> will be used for the
  73. signature verification and digest algorithm implementations. B<e> may be NULL.
  74. EVP_DigestVerifyUpdate() hashes B<cnt> bytes of data at B<d> into the
  75. verification context B<ctx>. This function can be called several times on the
  76. same B<ctx> to include additional data.
  77. EVP_DigestVerifyFinal() verifies the data in B<ctx> against the signature in
  78. B<sig> of length B<siglen>.
  79. EVP_DigestVerify() verifies B<tbslen> bytes at B<tbs> against the signature
  80. in B<sig> of length B<siglen>.
  81. =head1 RETURN VALUES
  82. EVP_DigestVerifyInit() and EVP_DigestVerifyUpdate() return 1 for success and 0
  83. for failure.
  84. EVP_DigestVerifyFinal() and EVP_DigestVerify() return 1 for success; any other
  85. value indicates failure. A return value of zero indicates that the signature
  86. did not verify successfully (that is, B<tbs> did not match the original data or
  87. the signature had an invalid form), while other values indicate a more serious
  88. error (and sometimes also indicate an invalid signature form).
  89. The error codes can be obtained from L<ERR_get_error(3)>.
  90. =head1 NOTES
  91. The B<EVP> interface to digital signatures should almost always be used in
  92. preference to the low level interfaces. This is because the code then becomes
  93. transparent to the algorithm used and much more flexible.
  94. EVP_DigestVerify() is a one shot operation which verifies a single block of
  95. data in one function. For algorithms that support streaming it is equivalent
  96. to calling EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal(). For
  97. algorithms which do not support streaming (e.g. PureEdDSA) it is the only way
  98. to verify data.
  99. In previous versions of OpenSSL there was a link between message digest types
  100. and public key algorithms. This meant that "clone" digests such as EVP_dss1()
  101. needed to be used to sign using SHA1 and DSA. This is no longer necessary and
  102. the use of clone digest is now discouraged.
  103. For some key types and parameters the random number generator must be seeded.
  104. If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
  105. external circumstances (see L<RAND(7)>), the operation will fail.
  106. The call to EVP_DigestVerifyFinal() internally finalizes a copy of the digest
  107. context. This means that EVP_VerifyUpdate() and EVP_VerifyFinal() can
  108. be called later to digest and verify additional data.
  109. Since only a copy of the digest context is ever finalized, the context must
  110. be cleaned up after use by calling EVP_MD_CTX_free() or a memory leak
  111. will occur.
  112. =head1 SEE ALSO
  113. L<EVP_DigestSignInit(3)>,
  114. L<EVP_DigestInit(3)>,
  115. L<evp(7)>, L<HMAC(3)>, L<MD2(3)>,
  116. L<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>,
  117. L<SHA1(3)>, L<openssl-dgst(1)>,
  118. L<RAND(7)>
  119. =head1 HISTORY
  120. EVP_DigestVerifyInit(), EVP_DigestVerifyUpdate() and EVP_DigestVerifyFinal()
  121. were added in OpenSSL 1.0.0.
  122. EVP_DigestVerifyInit_ex() was added in OpenSSL 3.0.
  123. EVP_DigestVerifyUpdate() was converted from a macro to a function in OpenSSL
  124. 3.0.
  125. =head1 COPYRIGHT
  126. Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
  127. Licensed under the Apache License 2.0 (the "License"). You may not use
  128. this file except in compliance with the License. You can obtain a copy
  129. in the file LICENSE in the source distribution or at
  130. L<https://www.openssl.org/source/license.html>.
  131. =cut