1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimRSA_set_default_method, RSA_get_default_method, RSA_set_method, 6e71b7053SJung-uk KimRSA_get_method, RSA_PKCS1_OpenSSL, RSA_flags, 7e71b7053SJung-uk KimRSA_new_method - select RSA method 8e71b7053SJung-uk Kim 9e71b7053SJung-uk Kim=head1 SYNOPSIS 10e71b7053SJung-uk Kim 11e71b7053SJung-uk Kim #include <openssl/rsa.h> 12e71b7053SJung-uk Kim 13*b077aed3SPierre ProncheryThe following functions have been deprecated since OpenSSL 3.0, and can be 14*b077aed3SPierre Proncheryhidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value, 15*b077aed3SPierre Proncherysee L<openssl_user_macros(7)>: 16*b077aed3SPierre Pronchery 17e71b7053SJung-uk Kim void RSA_set_default_method(const RSA_METHOD *meth); 18e71b7053SJung-uk Kim 19*b077aed3SPierre Pronchery const RSA_METHOD *RSA_get_default_method(void); 20e71b7053SJung-uk Kim 21e71b7053SJung-uk Kim int RSA_set_method(RSA *rsa, const RSA_METHOD *meth); 22e71b7053SJung-uk Kim 23*b077aed3SPierre Pronchery const RSA_METHOD *RSA_get_method(const RSA *rsa); 24e71b7053SJung-uk Kim 25*b077aed3SPierre Pronchery const RSA_METHOD *RSA_PKCS1_OpenSSL(void); 26e71b7053SJung-uk Kim 27e71b7053SJung-uk Kim int RSA_flags(const RSA *rsa); 28e71b7053SJung-uk Kim 29e71b7053SJung-uk Kim RSA *RSA_new_method(ENGINE *engine); 30e71b7053SJung-uk Kim 31e71b7053SJung-uk Kim=head1 DESCRIPTION 32e71b7053SJung-uk Kim 33*b077aed3SPierre ProncheryAll of the functions described on this page are deprecated. 34*b077aed3SPierre ProncheryApplications should instead use the OSSL_PROVIDER APIs. 35*b077aed3SPierre Pronchery 36e71b7053SJung-uk KimAn B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA 37e71b7053SJung-uk Kimoperations. By modifying the method, alternative implementations such as 38e71b7053SJung-uk Kimhardware accelerators may be used. IMPORTANT: See the NOTES section for 39e71b7053SJung-uk Kimimportant information about how these RSA API functions are affected by the 40e71b7053SJung-uk Kimuse of B<ENGINE> API calls. 41e71b7053SJung-uk Kim 42e71b7053SJung-uk KimInitially, the default RSA_METHOD is the OpenSSL internal implementation, 43e71b7053SJung-uk Kimas returned by RSA_PKCS1_OpenSSL(). 44e71b7053SJung-uk Kim 45e71b7053SJung-uk KimRSA_set_default_method() makes B<meth> the default method for all RSA 46e71b7053SJung-uk Kimstructures created later. 47e71b7053SJung-uk KimB<NB>: This is true only whilst no ENGINE has 48e71b7053SJung-uk Kimbeen set as a default for RSA, so this function is no longer recommended. 49e71b7053SJung-uk KimThis function is not thread-safe and should not be called at the same time 50e71b7053SJung-uk Kimas other OpenSSL functions. 51e71b7053SJung-uk Kim 52e71b7053SJung-uk KimRSA_get_default_method() returns a pointer to the current default 53e71b7053SJung-uk KimRSA_METHOD. However, the meaningfulness of this result is dependent on 54e71b7053SJung-uk Kimwhether the ENGINE API is being used, so this function is no longer 55e71b7053SJung-uk Kimrecommended. 56e71b7053SJung-uk Kim 57e71b7053SJung-uk KimRSA_set_method() selects B<meth> to perform all operations using the key 58e71b7053SJung-uk KimB<rsa>. This will replace the RSA_METHOD used by the RSA key and if the 59e71b7053SJung-uk Kimprevious method was supplied by an ENGINE, the handle to that ENGINE will 60e71b7053SJung-uk Kimbe released during the change. It is possible to have RSA keys that only 6158f35182SJung-uk Kimwork with certain RSA_METHOD implementations (e.g. from an ENGINE module 62e71b7053SJung-uk Kimthat supports embedded hardware-protected keys), and in such cases 63e71b7053SJung-uk Kimattempting to change the RSA_METHOD for the key can have unexpected 64e71b7053SJung-uk Kimresults. 65e71b7053SJung-uk Kim 66e71b7053SJung-uk KimRSA_get_method() returns a pointer to the RSA_METHOD being used by B<rsa>. 67e71b7053SJung-uk KimThis method may or may not be supplied by an ENGINE implementation, but if 68e71b7053SJung-uk Kimit is, the return value can only be guaranteed to be valid as long as the 69e71b7053SJung-uk KimRSA key itself is valid and does not have its implementation changed by 70e71b7053SJung-uk KimRSA_set_method(). 71e71b7053SJung-uk Kim 72e71b7053SJung-uk KimRSA_flags() returns the B<flags> that are set for B<rsa>'s current 73e71b7053SJung-uk KimRSA_METHOD. See the BUGS section. 74e71b7053SJung-uk Kim 75e71b7053SJung-uk KimRSA_new_method() allocates and initializes an RSA structure so that 76e71b7053SJung-uk KimB<engine> will be used for the RSA operations. If B<engine> is NULL, the 77e71b7053SJung-uk Kimdefault ENGINE for RSA operations is used, and if no default ENGINE is set, 78e71b7053SJung-uk Kimthe RSA_METHOD controlled by RSA_set_default_method() is used. 79e71b7053SJung-uk Kim 80e71b7053SJung-uk KimRSA_flags() returns the B<flags> that are set for B<rsa>'s current method. 81e71b7053SJung-uk Kim 82e71b7053SJung-uk KimRSA_new_method() allocates and initializes an B<RSA> structure so that 83e71b7053SJung-uk KimB<method> will be used for the RSA operations. If B<method> is B<NULL>, 84e71b7053SJung-uk Kimthe default method is used. 85e71b7053SJung-uk Kim 86e71b7053SJung-uk Kim=head1 THE RSA_METHOD STRUCTURE 87e71b7053SJung-uk Kim 88e71b7053SJung-uk Kim typedef struct rsa_meth_st 89e71b7053SJung-uk Kim { 90e71b7053SJung-uk Kim /* name of the implementation */ 91e71b7053SJung-uk Kim const char *name; 92e71b7053SJung-uk Kim 93e71b7053SJung-uk Kim /* encrypt */ 94e71b7053SJung-uk Kim int (*rsa_pub_enc)(int flen, unsigned char *from, 95e71b7053SJung-uk Kim unsigned char *to, RSA *rsa, int padding); 96e71b7053SJung-uk Kim 97e71b7053SJung-uk Kim /* verify arbitrary data */ 98e71b7053SJung-uk Kim int (*rsa_pub_dec)(int flen, unsigned char *from, 99e71b7053SJung-uk Kim unsigned char *to, RSA *rsa, int padding); 100e71b7053SJung-uk Kim 101e71b7053SJung-uk Kim /* sign arbitrary data */ 102e71b7053SJung-uk Kim int (*rsa_priv_enc)(int flen, unsigned char *from, 103e71b7053SJung-uk Kim unsigned char *to, RSA *rsa, int padding); 104e71b7053SJung-uk Kim 105e71b7053SJung-uk Kim /* decrypt */ 106e71b7053SJung-uk Kim int (*rsa_priv_dec)(int flen, unsigned char *from, 107e71b7053SJung-uk Kim unsigned char *to, RSA *rsa, int padding); 108e71b7053SJung-uk Kim 109e71b7053SJung-uk Kim /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some implementations) */ 110e71b7053SJung-uk Kim int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa); 111e71b7053SJung-uk Kim 112e71b7053SJung-uk Kim /* compute r = a ^ p mod m (May be NULL for some implementations) */ 113e71b7053SJung-uk Kim int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p, 114e71b7053SJung-uk Kim const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); 115e71b7053SJung-uk Kim 116e71b7053SJung-uk Kim /* called at RSA_new */ 117e71b7053SJung-uk Kim int (*init)(RSA *rsa); 118e71b7053SJung-uk Kim 119e71b7053SJung-uk Kim /* called at RSA_free */ 120e71b7053SJung-uk Kim int (*finish)(RSA *rsa); 121e71b7053SJung-uk Kim 122e71b7053SJung-uk Kim /* 123e71b7053SJung-uk Kim * RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key 124e71b7053SJung-uk Kim * operations, even if p,q,dmp1,dmq1,iqmp 125e71b7053SJung-uk Kim * are NULL 126e71b7053SJung-uk Kim * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match 127e71b7053SJung-uk Kim */ 128e71b7053SJung-uk Kim int flags; 129e71b7053SJung-uk Kim 130e71b7053SJung-uk Kim char *app_data; /* ?? */ 131e71b7053SJung-uk Kim 132e71b7053SJung-uk Kim int (*rsa_sign)(int type, 133e71b7053SJung-uk Kim const unsigned char *m, unsigned int m_length, 134e71b7053SJung-uk Kim unsigned char *sigret, unsigned int *siglen, const RSA *rsa); 135e71b7053SJung-uk Kim int (*rsa_verify)(int dtype, 136e71b7053SJung-uk Kim const unsigned char *m, unsigned int m_length, 137e71b7053SJung-uk Kim const unsigned char *sigbuf, unsigned int siglen, 138e71b7053SJung-uk Kim const RSA *rsa); 139*b077aed3SPierre Pronchery /* keygen. If NULL built-in RSA key generation will be used */ 140e71b7053SJung-uk Kim int (*rsa_keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); 141e71b7053SJung-uk Kim 142e71b7053SJung-uk Kim } RSA_METHOD; 143e71b7053SJung-uk Kim 144e71b7053SJung-uk Kim=head1 RETURN VALUES 145e71b7053SJung-uk Kim 146e71b7053SJung-uk KimRSA_PKCS1_OpenSSL(), RSA_PKCS1_null_method(), RSA_get_default_method() 147e71b7053SJung-uk Kimand RSA_get_method() return pointers to the respective RSA_METHODs. 148e71b7053SJung-uk Kim 149e71b7053SJung-uk KimRSA_set_default_method() returns no value. 150e71b7053SJung-uk Kim 151e71b7053SJung-uk KimRSA_set_method() returns a pointer to the old RSA_METHOD implementation 152e71b7053SJung-uk Kimthat was replaced. However, this return value should probably be ignored 153e71b7053SJung-uk Kimbecause if it was supplied by an ENGINE, the pointer could be invalidated 154e71b7053SJung-uk Kimat any time if the ENGINE is unloaded (in fact it could be unloaded as a 155e71b7053SJung-uk Kimresult of the RSA_set_method() function releasing its handle to the 156e71b7053SJung-uk KimENGINE). For this reason, the return type may be replaced with a B<void> 157e71b7053SJung-uk Kimdeclaration in a future release. 158e71b7053SJung-uk Kim 159e71b7053SJung-uk KimRSA_new_method() returns NULL and sets an error code that can be obtained 160e71b7053SJung-uk Kimby L<ERR_get_error(3)> if the allocation fails. Otherwise 161e71b7053SJung-uk Kimit returns a pointer to the newly allocated structure. 162e71b7053SJung-uk Kim 163e71b7053SJung-uk Kim=head1 BUGS 164e71b7053SJung-uk Kim 165e71b7053SJung-uk KimThe behaviour of RSA_flags() is a mis-feature that is left as-is for now 166e71b7053SJung-uk Kimto avoid creating compatibility problems. RSA functionality, such as the 167e71b7053SJung-uk Kimencryption functions, are controlled by the B<flags> value in the RSA key 168e71b7053SJung-uk Kimitself, not by the B<flags> value in the RSA_METHOD attached to the RSA key 169e71b7053SJung-uk Kim(which is what this function returns). If the flags element of an RSA key 170e71b7053SJung-uk Kimis changed, the changes will be honoured by RSA functionality but will not 171e71b7053SJung-uk Kimbe reflected in the return value of the RSA_flags() function - in effect 172e71b7053SJung-uk KimRSA_flags() behaves more like an RSA_default_flags() function (which does 173e71b7053SJung-uk Kimnot currently exist). 174e71b7053SJung-uk Kim 175e71b7053SJung-uk Kim=head1 SEE ALSO 176e71b7053SJung-uk Kim 177e71b7053SJung-uk KimL<RSA_new(3)> 178e71b7053SJung-uk Kim 179e71b7053SJung-uk Kim=head1 HISTORY 180e71b7053SJung-uk Kim 181*b077aed3SPierre ProncheryAll of these functions were deprecated in OpenSSL 3.0. 182*b077aed3SPierre Pronchery 183e71b7053SJung-uk KimThe RSA_null_method(), which was a partial attempt to avoid patent issues, 184e71b7053SJung-uk Kimwas replaced to always return NULL in OpenSSL 1.1.1. 185e71b7053SJung-uk Kim 186e71b7053SJung-uk Kim=head1 COPYRIGHT 187e71b7053SJung-uk Kim 188*b077aed3SPierre ProncheryCopyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved. 189e71b7053SJung-uk Kim 190*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 191e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 192e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 193e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 194e71b7053SJung-uk Kim 195e71b7053SJung-uk Kim=cut 196