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