Debian Codegraph @

upstream/debian-unstable/man3/RSA_public_encrypt.3ssl

raw
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 "RSA_PUBLIC_ENCRYPT 3SSL"
58 .TH RSA_PUBLIC_ENCRYPT 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 RSA_public_encrypt, RSA_private_decrypt \- RSA public key cryptography
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 1
68 \& #include <openssl/rsa.h>
69 .Ve
70 .PP
71 The following functions have been deprecated since OpenSSL 3.0, and can be
72 hidden entirely by defining \fBOPENSSL_API_COMPAT\fR with a suitable version value,
73 see \fBopenssl_user_macros\fR\|(7):
74 .PP
75 .Vb 2
76 \& int RSA_public_encrypt(int flen, const unsigned char *from,
77 \& unsigned char *to, RSA *rsa, int padding);
78 \&
79 \& int RSA_private_decrypt(int flen, const unsigned char *from,
80 \& unsigned char *to, RSA *rsa, int padding);
81 .Ve
82 .SH DESCRIPTION
83 .IX Header "DESCRIPTION"
84 Both of the functions described on this page are deprecated.
85 Applications should instead use \fBEVP_PKEY_encrypt_init_ex\fR\|(3),
86 \&\fBEVP_PKEY_encrypt\fR\|(3), \fBEVP_PKEY_decrypt_init_ex\fR\|(3) and
87 \&\fBEVP_PKEY_decrypt\fR\|(3).
88 .PP
89 \&\fBRSA_public_encrypt()\fR encrypts the \fBflen\fR bytes at \fBfrom\fR (usually a
90 session key) using the public key \fBrsa\fR and stores the ciphertext in
91 \&\fBto\fR. \fBto\fR must point to RSA_size(\fBrsa\fR) bytes of memory.
92 .PP
93 \&\fBpadding\fR denotes one of the following modes:
94 .IP RSA_PKCS1_PADDING 4
95 .IX Item "RSA_PKCS1_PADDING"
96 PKCS #1 v1.5 padding. This currently is the most widely used mode.
97 However, it is highly recommended to use RSA_PKCS1_OAEP_PADDING in
98 new applications. SEE WARNING BELOW.
99 .IP RSA_PKCS1_OAEP_PADDING 4
100 .IX Item "RSA_PKCS1_OAEP_PADDING"
101 EME-OAEP as defined in PKCS #1 v2.0 with SHA\-1, MGF1 and an empty
102 encoding parameter. This mode is recommended for all new applications.
103 .IP RSA_NO_PADDING 4
104 .IX Item "RSA_NO_PADDING"
105 Raw RSA encryption. This mode should \fIonly\fR be used to implement
106 cryptographically sound padding modes in the application code.
107 Encrypting user data directly with RSA is insecure.
108 .PP
109 When encrypting \fBflen\fR must not be more than RSA_size(\fBrsa\fR) \- 11 for the
110 PKCS #1 v1.5 based padding modes, not more than RSA_size(\fBrsa\fR) \- 42 for
111 RSA_PKCS1_OAEP_PADDING and exactly RSA_size(\fBrsa\fR) for RSA_NO_PADDING.
112 When a padding mode other than RSA_NO_PADDING is in use, then
113 \&\fBRSA_public_encrypt()\fR will include some random bytes into the ciphertext
114 and therefore the ciphertext will be different each time, even if the
115 plaintext and the public key are exactly identical.
116 The returned ciphertext in \fBto\fR will always be zero padded to exactly
117 RSA_size(\fBrsa\fR) bytes.
118 \&\fBto\fR and \fBfrom\fR may overlap.
119 .PP
120 \&\fBRSA_private_decrypt()\fR decrypts the \fBflen\fR bytes at \fBfrom\fR using the
121 private key \fBrsa\fR and stores the plaintext in \fBto\fR. \fBflen\fR should
122 be equal to RSA_size(\fBrsa\fR) but may be smaller, when leading zero
123 bytes are in the ciphertext. Those are not important and may be removed,
124 but \fBRSA_public_encrypt()\fR does not do that. \fBto\fR must point
125 to a memory section large enough to hold the maximal possible decrypted
126 data (which is equal to RSA_size(\fBrsa\fR) for RSA_NO_PADDING,
127 RSA_size(\fBrsa\fR) \- 11 for the PKCS #1 v1.5 based padding modes and
128 RSA_size(\fBrsa\fR) \- 42 for RSA_PKCS1_OAEP_PADDING).
129 \&\fBpadding\fR is the padding mode that was used to encrypt the data.
130 \&\fBto\fR and \fBfrom\fR may overlap.
131 .SH "RETURN VALUES"
132 .IX Header "RETURN VALUES"
133 \&\fBRSA_public_encrypt()\fR returns the size of the encrypted data (i.e.,
134 RSA_size(\fBrsa\fR)). \fBRSA_private_decrypt()\fR returns the size of the
135 recovered plaintext. A return value of 0 is not an error and
136 means only that the plaintext was empty.
137 .PP
138 On error, \-1 is returned; the error codes can be
139 obtained by \fBERR_get_error\fR\|(3).
140 .SH WARNINGS
141 .IX Header "WARNINGS"
142 Decryption failures in the RSA_PKCS1_PADDING mode leak information
143 which can potentially be used to mount a Bleichenbacher padding oracle
144 attack. This is an inherent weakness in the PKCS #1 v1.5 padding
145 design. Prefer RSA_PKCS1_OAEP_PADDING.
146 .PP
147 In OpenSSL before version 3.2.0, both the return value and the length of
148 returned value could be used to mount the Bleichenbacher attack.
149 Since version 3.2.0, the default provider in OpenSSL does not return an
150 error when padding checks fail. Instead it generates a random
151 message based on used private
152 key and provided ciphertext so that application code doesn't have to implement
153 a side-channel secure error handling.
154 Applications that want to be secure against side-channel attacks with
155 providers that don't implement implicit rejection, still need to
156 handle the returned values using side-channel free code.
157 Side-channel free handling of the error stack can be performed using
158 either a pair of unconditional \fBERR_set_mark\fR\|(3) and \fBERR_pop_to_mark\fR\|(3)
159 calls or by using the \fBERR_clear_error\fR\|(3) call.
160 .SH "CONFORMING TO"
161 .IX Header "CONFORMING TO"
162 SSL, PKCS #1 v2.0
163 .SH "SEE ALSO"
164 .IX Header "SEE ALSO"
165 \&\fBERR_get_error\fR\|(3), \fBRAND_bytes\fR\|(3),
166 \&\fBRSA_size\fR\|(3), \fBEVP_PKEY_decrypt\fR\|(3), \fBEVP_PKEY_encrypt\fR\|(3)
167 .SH HISTORY
168 .IX Header "HISTORY"
169 Both of these functions were deprecated in OpenSSL 3.0.
170 .SH COPYRIGHT
171 .IX Header "COPYRIGHT"
172 Copyright 2000\-2024 The OpenSSL Project Authors. All Rights Reserved.
173 .PP
174 Licensed under the Apache License 2.0 (the "License"). You may not use
175 this file except in compliance with the License. You can obtain a copy
176 in the file LICENSE in the source distribution or at
177 <https://www.openssl.org/source/license.html>.