From 377ed5445083af5703fe8b0411ad162af1766012 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Thu, 17 Jan 2019 09:16:50 -0500 Subject: Fix some warnings from PVS-Studio No real bugs, but pointed out some odd constructs and duplicated logic --- src/lib/math/numbertheory/make_prm.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/lib/math/numbertheory/make_prm.cpp') diff --git a/src/lib/math/numbertheory/make_prm.cpp b/src/lib/math/numbertheory/make_prm.cpp index d18c82c0b..7455a0049 100644 --- a/src/lib/math/numbertheory/make_prm.cpp +++ b/src/lib/math/numbertheory/make_prm.cpp @@ -112,8 +112,11 @@ BigInt random_prime(RandomNumberGenerator& rng, { for(;;) { - size_t idx = make_uint16(rng.next_byte(), rng.next_byte()) % PRIME_TABLE_SIZE; - uint16_t small_prime = PRIMES[idx]; + // This is slightly biased, but for small primes it does not seem to matter + const uint8_t b0 = rng.next_byte(); + const uint8_t b1 = rng.next_byte(); + const size_t idx = make_uint16(b0, b1) % PRIME_TABLE_SIZE; + const uint16_t small_prime = PRIMES[idx]; if(high_bit(small_prime) == bits) return small_prime; -- cgit v1.2.3