EVP_PKEY_decapsulate.pod 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. =pod
  2. =head1 NAME
  3. EVP_PKEY_decapsulate_init, EVP_PKEY_decapsulate
  4. - Key decapsulation using a private key algorithm
  5. =head1 SYNOPSIS
  6. #include <openssl/evp.h>
  7. int EVP_PKEY_decapsulate_init(EVP_PKEY_CTX *ctx);
  8. int EVP_PKEY_decapsulate(EVP_PKEY_CTX *ctx,
  9. unsigned char *secret, size_t *secretlen,
  10. const unsigned char *wrapped, size_t wrappedlen);
  11. =head1 DESCRIPTION
  12. The EVP_PKEY_decapsulate_init() function initializes a private key algorithm
  13. context I<ctx> for a decapsulation operation.
  14. The EVP_PKEY_decapsulate() function performs a private key decapsulation
  15. operation using I<ctx>. The data to be decapsulated is specified using the
  16. I<wrapped> and I<wrappedlen> parameters.
  17. If I<secret> is I<NULL> then the maximum size of the output secret buffer
  18. is written to the I<*secretlen> parameter. If I<secret> is not B<NULL> and the
  19. call is successful then the decapsulated secret data is written to I<secret> and
  20. the amount of data written to I<secretlen>.
  21. =head1 NOTES
  22. After the call to EVP_PKEY_decapsulate_init() algorithm specific parameters
  23. for the operation may be set using L<EVP_PKEY_CTX_set_params(3)>. There are no
  24. settable parameters currently.
  25. =head1 RETURN VALUES
  26. EVP_PKEY_decapsulate_init() and EVP_PKEY_decapsulate() return 1 for
  27. success and 0 or a negative value for failure. In particular a return value of -2
  28. indicates the operation is not supported by the private key algorithm.
  29. =head1 EXAMPLES
  30. Decapsulate data using RSA:
  31. #include <openssl/evp.h>
  32. /*
  33. * NB: assumes rsa_priv_key is an RSA private key,
  34. * and that in, inlen are already set up to contain encapsulated data.
  35. */
  36. EVP_PKEY_CTX *ctx = NULL;
  37. size_t secretlen = 0;
  38. unsigned char *secret = NULL;;
  39. ctx = EVP_PKEY_CTX_new_from_pkey(libctx, rsa_priv_key, NULL);
  40. if (ctx = NULL)
  41. /* Error */
  42. if (EVP_PKEY_decapsulate_init(ctx) <= 0)
  43. /* Error */
  44. /* Set the mode - only 'RSASVE' is currently supported */
  45. if (EVP_PKEY_CTX_set_kem_op(ctx, "RSASVE") <= 0)
  46. /* Error */
  47. /* Determine buffer length */
  48. if (EVP_PKEY_decapsulate(ctx, NULL, &secretlen, in, inlen) <= 0)
  49. /* Error */
  50. secret = OPENSSL_malloc(secretlen);
  51. if (secret == NULL)
  52. /* malloc failure */
  53. /* Decapsulated secret data is secretlen bytes long */
  54. if (EVP_PKEY_decapsulaterctx, secret, &secretlen, in, inlen) <= 0)
  55. /* Error */
  56. =head1 SEE ALSO
  57. L<EVP_PKEY_CTX_new(3)>,
  58. L<EVP_PKEY_encapsulate(3)>,
  59. L<EVP_KEM-RSA(7)>,
  60. =head1 HISTORY
  61. These functions were added in OpenSSL 3.0.
  62. =head1 COPYRIGHT
  63. Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
  64. Licensed under the Apache License 2.0 (the "License"). You may not use
  65. this file except in compliance with the License. You can obtain a copy
  66. in the file LICENSE in the source distribution or at
  67. L<https://www.openssl.org/source/license.html>.
  68. =cut