| 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_DECRYPT 3SSL" |
| 58 |
.TH EVP_PKEY_DECRYPT 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_decrypt_init, EVP_PKEY_decrypt_init_ex, |
| 65 |
EVP_PKEY_decrypt \- decrypt using a public key algorithm |
| 66 |
.SH SYNOPSIS |
| 67 |
.IX Header "SYNOPSIS" |
| 68 |
.Vb 1 |
| 69 |
\& #include <openssl/evp.h> |
| 70 |
\& |
| 71 |
\& int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx); |
| 72 |
\& int EVP_PKEY_decrypt_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]); |
| 73 |
\& int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, |
| 74 |
\& unsigned char *out, size_t *outlen, |
| 75 |
\& const unsigned char *in, size_t inlen); |
| 76 |
.Ve |
| 77 |
.SH DESCRIPTION |
| 78 |
.IX Header "DESCRIPTION" |
| 79 |
The \fBEVP_PKEY_decrypt_init()\fR function initializes a public key algorithm |
| 80 |
context using key \fIpkey\fR for a decryption operation. |
| 81 |
.PP |
| 82 |
The \fBEVP_PKEY_decrypt_init_ex()\fR function initializes a public key algorithm |
| 83 |
context using key \fIpkey\fR for a decryption operation and sets the |
| 84 |
algorithm specific \fIparams\fR. |
| 85 |
.PP |
| 86 |
The \fBEVP_PKEY_decrypt()\fR function performs a public key decryption operation |
| 87 |
using \fIctx\fR. The data to be decrypted is specified using the \fIin\fR and |
| 88 |
\&\fIinlen\fR parameters. If \fIout\fR is NULL then the minimum required size of |
| 89 |
the output buffer is written to the \fI*outlen\fR parameter. |
| 90 |
.PP |
| 91 |
If \fIout\fR is not NULL then before the call the \fI*outlen\fR parameter must |
| 92 |
contain the length of the \fIout\fR buffer. If the call is successful the |
| 93 |
decrypted data is written to \fIout\fR and the amount of the decrypted data |
| 94 |
written to \fI*outlen\fR, otherwise an error is returned. |
| 95 |
.SH NOTES |
| 96 |
.IX Header "NOTES" |
| 97 |
After the call to \fBEVP_PKEY_decrypt_init()\fR algorithm specific control |
| 98 |
operations can be performed to set any appropriate parameters for the |
| 99 |
operation. These operations can be included in the \fBEVP_PKEY_decrypt_init_ex()\fR |
| 100 |
call. |
| 101 |
.PP |
| 102 |
The function \fBEVP_PKEY_decrypt()\fR can be called more than once on the same |
| 103 |
context if several operations are performed using the same parameters. |
| 104 |
.SH "RETURN VALUES" |
| 105 |
.IX Header "RETURN VALUES" |
| 106 |
\&\fBEVP_PKEY_decrypt_init()\fR, \fBEVP_PKEY_decrypt_init_ex()\fR and \fBEVP_PKEY_decrypt()\fR |
| 107 |
return 1 for success and 0 or a negative value for failure. In particular a |
| 108 |
return value of \-2 indicates the operation is not supported by the public key |
| 109 |
algorithm. |
| 110 |
.SH WARNINGS |
| 111 |
.IX Header "WARNINGS" |
| 112 |
In OpenSSL versions before 3.2.0, when used in PKCS#1 v1.5 padding, |
| 113 |
both the return value from the \fBEVP_PKEY_decrypt()\fR and the \fBoutlen\fR provided |
| 114 |
information useful in mounting a Bleichenbacher attack against the |
| 115 |
used private key. They had to be processed in a side-channel free way. |
| 116 |
.PP |
| 117 |
Since version 3.2.0, the \fBEVP_PKEY_decrypt()\fR method when used with PKCS#1 |
| 118 |
v1.5 padding as implemented in the \fBdefault\fR provider implements |
| 119 |
the implicit rejection mechanism (see |
| 120 |
\&\fBOSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION\fR in \fBprovider\-asym_cipher\fR\|(7)). |
| 121 |
That means it doesn't return an error when it detects an error in padding, |
| 122 |
instead it returns a pseudo-randomly generated message, removing the need |
| 123 |
of side-channel secure code from applications using OpenSSL. |
| 124 |
If OpenSSL is configured to use a provider that doesn't implement implicit |
| 125 |
rejection, the code still needs to handle the returned values |
| 126 |
using side-channel free code. |
| 127 |
Side-channel free handling of the error stack can be performed using |
| 128 |
either a pair of unconditional \fBERR_set_mark\fR\|(3) and \fBERR_pop_to_mark\fR\|(3) |
| 129 |
calls or by using the \fBERR_clear_error\fR\|(3) call. |
| 130 |
.SH EXAMPLES |
| 131 |
.IX Header "EXAMPLES" |
| 132 |
Decrypt data using OAEP (for RSA keys): |
| 133 |
.PP |
| 134 |
.Vb 2 |
| 135 |
\& #include <openssl/evp.h> |
| 136 |
\& #include <openssl/rsa.h> |
| 137 |
\& |
| 138 |
\& EVP_PKEY_CTX *ctx; |
| 139 |
\& ENGINE *eng; |
| 140 |
\& unsigned char *out, *in; |
| 141 |
\& size_t outlen, inlen; |
| 142 |
\& EVP_PKEY *key; |
| 143 |
\& |
| 144 |
\& /* |
| 145 |
\& * NB: assumes key, eng, in, inlen are already set up |
| 146 |
\& * and that key is an RSA private key |
| 147 |
\& */ |
| 148 |
\& ctx = EVP_PKEY_CTX_new(key, eng); |
| 149 |
\& if (!ctx) |
| 150 |
\& /* Error occurred */ |
| 151 |
\& if (EVP_PKEY_decrypt_init(ctx) <= 0) |
| 152 |
\& /* Error */ |
| 153 |
\& if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING) <= 0) |
| 154 |
\& /* Error */ |
| 155 |
\& |
| 156 |
\& /* Determine buffer length */ |
| 157 |
\& if (EVP_PKEY_decrypt(ctx, NULL, &outlen, in, inlen) <= 0) |
| 158 |
\& /* Error */ |
| 159 |
\& |
| 160 |
\& out = OPENSSL_malloc(outlen); |
| 161 |
\& |
| 162 |
\& if (!out) |
| 163 |
\& /* malloc failure */ |
| 164 |
\& |
| 165 |
\& if (EVP_PKEY_decrypt(ctx, out, &outlen, in, inlen) <= 0) |
| 166 |
\& /* Error */ |
| 167 |
\& |
| 168 |
\& /* Decrypted data is outlen bytes written to buffer out */ |
| 169 |
.Ve |
| 170 |
.SH "SEE ALSO" |
| 171 |
.IX Header "SEE ALSO" |
| 172 |
\&\fBEVP_PKEY_CTX_new\fR\|(3), |
| 173 |
\&\fBEVP_PKEY_encrypt\fR\|(3), |
| 174 |
\&\fBEVP_PKEY_sign\fR\|(3), |
| 175 |
\&\fBEVP_PKEY_verify\fR\|(3), |
| 176 |
\&\fBEVP_PKEY_verify_recover\fR\|(3), |
| 177 |
\&\fBEVP_PKEY_derive\fR\|(3) |
| 178 |
.SH HISTORY |
| 179 |
.IX Header "HISTORY" |
| 180 |
These functions were added in OpenSSL 1.0.0. |
| 181 |
.SH COPYRIGHT |
| 182 |
.IX Header "COPYRIGHT" |
| 183 |
Copyright 2006\-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>. |