EVP_PKEY_decapsulate.3ossl 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "EVP_PKEY_DECAPSULATE 3ossl"
  58. .TH EVP_PKEY_DECAPSULATE 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. EVP_PKEY_decapsulate_init, EVP_PKEY_auth_decapsulate_init, EVP_PKEY_decapsulate
  65. \&\- Key decapsulation using a KEM algorithm with a private key
  66. .SH SYNOPSIS
  67. .IX Header "SYNOPSIS"
  68. .Vb 1
  69. \& #include <openssl/evp.h>
  70. \&
  71. \& int EVP_PKEY_decapsulate_init(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
  72. \& int EVP_PKEY_auth_decapsulate_init(EVP_PKEY_CTX *ctx, EVP_PKEY *authpub,
  73. \& const OSSL_PARAM params[]);
  74. \& int EVP_PKEY_decapsulate(EVP_PKEY_CTX *ctx,
  75. \& unsigned char *unwrapped, size_t *unwrappedlen,
  76. \& const unsigned char *wrapped, size_t wrappedlen);
  77. .Ve
  78. .SH DESCRIPTION
  79. .IX Header "DESCRIPTION"
  80. The \fBEVP_PKEY_decapsulate_init()\fR function initializes a private key algorithm
  81. context \fIctx\fR for a decapsulation operation and then sets the \fIparams\fR
  82. on the context in the same way as calling \fBEVP_PKEY_CTX_set_params\fR\|(3).
  83. Note that \fIctx\fR usually is produced using \fBEVP_PKEY_CTX_new_from_pkey\fR\|(3),
  84. specifying the private key to use.
  85. .PP
  86. The \fBEVP_PKEY_auth_decapsulate_init()\fR function is similar to
  87. \&\fBEVP_PKEY_decapsulate_init()\fR but also passes an \fIauthpub\fR authentication public
  88. key that is used during decapsulation.
  89. .PP
  90. The \fBEVP_PKEY_decapsulate()\fR function performs a private key decapsulation
  91. operation using \fIctx\fR. The data to be decapsulated is specified using the
  92. \&\fIwrapped\fR and \fIwrappedlen\fR parameters.
  93. If \fIunwrapped\fR is NULL then the size of the output secret buffer
  94. is written to \fI*unwrappedlen\fR. If \fIunwrapped\fR is not NULL and the
  95. call is successful then the decapsulated secret data is written to \fIunwrapped\fR
  96. and the amount of data written to \fI*unwrappedlen\fR. Note that, if \fIunwrappedlen\fR
  97. is not NULL in this call, the value it points to must be initialised to the length of
  98. \&\fIunwrapped\fR, so that the call can validate it is of sufficient size to hold the
  99. result of the operation.
  100. .SH NOTES
  101. .IX Header "NOTES"
  102. After the call to \fBEVP_PKEY_decapsulate_init()\fR algorithm-specific parameters
  103. for the operation may be set or modified using \fBEVP_PKEY_CTX_set_params\fR\|(3).
  104. .SH "RETURN VALUES"
  105. .IX Header "RETURN VALUES"
  106. \&\fBEVP_PKEY_decapsulate_init()\fR, \fBEVP_PKEY_auth_decapsulate_init()\fR and
  107. \&\fBEVP_PKEY_decapsulate()\fR return 1 for success and 0 or a negative value for
  108. failure. In particular a return value of \-2 indicates the operation is not
  109. supported by the private key algorithm.
  110. .SH EXAMPLES
  111. .IX Header "EXAMPLES"
  112. Decapsulate data using RSA:
  113. .PP
  114. .Vb 1
  115. \& #include <openssl/evp.h>
  116. \&
  117. \& /*
  118. \& * NB: assumes rsa_priv_key is an RSA private key,
  119. \& * and that in, inlen are already set up to contain encapsulated data.
  120. \& */
  121. \&
  122. \& EVP_PKEY_CTX *ctx = NULL;
  123. \& size_t secretlen = 0;
  124. \& unsigned char *secret = NULL;;
  125. \&
  126. \& ctx = EVP_PKEY_CTX_new_from_pkey(libctx, rsa_priv_key, NULL);
  127. \& if (ctx == NULL)
  128. \& /* Error */
  129. \& if (EVP_PKEY_decapsulate_init(ctx, NULL) <= 0)
  130. \& /* Error */
  131. \&
  132. \& /* Set the mode \- only \*(AqRSASVE\*(Aq is currently supported */
  133. \& if (EVP_PKEY_CTX_set_kem_op(ctx, "RSASVE") <= 0)
  134. \& /* Error */
  135. \&
  136. \& /* Determine buffer length */
  137. \& if (EVP_PKEY_decapsulate(ctx, NULL, &secretlen, in, inlen) <= 0)
  138. \& /* Error */
  139. \&
  140. \& secret = OPENSSL_malloc(secretlen);
  141. \& if (secret == NULL)
  142. \& /* malloc failure */
  143. \&
  144. \& /* Decapsulated secret data is secretlen bytes long */
  145. \& if (EVP_PKEY_decapsulate(ctx, secret, &secretlen, in, inlen) <= 0)
  146. \& /* Error */
  147. .Ve
  148. .SH "SEE ALSO"
  149. .IX Header "SEE ALSO"
  150. \&\fBEVP_PKEY_CTX_new_from_pkey\fR\|(3),
  151. \&\fBEVP_PKEY_encapsulate\fR\|(3),
  152. \&\fBEVP_KEM\-RSA\fR\|(7), \fBEVP_KEM\-X25519\fR\|(7), \fBEVP_KEM\-EC\fR\|(7)
  153. .SH HISTORY
  154. .IX Header "HISTORY"
  155. The functions \fBEVP_PKEY_decapsulate_init()\fR and \fBEVP_PKEY_decapsulate()\fR were added
  156. in OpenSSL 3.0.
  157. .PP
  158. The function \fBEVP_PKEY_auth_decapsulate_init()\fR was added in OpenSSL 3.2.
  159. .SH COPYRIGHT
  160. .IX Header "COPYRIGHT"
  161. Copyright 2020\-2024 The OpenSSL Project Authors. All Rights Reserved.
  162. .PP
  163. Licensed under the Apache License 2.0 (the "License"). You may not use
  164. this file except in compliance with the License. You can obtain a copy
  165. in the file LICENSE in the source distribution or at
  166. <https://www.openssl.org/source/license.html>.