Skip to content

Commit 523ca4b

Browse files
committed
Fix off-by-one error in SHA512_rng.
This fixes issue originally filed in scipr-lab/libsnark#24.
1 parent 166a10b commit 523ca4b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/common/rng.tcc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ FieldT SHA512_rng(const uint64_t idx)
4444
}
4545

4646
/* clear all bits higher than MSB of modulus */
47-
size_t bitno = GMP_NUMB_BITS * FieldT::num_limbs;
47+
size_t bitno = GMP_NUMB_BITS * FieldT::num_limbs - 1;
48+
49+
/* mod is non-zero so the loop will always terminate */
4850
while (FieldT::mod.test_bit(bitno) == false)
4951
{
5052
const std::size_t part = bitno/GMP_NUMB_BITS;

0 commit comments

Comments
 (0)