From: Richard Levitte Date: Fri, 7 Jul 2000 16:57:16 +0000 (+0000) Subject: Change the overall RAND routines to actually make use of engines. X-Git-Tag: OpenSSL-engine-0_9_6-beta1~27 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=eb2f937b93306eb70767fddbe6ccc83e462de77f;p=oweals%2Fopenssl.git Change the overall RAND routines to actually make use of engines. This seems to work, but I'm a little unsure that I got it all right, and would like this to be reviewed. --- diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c index 7da74aab0e..57eff0f132 100644 --- a/crypto/rand/rand_lib.c +++ b/crypto/rand/rand_lib.c @@ -59,59 +59,78 @@ #include #include #include +#include -#ifdef NO_RAND -static RAND_METHOD *rand_meth=NULL; -#else -extern RAND_METHOD rand_ssleay_meth; -static RAND_METHOD *rand_meth= &rand_ssleay_meth; -#endif +static ENGINE *rand_engine=NULL; +#if 0 void RAND_set_rand_method(RAND_METHOD *meth) { rand_meth=meth; } +#else +int RAND_set_rand_method(ENGINE *engine) + { + ENGINE *mtmp; + mtmp = rand_engine; + if (!ENGINE_init(engine)) + return 0; + rand_engine = engine; + /* SHOULD ERROR CHECK THIS!!! */ + ENGINE_finish(mtmp); + return 1; + } +#endif RAND_METHOD *RAND_get_rand_method(void) { - return(rand_meth); + if (rand_engine == NULL + && (rand_engine = ENGINE_get_default_RAND()) == NULL) + return NULL; + return ENGINE_get_RAND(rand_engine); } void RAND_cleanup(void) { - if (rand_meth != NULL) - rand_meth->cleanup(); + RAND_METHOD *meth = RAND_get_rand_method(); + if (meth && meth->cleanup) + meth->cleanup(); } void RAND_seed(const void *buf, int num) { - if (rand_meth != NULL) - rand_meth->seed(buf,num); + RAND_METHOD *meth = RAND_get_rand_method(); + if (meth && meth->seed) + meth->seed(buf,num); } void RAND_add(const void *buf, int num, double entropy) { - if (rand_meth != NULL) - rand_meth->add(buf,num,entropy); + RAND_METHOD *meth = RAND_get_rand_method(); + if (meth && meth->add) + meth->add(buf,num,entropy); } int RAND_bytes(unsigned char *buf, int num) { - if (rand_meth != NULL) - return rand_meth->bytes(buf,num); + RAND_METHOD *meth = RAND_get_rand_method(); + if (meth && meth->bytes) + return meth->bytes(buf,num); return(-1); } int RAND_pseudo_bytes(unsigned char *buf, int num) { - if (rand_meth != NULL) - return rand_meth->pseudorand(buf,num); + RAND_METHOD *meth = RAND_get_rand_method(); + if (meth && meth->pseudorand) + return meth->pseudorand(buf,num); return(-1); } int RAND_status(void) { - if (rand_meth != NULL) - return rand_meth->status(); + RAND_METHOD *meth = RAND_get_rand_method(); + if (meth && meth->status) + return meth->status(); return 0; }