1 .\" $OpenBSD: RSA_public_encrypt.3,v 1.8 2017/08/28 17:41:59 jsing Exp $
2 .\" OpenSSL RSA_public_encrypt.pod 1e3f62a3 Jul 17 16:47:13 2017 +0200
4 .\" This file was written by Ulf Moeller <ulf@openssl.org>.
5 .\" Copyright (c) 2000, 2004 The OpenSSL Project. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in
16 .\" the documentation and/or other materials provided with the
19 .\" 3. All advertising materials mentioning features or use of this
20 .\" software must display the following acknowledgment:
21 .\" "This product includes software developed by the OpenSSL Project
22 .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 .\" endorse or promote products derived from this software without
26 .\" prior written permission. For written permission, please contact
27 .\" openssl-core@openssl.org.
29 .\" 5. Products derived from this software may not be called "OpenSSL"
30 .\" nor may "OpenSSL" appear in their names without prior written
31 .\" permission of the OpenSSL Project.
33 .\" 6. Redistributions of any form whatsoever must retain the following
35 .\" "This product includes software developed by the OpenSSL Project
36 .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
51 .Dd $Mdocdate: August 28 2017 $
52 .Dt RSA_PUBLIC_ENCRYPT 3
55 .Nm RSA_public_encrypt ,
56 .Nm RSA_private_decrypt
57 .Nd RSA public key cryptography
61 .Fo RSA_public_encrypt
63 .Fa "const unsigned char *from"
64 .Fa "unsigned char *to"
69 .Fo RSA_private_decrypt
71 .Fa "const unsigned char *from"
72 .Fa "unsigned char *to"
77 .Fn RSA_public_encrypt
82 (usually a session key) using the public key
84 and stores the ciphertext in
92 denotes one of the following modes:
94 .It Dv RSA_PKCS1_PADDING
96 This currently is the most widely used mode.
97 .It Dv RSA_PKCS1_OAEP_PADDING
98 EME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty
100 This mode is recommended for all new applications.
101 .It Dv RSA_NO_PADDING
103 This mode should only be used to implement cryptographically sound
104 padding modes in the application code.
105 Encrypting user data directly with RSA is insecure.
111 - 11 for the PKCS #1 v1.5 based padding modes, less than
114 .Dv RSA_PKCS1_OAEP_PADDING
120 .Fn RSA_private_decrypt
125 using the private key
127 and stores the plaintext in
130 must point to a memory section large enough to hold the decrypted data
131 (which is smaller than
134 is the padding mode that was used to encrypt the data.
136 .Fn RSA_public_encrypt
137 returns the size of the encrypted data (i.e.\&
139 .Fn RSA_private_decrypt
140 returns the size of the recovered plaintext.
142 On error, -1 is returned; the error codes can be obtained by
143 .Xr ERR_get_error 3 .
145 .Xr ERR_get_error 3 ,
153 argument was added in SSLeay 0.8.
155 is available since SSLeay 0.9.0.
156 OAEP was added in OpenSSL 0.9.2b.
158 Decryption failures in the
159 .Dv RSA_PKCS1_PADDING
160 mode leak information which can potentially be used to mount a
161 Bleichenbacher padding oracle attack.
162 This is an inherent weakness in the PKCS #1 v1.5 padding design.
164 .Dv RSA_PKCS1_OAEP_PADDING .