From: Geoff Thorpe Date: Tue, 7 Jan 2003 05:51:39 +0000 (+0000) Subject: This is the first step in allowing RSA_METHODs to implement their own key X-Git-Tag: OpenSSL_0_9_7a~86^2~18 X-Git-Url: https://git.openssl.org/?p=openssl.git;a=commitdiff_plain;h=2814c629154a2ef9f7371808738eb70c92a1d1b1 This is the first step in allowing RSA_METHODs to implement their own key generation. This prototype matches the new API function RSA_generate_key_ex(), though both may be subject to change during development before 0.9.8. --- diff --git a/crypto/rsa/rsa.h b/crypto/rsa/rsa.h index cdf514c009..b005b4b0b3 100644 --- a/crypto/rsa/rsa.h +++ b/crypto/rsa/rsa.h @@ -114,7 +114,11 @@ typedef struct rsa_meth_st int (*rsa_verify)(int dtype, const unsigned char *m, unsigned int m_length, unsigned char *sigbuf, unsigned int siglen, const RSA *rsa); - +/* If this callback is NULL, the builtin software RSA key-gen will be used. This + * is for behavioural compatibility whilst the code gets rewired, but one day + * it would be nice to assume there are no such things as "builtin software" + * implementations. */ + int (*rsa_keygen)(RSA *rsa, int bits, unsigned long e, BN_GENCB *cb); } RSA_METHOD; struct rsa_st diff --git a/crypto/rsa/rsa_eay.c b/crypto/rsa/rsa_eay.c index c4e6d1e22a..cab34847df 100644 --- a/crypto/rsa/rsa_eay.c +++ b/crypto/rsa/rsa_eay.c @@ -89,7 +89,8 @@ static RSA_METHOD rsa_pkcs1_eay_meth={ 0, /* flags */ NULL, 0, /* rsa_sign */ - 0 /* rsa_verify */ + 0, /* rsa_verify */ + NULL /* rsa_keygen */ }; const RSA_METHOD *RSA_PKCS1_SSLeay(void) diff --git a/crypto/rsa/rsa_gen.c b/crypto/rsa/rsa_gen.c index e3ae03e691..3714b248c4 100644 --- a/crypto/rsa/rsa_gen.c +++ b/crypto/rsa/rsa_gen.c @@ -68,7 +68,21 @@ #include #include +static int rsa_builtin_keygen(RSA *rsa, int bits, unsigned long e_value, BN_GENCB *cb); + +/* NB: this wrapper would normally be placed in rsa_lib.c and the static + * implementation would probably be in rsa_eay.c. Nonetheless, is kept here so + * that we don't introduce a new linker dependency. Eg. any application that + * wasn't previously linking object code related to key-generation won't have to + * now just because key-generation is part of RSA_METHOD. */ int RSA_generate_key_ex(RSA *rsa, int bits, unsigned long e_value, BN_GENCB *cb) + { + if(rsa->meth->rsa_keygen) + return rsa->meth->rsa_keygen(rsa, bits, e_value, cb); + return rsa_builtin_keygen(rsa, bits, e_value, cb); + } + +static int rsa_builtin_keygen(RSA *rsa, int bits, unsigned long e_value, BN_GENCB *cb) { BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp; int bitsp,bitsq,ok= -1,n=0,i; diff --git a/crypto/rsa/rsa_null.c b/crypto/rsa/rsa_null.c index 64057fbdcf..1bf70ca2a9 100644 --- a/crypto/rsa/rsa_null.c +++ b/crypto/rsa/rsa_null.c @@ -94,6 +94,9 @@ static RSA_METHOD rsa_null_meth={ RSA_null_finish, 0, NULL, + NULL, + NULL, + NULL }; const RSA_METHOD *RSA_null_method(void)