Fix bug where only 16 bits of entropy was used

Always use aesrand_getword() & 0xFFFFFFFF not 0xFFFF. This was causing
the groups used over multiple runs of ZMap to have identical generators
too often.
This commit is contained in:
David Adrian 2013-10-16 17:22:22 -04:00
parent 69fe56864b
commit 0e03d170e6
1 changed files with 4 additions and 3 deletions

View File

@ -126,7 +126,8 @@ static int check_coprime(uint64_t check, const cyclic_group_t *group)
static uint64_t find_primroot(const cyclic_group_t *group) static uint64_t find_primroot(const cyclic_group_t *group)
{ {
// what luck, rand() returns a uint32_t! // what luck, rand() returns a uint32_t!
uint32_t candidate = (uint32_t) aesrand_getword() & 0xFFFF; uint32_t candidate = (uint32_t) aesrand_getword() & 0xFFFFFFFF;
printf("Candidate: %u\n", (unsigned) candidate);
while(check_coprime(candidate, group) != COPRIME) { while(check_coprime(candidate, group) != COPRIME) {
++candidate; ++candidate;
} }
@ -186,14 +187,14 @@ int cyclic_init(uint32_t primroot_, uint32_t current_)
primroot = find_primroot(cur_group); primroot = find_primroot(cur_group);
} while (primroot >= (1LL << 32)); } while (primroot >= (1LL << 32));
log_debug(LSRC, "primitive root: %lld", primroot); log_debug(LSRC, "primitive root: %lld", primroot);
current = (uint32_t) aesrand_getword() & 0xFFFF; current = (uint32_t) aesrand_getword() & 0xFFFFFFFF;
log_debug(LSRC, "starting point: %lld", current); log_debug(LSRC, "starting point: %lld", current);
} else { } else {
primroot = primroot_; primroot = primroot_;
log_debug(LSRC, "primitive root %lld specified by caller", log_debug(LSRC, "primitive root %lld specified by caller",
primroot); primroot);
if (!current_) { if (!current_) {
current = (uint32_t) aesrand_getword() & 0xFFFF; current = (uint32_t) aesrand_getword() & 0xFFFFFFFF;
log_debug(LSRC, "no cyclic starting point, " log_debug(LSRC, "no cyclic starting point, "
"selected random startpoint: %lld", "selected random startpoint: %lld",
current); current);