EVP_PKEY_decapsulate.pod 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. =pod
  2. =head1 NAME
  3. EVP_PKEY_decapsulate_init, EVP_PKEY_auth_decapsulate_init, EVP_PKEY_decapsulate
  4. - Key decapsulation using a KEM algorithm with a private key
  5. =head1 SYNOPSIS
  6. #include <openssl/evp.h>
  7. int EVP_PKEY_decapsulate_init(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
  8. int EVP_PKEY_auth_decapsulate_init(EVP_PKEY_CTX *ctx, EVP_PKEY *authpub,
  9. const OSSL_PARAM params[]);
  10. int EVP_PKEY_decapsulate(EVP_PKEY_CTX *ctx,
  11. unsigned char *unwrapped, size_t *unwrappedlen,
  12. const unsigned char *wrapped, size_t wrappedlen);
  13. =head1 DESCRIPTION
  14. The EVP_PKEY_decapsulate_init() function initializes a private key algorithm
  15. context I<ctx> for a decapsulation operation and then sets the I<params>
  16. on the context in the same way as calling L<EVP_PKEY_CTX_set_params(3)>.
  17. Note that I<ctx> usually is produced using L<EVP_PKEY_CTX_new_from_pkey(3)>,
  18. specifying the private key to use.
  19. The EVP_PKEY_auth_decapsulate_init() function is similar to
  20. EVP_PKEY_decapsulate_init() but also passes an I<authpub> authentication public
  21. key that is used during decapsulation.
  22. The EVP_PKEY_decapsulate() function performs a private key decapsulation
  23. operation using I<ctx>. The data to be decapsulated is specified using the
  24. I<wrapped> and I<wrappedlen> parameters.
  25. If I<unwrapped> is NULL then the maximum size of the output secret buffer
  26. is written to I<*unwrappedlen>. If I<unwrapped> is not NULL and the
  27. call is successful then the decapsulated secret data is written to I<unwrapped>
  28. and the amount of data written to I<*unwrappedlen>.
  29. =head1 NOTES
  30. After the call to EVP_PKEY_decapsulate_init() algorithm-specific parameters
  31. for the operation may be set or modified using L<EVP_PKEY_CTX_set_params(3)>.
  32. =head1 RETURN VALUES
  33. EVP_PKEY_decapsulate_init(), EVP_PKEY_auth_decapsulate_init() and
  34. EVP_PKEY_decapsulate() return 1 for success and 0 or a negative value for
  35. failure. In particular a return value of -2 indicates the operation is not
  36. supported by the private key algorithm.
  37. =head1 EXAMPLES
  38. Decapsulate data using RSA:
  39. #include <openssl/evp.h>
  40. /*
  41. * NB: assumes rsa_priv_key is an RSA private key,
  42. * and that in, inlen are already set up to contain encapsulated data.
  43. */
  44. EVP_PKEY_CTX *ctx = NULL;
  45. size_t secretlen = 0;
  46. unsigned char *secret = NULL;;
  47. ctx = EVP_PKEY_CTX_new_from_pkey(libctx, rsa_priv_key, NULL);
  48. if (ctx = NULL)
  49. /* Error */
  50. if (EVP_PKEY_decapsulate_init(ctx, NULL) <= 0)
  51. /* Error */
  52. /* Set the mode - only 'RSASVE' is currently supported */
  53. if (EVP_PKEY_CTX_set_kem_op(ctx, "RSASVE") <= 0)
  54. /* Error */
  55. /* Determine buffer length */
  56. if (EVP_PKEY_decapsulate(ctx, NULL, &secretlen, in, inlen) <= 0)
  57. /* Error */
  58. secret = OPENSSL_malloc(secretlen);
  59. if (secret == NULL)
  60. /* malloc failure */
  61. /* Decapsulated secret data is secretlen bytes long */
  62. if (EVP_PKEY_decapsulate(ctx, secret, &secretlen, in, inlen) <= 0)
  63. /* Error */
  64. =head1 SEE ALSO
  65. L<EVP_PKEY_CTX_new_from_pkey(3)>,
  66. L<EVP_PKEY_encapsulate(3)>,
  67. L<EVP_KEM-RSA(7)>, L<EVP_KEM-X25519(7)>, L<EVP_KEM-EC(7)>
  68. =head1 HISTORY
  69. The functions EVP_PKEY_decapsulate_init() and EVP_PKEY_decapsulate() were added
  70. in OpenSSL 3.0.
  71. The function EVP_PKEY_auth_decapsulate_init() was added in OpenSSL 3.2.
  72. =head1 COPYRIGHT
  73. Copyright 2020-2023 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