EVP_PKEY_verify.pod 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. =pod
  2. =head1 NAME
  3. EVP_PKEY_verify_init, EVP_PKEY_verify
  4. - signature verification using a public key algorithm
  5. =head1 SYNOPSIS
  6. #include <openssl/evp.h>
  7. int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx);
  8. int EVP_PKEY_verify(EVP_PKEY_CTX *ctx,
  9. const unsigned char *sig, size_t siglen,
  10. const unsigned char *tbs, size_t tbslen);
  11. =head1 DESCRIPTION
  12. EVP_PKEY_verify_init() initializes a public key algorithm context I<ctx> for
  13. signing using the algorithm given when the context was created
  14. using L<EVP_PKEY_CTX_new(3)> or variants thereof. The algorithm is used to
  15. fetch a B<EVP_SIGNATURE> method implicitly, see L<provider(7)/Implicit fetch>
  16. for more information about implict fetches.
  17. The EVP_PKEY_verify() function performs a public key verification operation
  18. using I<ctx>. The signature is specified using the I<sig> and
  19. I<siglen> parameters. The verified data (i.e. the data believed originally
  20. signed) is specified using the I<tbs> and I<tbslen> parameters.
  21. =head1 NOTES
  22. After the call to EVP_PKEY_verify_init() algorithm specific control
  23. operations can be performed to set any appropriate parameters for the
  24. operation.
  25. The function EVP_PKEY_verify() can be called more than once on the same
  26. context if several operations are performed using the same parameters.
  27. =head1 RETURN VALUES
  28. EVP_PKEY_verify_init() and EVP_PKEY_verify() return 1 if the verification was
  29. successful and 0 if it failed. Unlike other functions the return value 0 from
  30. EVP_PKEY_verify() only indicates that the signature did not verify
  31. successfully (that is tbs did not match the original data or the signature was
  32. of invalid form) it is not an indication of a more serious error.
  33. A negative value indicates an error other that signature verification failure.
  34. In particular a return value of -2 indicates the operation is not supported by
  35. the public key algorithm.
  36. =head1 EXAMPLES
  37. Verify signature using PKCS#1 and SHA256 digest:
  38. #include <openssl/evp.h>
  39. #include <openssl/rsa.h>
  40. EVP_PKEY_CTX *ctx;
  41. unsigned char *md, *sig;
  42. size_t mdlen, siglen;
  43. EVP_PKEY *verify_key;
  44. /*
  45. * NB: assumes verify_key, sig, siglen md and mdlen are already set up
  46. * and that verify_key is an RSA public key
  47. */
  48. ctx = EVP_PKEY_CTX_new(verify_key, NULL /* no engine */);
  49. if (!ctx)
  50. /* Error occurred */
  51. if (EVP_PKEY_verify_init(ctx) <= 0)
  52. /* Error */
  53. if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
  54. /* Error */
  55. if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
  56. /* Error */
  57. /* Perform operation */
  58. ret = EVP_PKEY_verify(ctx, sig, siglen, md, mdlen);
  59. /*
  60. * ret == 1 indicates success, 0 verify failure and < 0 for some
  61. * other error.
  62. */
  63. =head1 SEE ALSO
  64. L<EVP_PKEY_CTX_new(3)>,
  65. L<EVP_PKEY_encrypt(3)>,
  66. L<EVP_PKEY_decrypt(3)>,
  67. L<EVP_PKEY_sign(3)>,
  68. L<EVP_PKEY_verify_recover(3)>,
  69. L<EVP_PKEY_derive(3)>
  70. =head1 HISTORY
  71. These functions were added in OpenSSL 1.0.0.
  72. =head1 COPYRIGHT
  73. Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
  74. Licensed under the Apache License 2.0 (the "License"). You may not use
  75. this file except in compliance with the License. You can obtain a copy
  76. in the file LICENSE in the source distribution or at
  77. L<https://www.openssl.org/source/license.html>.
  78. =cut