| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 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 3SSL" |
| 58 |
.TH EVP_PKEY_DECAPSULATE 3SSL 2026-04-07 3.6.2 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 (which must both non-NULL). |
| 93 |
.PP |
| 94 |
The \fIwrapped\fR parameter is an output argument, to which the decapsulated |
| 95 |
shared secret is written. |
| 96 |
The shared secret may not match the peer's value even when decapsulation |
| 97 |
returns success. |
| 98 |
Instead, the shared secret must be used to derive a key that is used to |
| 99 |
authenticate data subsequently received from the peer. |
| 100 |
If \fIunwrapped\fR is NULL then the size of the output shared secret buffer is |
| 101 |
written to \fI*unwrappedlen\fR and no decapsulation is performed, this makes it |
| 102 |
possible to determine the required buffer size at run time. Otherwise, the |
| 103 |
decapsulated secret data is written to \fIunwrapped\fR and the length of shared |
| 104 |
secret is written to \fI*unwrappedlen\fR. |
| 105 |
.PP |
| 106 |
Note that the value pointed to by \fIunwrappedlen\fR (which must NOT be \fBNULL\fR) |
| 107 |
must be initialised to the length of \fIunwrapped\fR, so that the call can |
| 108 |
validate it is of sufficient size to hold the result of the operation. |
| 109 |
.PP |
| 110 |
Absent detailed prior knowledge of the internals of the specific KEM |
| 111 |
algorithm, callers SHOULD NOT assume that the returned shared secret |
| 112 |
is necessarily of the maximum possible length. |
| 113 |
The length returned via \fI*unwrappedlen\fR SHOULD be used to determine the actual |
| 114 |
length of the output. |
| 115 |
.SH NOTES |
| 116 |
.IX Header "NOTES" |
| 117 |
After the call to \fBEVP_PKEY_decapsulate_init()\fR algorithm-specific parameters |
| 118 |
for the operation may be set or modified using \fBEVP_PKEY_CTX_set_params\fR\|(3). |
| 119 |
.SH "RETURN VALUES" |
| 120 |
.IX Header "RETURN VALUES" |
| 121 |
\&\fBEVP_PKEY_decapsulate_init()\fR, \fBEVP_PKEY_auth_decapsulate_init()\fR and |
| 122 |
\&\fBEVP_PKEY_decapsulate()\fR return 1 for success and 0 or a negative value for |
| 123 |
failure. In particular a return value of \-2 indicates the operation is not |
| 124 |
supported by the private key algorithm. |
| 125 |
.SH EXAMPLES |
| 126 |
.IX Header "EXAMPLES" |
| 127 |
Decapsulate data using RSA: |
| 128 |
.PP |
| 129 |
.Vb 1 |
| 130 |
\& #include <openssl/evp.h> |
| 131 |
\& |
| 132 |
\& /* |
| 133 |
\& * NB: assumes rsa_priv_key is an RSA private key, |
| 134 |
\& * and that in, inlen are already set up to contain encapsulated data. |
| 135 |
\& */ |
| 136 |
\& |
| 137 |
\& EVP_PKEY_CTX *ctx = NULL; |
| 138 |
\& size_t secretlen = 0; |
| 139 |
\& unsigned char *secret = NULL;; |
| 140 |
\& |
| 141 |
\& ctx = EVP_PKEY_CTX_new_from_pkey(libctx, rsa_priv_key, NULL); |
| 142 |
\& if (ctx == NULL) |
| 143 |
\& /* Error */ |
| 144 |
\& if (EVP_PKEY_decapsulate_init(ctx, NULL) <= 0) |
| 145 |
\& /* Error */ |
| 146 |
\& |
| 147 |
\& /* Set the mode \- only \*(AqRSASVE\*(Aq is currently supported */ |
| 148 |
\& if (EVP_PKEY_CTX_set_kem_op(ctx, "RSASVE") <= 0) |
| 149 |
\& /* Error */ |
| 150 |
\& |
| 151 |
\& /* Determine buffer length */ |
| 152 |
\& if (EVP_PKEY_decapsulate(ctx, NULL, &secretlen, in, inlen) <= 0) |
| 153 |
\& /* Error */ |
| 154 |
\& |
| 155 |
\& secret = OPENSSL_malloc(secretlen); |
| 156 |
\& if (secret == NULL) |
| 157 |
\& /* malloc failure */ |
| 158 |
\& |
| 159 |
\& /* Decapsulated secret data is secretlen bytes long */ |
| 160 |
\& if (EVP_PKEY_decapsulate(ctx, secret, &secretlen, in, inlen) <= 0) |
| 161 |
\& /* Error */ |
| 162 |
.Ve |
| 163 |
.SH "SEE ALSO" |
| 164 |
.IX Header "SEE ALSO" |
| 165 |
\&\fBEVP_PKEY_CTX_new_from_pkey\fR\|(3), |
| 166 |
\&\fBEVP_PKEY_encapsulate\fR\|(3), |
| 167 |
\&\fBEVP_KEM\-RSA\fR\|(7), |
| 168 |
\&\fBEVP_KEM\-X25519\fR\|(7), |
| 169 |
\&\fBEVP_KEM\-EC\fR\|(7), |
| 170 |
\&\fBEVP_KEM\-ML\-KEM\-512\fR\|(7), |
| 171 |
\&\fBEVP_KEM\-ML\-KEM\-768\fR\|(7), |
| 172 |
\&\fBEVP_KEM\-ML\-KEM\-1024\fR\|(7) |
| 173 |
.SH HISTORY |
| 174 |
.IX Header "HISTORY" |
| 175 |
The functions \fBEVP_PKEY_decapsulate_init()\fR and \fBEVP_PKEY_decapsulate()\fR were added |
| 176 |
in OpenSSL 3.0. |
| 177 |
.PP |
| 178 |
The function \fBEVP_PKEY_auth_decapsulate_init()\fR was added in OpenSSL 3.2. |
| 179 |
.PP |
| 180 |
Support for \fBML-KEM\fR was added in OpenSSL 3.5. |
| 181 |
.SH COPYRIGHT |
| 182 |
.IX Header "COPYRIGHT" |
| 183 |
Copyright 2020\-2025 The OpenSSL Project Authors. All Rights Reserved. |
| 184 |
.PP |
| 185 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 186 |
this file except in compliance with the License. You can obtain a copy |
| 187 |
in the file LICENSE in the source distribution or at |
| 188 |
<https://www.openssl.org/source/license.html>. |