Mercurial > dropbear
diff random.c @ 511:582cb38e4eb5 insecure-nocrypto
propagate from branch 'au.asn.ucc.matt.dropbear' (head cdcc3c729e29544e8b98a408e2dc60e4483dfd2a)
to branch 'au.asn.ucc.matt.dropbear.insecure-nocrypto' (head 0ca38a1cf349f7426ac9de34ebe4c3e3735effab)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 06 Nov 2008 13:16:55 +0000 |
parents | 2cd2edfa11ee |
children | c1e9c81d1d27 76097ec1a29a |
line wrap: on
line diff
--- a/random.c Mon Oct 02 06:40:51 2006 +0000 +++ b/random.c Thu Nov 06 13:16:55 2008 +0000 @@ -31,7 +31,8 @@ /* this is used to generate unique output from the same hashpool */ static uint32_t counter = 0; -#define MAX_COUNTER 1<<31 /* the max value for the counter, so it won't loop */ +/* the max value for the counter, so it won't integer overflow */ +#define MAX_COUNTER 1<<30 static unsigned char hashpool[SHA1_HASH_SIZE]; @@ -133,7 +134,7 @@ hash_state hs; /* initialise so that things won't warn about - * hashing an undefined buffer */ + * hashing an undefined buffer */ if (!donerandinit) { m_burn(hashpool, sizeof(hashpool)); } @@ -156,18 +157,17 @@ * the random pools for fork()ed processes. */ void reseedrandom() { - pid_t pid; - struct timeval tv; + pid_t pid; + hash_state hs; + struct timeval tv; if (!donerandinit) { dropbear_exit("seedrandom not done"); } - pid = getpid(); - gettimeofday(&tv, NULL); + pid = getpid(); + gettimeofday(&tv, NULL); - hash_state hs; - unsigned char hash[SHA1_HASH_SIZE]; sha1_init(&hs); sha1_process(&hs, (void*)hashpool, sizeof(hashpool)); sha1_process(&hs, (void*)&pid, sizeof(pid)); @@ -214,7 +214,7 @@ unsigned char *randbuf = NULL; unsigned int len = 0; - const char masks[] = {0xff, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f}; + const unsigned char masks[] = {0xff, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f}; const int size_bits = mp_count_bits(max); @@ -234,8 +234,7 @@ /* keep regenerating until we get one satisfying * 0 < rand < max */ - } while ( ( (max != NULL) && (mp_cmp(rand, max) != MP_LT) ) - || (mp_cmp_d(rand, 0) != MP_GT) ); + } while (mp_cmp(rand, max) != MP_LT); m_burn(randbuf, len); m_free(randbuf); }