1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimRSA_public_encrypt, RSA_private_decrypt - RSA public key cryptography 6e71b7053SJung-uk Kim 7e71b7053SJung-uk Kim=head1 SYNOPSIS 8e71b7053SJung-uk Kim 9e71b7053SJung-uk Kim #include <openssl/rsa.h> 10e71b7053SJung-uk Kim 11*b077aed3SPierre ProncheryThe following functions have been deprecated since OpenSSL 3.0, and can be 12*b077aed3SPierre Proncheryhidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value, 13*b077aed3SPierre Proncherysee L<openssl_user_macros(7)>: 14*b077aed3SPierre Pronchery 15610a21fdSJung-uk Kim int RSA_public_encrypt(int flen, const unsigned char *from, 16e71b7053SJung-uk Kim unsigned char *to, RSA *rsa, int padding); 17e71b7053SJung-uk Kim 18610a21fdSJung-uk Kim int RSA_private_decrypt(int flen, const unsigned char *from, 19e71b7053SJung-uk Kim unsigned char *to, RSA *rsa, int padding); 20e71b7053SJung-uk Kim 21e71b7053SJung-uk Kim=head1 DESCRIPTION 22e71b7053SJung-uk Kim 23*b077aed3SPierre ProncheryBoth of the functions described on this page are deprecated. 24*b077aed3SPierre ProncheryApplications should instead use L<EVP_PKEY_encrypt_init_ex(3)>, 25*b077aed3SPierre ProncheryL<EVP_PKEY_encrypt(3)>, L<EVP_PKEY_decrypt_init_ex(3)> and 26*b077aed3SPierre ProncheryL<EVP_PKEY_decrypt(3)>. 27*b077aed3SPierre Pronchery 28e71b7053SJung-uk KimRSA_public_encrypt() encrypts the B<flen> bytes at B<from> (usually a 29e71b7053SJung-uk Kimsession key) using the public key B<rsa> and stores the ciphertext in 30e71b7053SJung-uk KimB<to>. B<to> must point to RSA_size(B<rsa>) bytes of memory. 31e71b7053SJung-uk Kim 32e71b7053SJung-uk KimB<padding> denotes one of the following modes: 33e71b7053SJung-uk Kim 34e71b7053SJung-uk Kim=over 4 35e71b7053SJung-uk Kim 36e71b7053SJung-uk Kim=item RSA_PKCS1_PADDING 37e71b7053SJung-uk Kim 38e71b7053SJung-uk KimPKCS #1 v1.5 padding. This currently is the most widely used mode. 39610a21fdSJung-uk KimHowever, it is highly recommended to use RSA_PKCS1_OAEP_PADDING in 40610a21fdSJung-uk Kimnew applications. SEE WARNING BELOW. 41e71b7053SJung-uk Kim 42e71b7053SJung-uk Kim=item RSA_PKCS1_OAEP_PADDING 43e71b7053SJung-uk Kim 44e71b7053SJung-uk KimEME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty 45e71b7053SJung-uk Kimencoding parameter. This mode is recommended for all new applications. 46e71b7053SJung-uk Kim 47e71b7053SJung-uk Kim=item RSA_NO_PADDING 48e71b7053SJung-uk Kim 49e71b7053SJung-uk KimRaw RSA encryption. This mode should I<only> be used to implement 50e71b7053SJung-uk Kimcryptographically sound padding modes in the application code. 51e71b7053SJung-uk KimEncrypting user data directly with RSA is insecure. 52e71b7053SJung-uk Kim 53e71b7053SJung-uk Kim=back 54e71b7053SJung-uk Kim 55610a21fdSJung-uk KimB<flen> must not be more than RSA_size(B<rsa>) - 11 for the PKCS #1 v1.5 56610a21fdSJung-uk Kimbased padding modes, not more than RSA_size(B<rsa>) - 42 for 57e71b7053SJung-uk KimRSA_PKCS1_OAEP_PADDING and exactly RSA_size(B<rsa>) for RSA_NO_PADDING. 58610a21fdSJung-uk KimWhen a padding mode other than RSA_NO_PADDING is in use, then 59610a21fdSJung-uk KimRSA_public_encrypt() will include some random bytes into the ciphertext 60610a21fdSJung-uk Kimand therefore the ciphertext will be different each time, even if the 61610a21fdSJung-uk Kimplaintext and the public key are exactly identical. 62610a21fdSJung-uk KimThe returned ciphertext in B<to> will always be zero padded to exactly 63610a21fdSJung-uk KimRSA_size(B<rsa>) bytes. 64610a21fdSJung-uk KimB<to> and B<from> may overlap. 65e71b7053SJung-uk Kim 66e71b7053SJung-uk KimRSA_private_decrypt() decrypts the B<flen> bytes at B<from> using the 67610a21fdSJung-uk Kimprivate key B<rsa> and stores the plaintext in B<to>. B<flen> should 68610a21fdSJung-uk Kimbe equal to RSA_size(B<rsa>) but may be smaller, when leading zero 69610a21fdSJung-uk Kimbytes are in the ciphertext. Those are not important and may be removed, 70610a21fdSJung-uk Kimbut RSA_public_encrypt() does not do that. B<to> must point 71610a21fdSJung-uk Kimto a memory section large enough to hold the maximal possible decrypted 72610a21fdSJung-uk Kimdata (which is equal to RSA_size(B<rsa>) for RSA_NO_PADDING, 73610a21fdSJung-uk KimRSA_size(B<rsa>) - 11 for the PKCS #1 v1.5 based padding modes and 74610a21fdSJung-uk KimRSA_size(B<rsa>) - 42 for RSA_PKCS1_OAEP_PADDING). 75610a21fdSJung-uk KimB<padding> is the padding mode that was used to encrypt the data. 76610a21fdSJung-uk KimB<to> and B<from> may overlap. 77e71b7053SJung-uk Kim 78e71b7053SJung-uk Kim=head1 RETURN VALUES 79e71b7053SJung-uk Kim 80e71b7053SJung-uk KimRSA_public_encrypt() returns the size of the encrypted data (i.e., 81e71b7053SJung-uk KimRSA_size(B<rsa>)). RSA_private_decrypt() returns the size of the 82610a21fdSJung-uk Kimrecovered plaintext. A return value of 0 is not an error and 83610a21fdSJung-uk Kimmeans only that the plaintext was empty. 84e71b7053SJung-uk Kim 85e71b7053SJung-uk KimOn error, -1 is returned; the error codes can be 86e71b7053SJung-uk Kimobtained by L<ERR_get_error(3)>. 87e71b7053SJung-uk Kim 88da327cd2SJung-uk Kim=head1 WARNINGS 89e71b7053SJung-uk Kim 90e71b7053SJung-uk KimDecryption failures in the RSA_PKCS1_PADDING mode leak information 91e71b7053SJung-uk Kimwhich can potentially be used to mount a Bleichenbacher padding oracle 92e71b7053SJung-uk Kimattack. This is an inherent weakness in the PKCS #1 v1.5 padding 93e71b7053SJung-uk Kimdesign. Prefer RSA_PKCS1_OAEP_PADDING. 94e71b7053SJung-uk Kim 95e71b7053SJung-uk Kim=head1 CONFORMING TO 96e71b7053SJung-uk Kim 97e71b7053SJung-uk KimSSL, PKCS #1 v2.0 98e71b7053SJung-uk Kim 99e71b7053SJung-uk Kim=head1 SEE ALSO 100e71b7053SJung-uk Kim 101e71b7053SJung-uk KimL<ERR_get_error(3)>, L<RAND_bytes(3)>, 102e71b7053SJung-uk KimL<RSA_size(3)> 103e71b7053SJung-uk Kim 104*b077aed3SPierre Pronchery=head1 HISTORY 105*b077aed3SPierre Pronchery 106*b077aed3SPierre ProncheryBoth of these functions were deprecated in OpenSSL 3.0. 107*b077aed3SPierre Pronchery 108e71b7053SJung-uk Kim=head1 COPYRIGHT 109e71b7053SJung-uk Kim 110*b077aed3SPierre ProncheryCopyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved. 111e71b7053SJung-uk Kim 112*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 113e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 114e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 115e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 116e71b7053SJung-uk Kim 117e71b7053SJung-uk Kim=cut 118