Blame doc/man3/RSA_public_encrypt.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
RSA_public_encrypt, RSA_private_decrypt - RSA public key cryptography
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/rsa.h>
Packit c4476c
Packit c4476c
 int RSA_public_encrypt(int flen, const unsigned char *from,
Packit c4476c
                        unsigned char *to, RSA *rsa, int padding);
Packit c4476c
Packit c4476c
 int RSA_private_decrypt(int flen, const unsigned char *from,
Packit c4476c
                         unsigned char *to, RSA *rsa, int padding);
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
RSA_public_encrypt() encrypts the B<flen> bytes at B<from> (usually a
Packit c4476c
session key) using the public key B<rsa> and stores the ciphertext in
Packit c4476c
B<to>. B<to> must point to RSA_size(B<rsa>) bytes of memory.
Packit c4476c
Packit c4476c
B<padding> denotes one of the following modes:
Packit c4476c
Packit c4476c
=over 4
Packit c4476c
Packit c4476c
=item RSA_PKCS1_PADDING
Packit c4476c
Packit c4476c
PKCS #1 v1.5 padding. This currently is the most widely used mode.
Packit c4476c
However, it is highly recommended to use RSA_PKCS1_OAEP_PADDING in
Packit c4476c
new applications. SEE WARNING BELOW.
Packit c4476c
Packit c4476c
=item RSA_PKCS1_OAEP_PADDING
Packit c4476c
Packit c4476c
EME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty
Packit c4476c
encoding parameter. This mode is recommended for all new applications.
Packit c4476c
Packit c4476c
=item RSA_SSLV23_PADDING
Packit c4476c
Packit c4476c
PKCS #1 v1.5 padding with an SSL-specific modification that denotes
Packit c4476c
that the server is SSL3 capable.
Packit c4476c
Packit c4476c
=item RSA_NO_PADDING
Packit c4476c
Packit c4476c
Raw RSA encryption. This mode should I<only> be used to implement
Packit c4476c
cryptographically sound padding modes in the application code.
Packit c4476c
Encrypting user data directly with RSA is insecure.
Packit c4476c
Packit c4476c
=back
Packit c4476c
Packit c4476c
B<flen> must not be more than RSA_size(B<rsa>) - 11 for the PKCS #1 v1.5
Packit c4476c
based padding modes, not more than RSA_size(B<rsa>) - 42 for
Packit c4476c
RSA_PKCS1_OAEP_PADDING and exactly RSA_size(B<rsa>) for RSA_NO_PADDING.
Packit c4476c
When a padding mode other than RSA_NO_PADDING is in use, then
Packit c4476c
RSA_public_encrypt() will include some random bytes into the ciphertext
Packit c4476c
and therefore the ciphertext will be different each time, even if the
Packit c4476c
plaintext and the public key are exactly identical.
Packit c4476c
The returned ciphertext in B<to> will always be zero padded to exactly
Packit c4476c
RSA_size(B<rsa>) bytes.
Packit c4476c
B<to> and B<from> may overlap.
Packit c4476c
Packit c4476c
RSA_private_decrypt() decrypts the B<flen> bytes at B<from> using the
Packit c4476c
private key B<rsa> and stores the plaintext in B<to>. B<flen> should
Packit c4476c
be equal to RSA_size(B<rsa>) but may be smaller, when leading zero
Packit c4476c
bytes are in the ciphertext. Those are not important and may be removed,
Packit c4476c
but RSA_public_encrypt() does not do that. B<to> must point
Packit c4476c
to a memory section large enough to hold the maximal possible decrypted
Packit c4476c
data (which is equal to RSA_size(B<rsa>) for RSA_NO_PADDING,
Packit c4476c
RSA_size(B<rsa>) - 11 for the PKCS #1 v1.5 based padding modes and
Packit c4476c
RSA_size(B<rsa>) - 42 for RSA_PKCS1_OAEP_PADDING).
Packit c4476c
B<padding> is the padding mode that was used to encrypt the data.
Packit c4476c
B<to> and B<from> may overlap.
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
RSA_public_encrypt() returns the size of the encrypted data (i.e.,
Packit c4476c
RSA_size(B<rsa>)). RSA_private_decrypt() returns the size of the
Packit c4476c
recovered plaintext. A return value of 0 is not an error and
Packit c4476c
means only that the plaintext was empty.
Packit c4476c
Packit c4476c
On error, -1 is returned; the error codes can be
Packit c4476c
obtained by L<ERR_get_error(3)>.
Packit c4476c
Packit c4476c
=head1 WARNINGS
Packit c4476c
Packit c4476c
Decryption failures in the RSA_PKCS1_PADDING mode leak information
Packit c4476c
which can potentially be used to mount a Bleichenbacher padding oracle
Packit c4476c
attack. This is an inherent weakness in the PKCS #1 v1.5 padding
Packit c4476c
design. Prefer RSA_PKCS1_OAEP_PADDING.
Packit c4476c
Packit c4476c
=head1 CONFORMING TO
Packit c4476c
Packit c4476c
SSL, PKCS #1 v2.0
Packit c4476c
Packit c4476c
=head1 SEE ALSO
Packit c4476c
Packit c4476c
L<ERR_get_error(3)>, L<RAND_bytes(3)>,
Packit c4476c
L<RSA_size(3)>
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut