1*2175Sjp161948=pod 2*2175Sjp161948 3*2175Sjp161948=head1 NAME 4*2175Sjp161948 5*2175Sjp161948RSA_set_default_method, RSA_get_default_method, RSA_set_method, 6*2175Sjp161948RSA_get_method, RSA_PKCS1_SSLeay, RSA_null_method, RSA_flags, 7*2175Sjp161948RSA_new_method - select RSA method 8*2175Sjp161948 9*2175Sjp161948=head1 SYNOPSIS 10*2175Sjp161948 11*2175Sjp161948 #include <openssl/rsa.h> 12*2175Sjp161948 13*2175Sjp161948 void RSA_set_default_method(const RSA_METHOD *meth); 14*2175Sjp161948 15*2175Sjp161948 RSA_METHOD *RSA_get_default_method(void); 16*2175Sjp161948 17*2175Sjp161948 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth); 18*2175Sjp161948 19*2175Sjp161948 RSA_METHOD *RSA_get_method(const RSA *rsa); 20*2175Sjp161948 21*2175Sjp161948 RSA_METHOD *RSA_PKCS1_SSLeay(void); 22*2175Sjp161948 23*2175Sjp161948 RSA_METHOD *RSA_null_method(void); 24*2175Sjp161948 25*2175Sjp161948 int RSA_flags(const RSA *rsa); 26*2175Sjp161948 27*2175Sjp161948 RSA *RSA_new_method(RSA_METHOD *method); 28*2175Sjp161948 29*2175Sjp161948=head1 DESCRIPTION 30*2175Sjp161948 31*2175Sjp161948An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA 32*2175Sjp161948operations. By modifying the method, alternative implementations such as 33*2175Sjp161948hardware accelerators may be used. IMPORTANT: See the NOTES section for 34*2175Sjp161948important information about how these RSA API functions are affected by the 35*2175Sjp161948use of B<ENGINE> API calls. 36*2175Sjp161948 37*2175Sjp161948Initially, the default RSA_METHOD is the OpenSSL internal implementation, 38*2175Sjp161948as returned by RSA_PKCS1_SSLeay(). 39*2175Sjp161948 40*2175Sjp161948RSA_set_default_method() makes B<meth> the default method for all RSA 41*2175Sjp161948structures created later. B<NB>: This is true only whilst no ENGINE has 42*2175Sjp161948been set as a default for RSA, so this function is no longer recommended. 43*2175Sjp161948 44*2175Sjp161948RSA_get_default_method() returns a pointer to the current default 45*2175Sjp161948RSA_METHOD. However, the meaningfulness of this result is dependant on 46*2175Sjp161948whether the ENGINE API is being used, so this function is no longer 47*2175Sjp161948recommended. 48*2175Sjp161948 49*2175Sjp161948RSA_set_method() selects B<meth> to perform all operations using the key 50*2175Sjp161948B<rsa>. This will replace the RSA_METHOD used by the RSA key and if the 51*2175Sjp161948previous method was supplied by an ENGINE, the handle to that ENGINE will 52*2175Sjp161948be released during the change. It is possible to have RSA keys that only 53*2175Sjp161948work with certain RSA_METHOD implementations (eg. from an ENGINE module 54*2175Sjp161948that supports embedded hardware-protected keys), and in such cases 55*2175Sjp161948attempting to change the RSA_METHOD for the key can have unexpected 56*2175Sjp161948results. 57*2175Sjp161948 58*2175Sjp161948RSA_get_method() returns a pointer to the RSA_METHOD being used by B<rsa>. 59*2175Sjp161948This method may or may not be supplied by an ENGINE implementation, but if 60*2175Sjp161948it is, the return value can only be guaranteed to be valid as long as the 61*2175Sjp161948RSA key itself is valid and does not have its implementation changed by 62*2175Sjp161948RSA_set_method(). 63*2175Sjp161948 64*2175Sjp161948RSA_flags() returns the B<flags> that are set for B<rsa>'s current 65*2175Sjp161948RSA_METHOD. See the BUGS section. 66*2175Sjp161948 67*2175Sjp161948RSA_new_method() allocates and initializes an RSA structure so that 68*2175Sjp161948B<engine> will be used for the RSA operations. If B<engine> is NULL, the 69*2175Sjp161948default ENGINE for RSA operations is used, and if no default ENGINE is set, 70*2175Sjp161948the RSA_METHOD controlled by RSA_set_default_method() is used. 71*2175Sjp161948 72*2175Sjp161948RSA_flags() returns the B<flags> that are set for B<rsa>'s current method. 73*2175Sjp161948 74*2175Sjp161948RSA_new_method() allocates and initializes an B<RSA> structure so that 75*2175Sjp161948B<method> will be used for the RSA operations. If B<method> is B<NULL>, 76*2175Sjp161948the default method is used. 77*2175Sjp161948 78*2175Sjp161948=head1 THE RSA_METHOD STRUCTURE 79*2175Sjp161948 80*2175Sjp161948 typedef struct rsa_meth_st 81*2175Sjp161948 { 82*2175Sjp161948 /* name of the implementation */ 83*2175Sjp161948 const char *name; 84*2175Sjp161948 85*2175Sjp161948 /* encrypt */ 86*2175Sjp161948 int (*rsa_pub_enc)(int flen, unsigned char *from, 87*2175Sjp161948 unsigned char *to, RSA *rsa, int padding); 88*2175Sjp161948 89*2175Sjp161948 /* verify arbitrary data */ 90*2175Sjp161948 int (*rsa_pub_dec)(int flen, unsigned char *from, 91*2175Sjp161948 unsigned char *to, RSA *rsa, int padding); 92*2175Sjp161948 93*2175Sjp161948 /* sign arbitrary data */ 94*2175Sjp161948 int (*rsa_priv_enc)(int flen, unsigned char *from, 95*2175Sjp161948 unsigned char *to, RSA *rsa, int padding); 96*2175Sjp161948 97*2175Sjp161948 /* decrypt */ 98*2175Sjp161948 int (*rsa_priv_dec)(int flen, unsigned char *from, 99*2175Sjp161948 unsigned char *to, RSA *rsa, int padding); 100*2175Sjp161948 101*2175Sjp161948 /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some 102*2175Sjp161948 implementations) */ 103*2175Sjp161948 int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa); 104*2175Sjp161948 105*2175Sjp161948 /* compute r = a ^ p mod m (May be NULL for some implementations) */ 106*2175Sjp161948 int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p, 107*2175Sjp161948 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); 108*2175Sjp161948 109*2175Sjp161948 /* called at RSA_new */ 110*2175Sjp161948 int (*init)(RSA *rsa); 111*2175Sjp161948 112*2175Sjp161948 /* called at RSA_free */ 113*2175Sjp161948 int (*finish)(RSA *rsa); 114*2175Sjp161948 115*2175Sjp161948 /* RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key 116*2175Sjp161948 * operations, even if p,q,dmp1,dmq1,iqmp 117*2175Sjp161948 * are NULL 118*2175Sjp161948 * RSA_FLAG_SIGN_VER - enable rsa_sign and rsa_verify 119*2175Sjp161948 * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match 120*2175Sjp161948 */ 121*2175Sjp161948 int flags; 122*2175Sjp161948 123*2175Sjp161948 char *app_data; /* ?? */ 124*2175Sjp161948 125*2175Sjp161948 /* sign. For backward compatibility, this is used only 126*2175Sjp161948 * if (flags & RSA_FLAG_SIGN_VER) 127*2175Sjp161948 */ 128*2175Sjp161948 int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len, 129*2175Sjp161948 unsigned char *sigret, unsigned int *siglen, RSA *rsa); 130*2175Sjp161948 131*2175Sjp161948 /* verify. For backward compatibility, this is used only 132*2175Sjp161948 * if (flags & RSA_FLAG_SIGN_VER) 133*2175Sjp161948 */ 134*2175Sjp161948 int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len, 135*2175Sjp161948 unsigned char *sigbuf, unsigned int siglen, RSA *rsa); 136*2175Sjp161948 137*2175Sjp161948 } RSA_METHOD; 138*2175Sjp161948 139*2175Sjp161948=head1 RETURN VALUES 140*2175Sjp161948 141*2175Sjp161948RSA_PKCS1_SSLeay(), RSA_PKCS1_null_method(), RSA_get_default_method() 142*2175Sjp161948and RSA_get_method() return pointers to the respective RSA_METHODs. 143*2175Sjp161948 144*2175Sjp161948RSA_set_default_method() returns no value. 145*2175Sjp161948 146*2175Sjp161948RSA_set_method() returns a pointer to the old RSA_METHOD implementation 147*2175Sjp161948that was replaced. However, this return value should probably be ignored 148*2175Sjp161948because if it was supplied by an ENGINE, the pointer could be invalidated 149*2175Sjp161948at any time if the ENGINE is unloaded (in fact it could be unloaded as a 150*2175Sjp161948result of the RSA_set_method() function releasing its handle to the 151*2175Sjp161948ENGINE). For this reason, the return type may be replaced with a B<void> 152*2175Sjp161948declaration in a future release. 153*2175Sjp161948 154*2175Sjp161948RSA_new_method() returns NULL and sets an error code that can be obtained 155*2175Sjp161948by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise 156*2175Sjp161948it returns a pointer to the newly allocated structure. 157*2175Sjp161948 158*2175Sjp161948=head1 NOTES 159*2175Sjp161948 160*2175Sjp161948As of version 0.9.7, RSA_METHOD implementations are grouped together with 161*2175Sjp161948other algorithmic APIs (eg. DSA_METHOD, EVP_CIPHER, etc) into B<ENGINE> 162*2175Sjp161948modules. If a default ENGINE is specified for RSA functionality using an 163*2175Sjp161948ENGINE API function, that will override any RSA defaults set using the RSA 164*2175Sjp161948API (ie. RSA_set_default_method()). For this reason, the ENGINE API is the 165*2175Sjp161948recommended way to control default implementations for use in RSA and other 166*2175Sjp161948cryptographic algorithms. 167*2175Sjp161948 168*2175Sjp161948=head1 BUGS 169*2175Sjp161948 170*2175Sjp161948The behaviour of RSA_flags() is a mis-feature that is left as-is for now 171*2175Sjp161948to avoid creating compatibility problems. RSA functionality, such as the 172*2175Sjp161948encryption functions, are controlled by the B<flags> value in the RSA key 173*2175Sjp161948itself, not by the B<flags> value in the RSA_METHOD attached to the RSA key 174*2175Sjp161948(which is what this function returns). If the flags element of an RSA key 175*2175Sjp161948is changed, the changes will be honoured by RSA functionality but will not 176*2175Sjp161948be reflected in the return value of the RSA_flags() function - in effect 177*2175Sjp161948RSA_flags() behaves more like an RSA_default_flags() function (which does 178*2175Sjp161948not currently exist). 179*2175Sjp161948 180*2175Sjp161948=head1 SEE ALSO 181*2175Sjp161948 182*2175Sjp161948L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)> 183*2175Sjp161948 184*2175Sjp161948=head1 HISTORY 185*2175Sjp161948 186*2175Sjp161948RSA_new_method() and RSA_set_default_method() appeared in SSLeay 0.8. 187*2175Sjp161948RSA_get_default_method(), RSA_set_method() and RSA_get_method() as 188*2175Sjp161948well as the rsa_sign and rsa_verify components of RSA_METHOD were 189*2175Sjp161948added in OpenSSL 0.9.4. 190*2175Sjp161948 191*2175Sjp161948RSA_set_default_openssl_method() and RSA_get_default_openssl_method() 192*2175Sjp161948replaced RSA_set_default_method() and RSA_get_default_method() 193*2175Sjp161948respectively, and RSA_set_method() and RSA_new_method() were altered to use 194*2175Sjp161948B<ENGINE>s rather than B<RSA_METHOD>s during development of the engine 195*2175Sjp161948version of OpenSSL 0.9.6. For 0.9.7, the handling of defaults in the ENGINE 196*2175Sjp161948API was restructured so that this change was reversed, and behaviour of the 197*2175Sjp161948other functions resembled more closely the previous behaviour. The 198*2175Sjp161948behaviour of defaults in the ENGINE API now transparently overrides the 199*2175Sjp161948behaviour of defaults in the RSA API without requiring changing these 200*2175Sjp161948function prototypes. 201*2175Sjp161948 202*2175Sjp161948=cut 203