EVP_PKEY_verify_recover.pod 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. =pod
  2. =head1 NAME
  3. EVP_PKEY_verify_recover_init, EVP_PKEY_verify_recover - recover signature using a public key algorithm
  4. =head1 SYNOPSIS
  5. #include <openssl/evp.h>
  6. int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx);
  7. int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx,
  8. unsigned char *rout, size_t *routlen,
  9. const unsigned char *sig, size_t siglen);
  10. =head1 DESCRIPTION
  11. The EVP_PKEY_verify_recover_init() function initializes a public key algorithm
  12. context using key B<pkey> for a verify recover operation.
  13. The EVP_PKEY_verify_recover() function recovers signed data
  14. using B<ctx>. The signature is specified using the B<sig> and
  15. B<siglen> parameters. If B<rout> is B<NULL> then the maximum size of the output
  16. buffer is written to the B<routlen> parameter. If B<rout> is not B<NULL> then
  17. before the call the B<routlen> parameter should contain the length of the
  18. B<rout> buffer, if the call is successful recovered data is written to
  19. B<rout> and the amount of data written to B<routlen>.
  20. =head1 NOTES
  21. Normally an application is only interested in whether a signature verification
  22. operation is successful in those cases the EVP_verify() function should be
  23. used.
  24. Sometimes however it is useful to obtain the data originally signed using a
  25. signing operation. Only certain public key algorithms can recover a signature
  26. in this way (for example RSA in PKCS padding mode).
  27. After the call to EVP_PKEY_verify_recover_init() algorithm specific control
  28. operations can be performed to set any appropriate parameters for the
  29. operation.
  30. The function EVP_PKEY_verify_recover() can be called more than once on the same
  31. context if several operations are performed using the same parameters.
  32. =head1 RETURN VALUES
  33. EVP_PKEY_verify_recover_init() and EVP_PKEY_verify_recover() return 1 for success
  34. and 0 or a negative value for failure. In particular a return value of -2
  35. indicates the operation is not supported by the public key algorithm.
  36. =head1 EXAMPLE
  37. Recover digest originally signed using PKCS#1 and SHA256 digest:
  38. #include <openssl/evp.h>
  39. #include <openssl/rsa.h>
  40. EVP_PKEY_CTX *ctx;
  41. unsigned char *rout, *sig;
  42. size_t routlen, siglen;
  43. EVP_PKEY *verify_key;
  44. /*
  45. * NB: assumes verify_key, sig and siglen 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_recover_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. /* Determine buffer length */
  58. if (EVP_PKEY_verify_recover(ctx, NULL, &routlen, sig, siglen) <= 0)
  59. /* Error */
  60. rout = OPENSSL_malloc(routlen);
  61. if (!rout)
  62. /* malloc failure */
  63. if (EVP_PKEY_verify_recover(ctx, rout, &routlen, sig, siglen) <= 0)
  64. /* Error */
  65. /* Recovered data is routlen bytes written to buffer rout */
  66. =head1 SEE ALSO
  67. L<EVP_PKEY_CTX_new(3)>,
  68. L<EVP_PKEY_encrypt(3)>,
  69. L<EVP_PKEY_decrypt(3)>,
  70. L<EVP_PKEY_sign(3)>,
  71. L<EVP_PKEY_verify(3)>,
  72. L<EVP_PKEY_derive(3)>
  73. =head1 HISTORY
  74. These functions were first added to OpenSSL 1.0.0.
  75. =head1 COPYRIGHT
  76. Copyright 2013-2018 The OpenSSL Project Authors. All Rights Reserved.
  77. Licensed under the OpenSSL license (the "License"). You may not use
  78. this file except in compliance with the License. You can obtain a copy
  79. in the file LICENSE in the source distribution or at
  80. L<https://www.openssl.org/source/license.html>.
  81. =cut