X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=fips%2Frand%2Ffips_rand.c;h=2cbe16bfd5fc4e8d36940ba8d90546549a703ae3;hb=6653c6f2e86a8e180bca4c5cd1ea9fd81aab3db1;hp=f573b26b6107090a1819c776488c975eee0ba3e7;hpb=7c8ced94c32131f24d469d2899f3339f77c47aa1;p=oweals%2Fopenssl.git diff --git a/fips/rand/fips_rand.c b/fips/rand/fips_rand.c index f573b26b61..2cbe16bfd5 100644 --- a/fips/rand/fips_rand.c +++ b/fips/rand/fips_rand.c @@ -52,7 +52,7 @@ /* * This is a FIPS approved AES PRNG based on ANSI X9.31 A.2.4. */ - +#include #include "e_os.h" /* If we don't define _XOPEN_SOURCE_EXTENDED, struct timeval won't @@ -111,7 +111,7 @@ static FIPS_PRNG_CTX sctx; static int fips_prng_fail = 0; -void FIPS_rng_stick(void) +void FIPS_x931_stick(void) { fips_prng_fail = 1; } @@ -205,30 +205,29 @@ static int fips_set_test_mode(FIPS_PRNG_CTX *ctx) return 1; } -int FIPS_rand_test_mode(void) +int FIPS_x931_test_mode(void) { return fips_set_test_mode(&sctx); } -int FIPS_rand_set_dt(unsigned char *dt) +int FIPS_x931_set_dt(unsigned char *dt) { if (!sctx.test_mode) { - RANDerr(RAND_F_FIPS_RAND_SET_DT,RAND_R_NOT_IN_TEST_MODE); + RANDerr(RAND_F_FIPS_X931_SET_DT,RAND_R_NOT_IN_TEST_MODE); return 0; } memcpy(sctx.DT, dt, AES_BLOCK_LENGTH); return 1; } -static void fips_get_dt(FIPS_PRNG_CTX *ctx) - { +void FIPS_get_timevec(unsigned char *buf, unsigned long *pctr) + { #ifdef OPENSSL_SYS_WIN32 FILETIME ft; #else struct timeval tv; #endif - unsigned char *buf = ctx->DT; #ifndef GETPID_IS_MEANINGLESS unsigned long pid; @@ -255,12 +254,12 @@ static void fips_get_dt(FIPS_PRNG_CTX *ctx) buf[6] = (unsigned char) ((tv.tv_usec >> 16) & 0xff); buf[7] = (unsigned char) ((tv.tv_usec >> 24) & 0xff); #endif - buf[8] = (unsigned char) (ctx->counter & 0xff); - buf[9] = (unsigned char) ((ctx->counter >> 8) & 0xff); - buf[10] = (unsigned char) ((ctx->counter >> 16) & 0xff); - buf[11] = (unsigned char) ((ctx->counter >> 24) & 0xff); + buf[8] = (unsigned char) (*pctr & 0xff); + buf[9] = (unsigned char) ((*pctr >> 8) & 0xff); + buf[10] = (unsigned char) ((*pctr >> 16) & 0xff); + buf[11] = (unsigned char) ((*pctr >> 24) & 0xff); - ctx->counter++; + (*pctr)++; #ifndef GETPID_IS_MEANINGLESS @@ -296,7 +295,7 @@ static int fips_rand(FIPS_PRNG_CTX *ctx, for (;;) { if (!ctx->test_mode) - fips_get_dt(ctx); + FIPS_get_timevec(ctx->DT, &ctx->counter); AES_encrypt(ctx->DT, I, &ctx->ks); for (i = 0; i < AES_BLOCK_LENGTH; i++) tmp[i] = I[i] ^ ctx->V[i]; @@ -339,7 +338,7 @@ static int fips_rand(FIPS_PRNG_CTX *ctx, } -int FIPS_rand_set_key(const unsigned char *key, int keylen) +int FIPS_x931_set_key(const unsigned char *key, int keylen) { int ret; CRYPTO_w_lock(CRYPTO_LOCK_RAND); @@ -348,7 +347,7 @@ int FIPS_rand_set_key(const unsigned char *key, int keylen) return ret; } -int FIPS_rand_seed(const void *seed, int seedlen) +int FIPS_x931_seed(const void *seed, int seedlen) { int ret; CRYPTO_w_lock(CRYPTO_LOCK_RAND); @@ -358,7 +357,7 @@ int FIPS_rand_seed(const void *seed, int seedlen) } -int FIPS_rand_bytes(unsigned char *out, int count) +int FIPS_x931_bytes(unsigned char *out, int count) { int ret; CRYPTO_w_lock(CRYPTO_LOCK_RAND); @@ -367,7 +366,7 @@ int FIPS_rand_bytes(unsigned char *out, int count) return ret; } -int FIPS_rand_status(void) +int FIPS_x931_status(void) { int ret; CRYPTO_r_lock(CRYPTO_LOCK_RAND); @@ -376,7 +375,7 @@ int FIPS_rand_status(void) return ret; } -void FIPS_rand_reset(void) +void FIPS_x931_reset(void) { CRYPTO_w_lock(CRYPTO_LOCK_RAND); fips_rand_prng_reset(&sctx); @@ -385,30 +384,30 @@ void FIPS_rand_reset(void) static int fips_do_rand_seed(const void *seed, int seedlen) { - FIPS_rand_seed(seed, seedlen); + FIPS_x931_seed(seed, seedlen); return 1; } static int fips_do_rand_add(const void *seed, int seedlen, double add_entropy) { - FIPS_rand_seed(seed, seedlen); + FIPS_x931_seed(seed, seedlen); return 1; } -static const RAND_METHOD rand_fips_meth= +static const RAND_METHOD rand_x931_meth= { fips_do_rand_seed, - FIPS_rand_bytes, - FIPS_rand_reset, + FIPS_x931_bytes, + FIPS_x931_reset, fips_do_rand_add, - FIPS_rand_bytes, - FIPS_rand_status + FIPS_x931_bytes, + FIPS_x931_status }; -const RAND_METHOD *FIPS_rand_method(void) +const RAND_METHOD *FIPS_x931_method(void) { - return &rand_fips_meth; + return &rand_x931_meth; } #endif