2
0

EVP_PKEY_verify_recover.pod 3.7 KB

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