diff options
author | Jack Lloyd <[email protected]> | 2015-08-08 16:40:41 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2015-08-08 16:40:41 -0400 |
commit | bd562dd6d4ac89a5ab615c8811fb3aef8da703ad (patch) | |
tree | 6345e561cd6bfa55d95ff4bd201ba10aff85fdc8 /src | |
parent | fdb6a160032618be278f138715e557e76e50dde0 (diff) |
Restrict input values to NIST reductions to defined range
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/test_bigint.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp index dabe5746e..7bac56bc7 100644 --- a/src/tests/test_bigint.cpp +++ b/src/tests/test_bigint.cpp @@ -88,7 +88,7 @@ BOTAN_TEST_CASE(bigint_to_u32bit, "BigInt to_u32bit", { } }); -BigInt test_integer(RandomNumberGenerator& rng, size_t bits) +BigInt test_integer(RandomNumberGenerator& rng, size_t bits, BigInt max) { /* Produces integers with long runs of ones and zeros, for testing for @@ -119,7 +119,16 @@ BigInt test_integer(RandomNumberGenerator& rng, size_t bits) active = !active; } - //std::cout << std::hex << x << "\n"; + if(max > 0) + { + while(x >= max) + { + const size_t b = x.bits() - 1; + BOTAN_ASSERT(x.get_bit(b) == true, "Set"); + x.clear_bit(b); + } + } + return x; } @@ -131,6 +140,7 @@ void nist_redc_test(Test_State& _test, std::function<void (BigInt&, secure_vector<word>&)> redc_fn) { auto& rng = test_rng(); + const BigInt p2 = p*p; const size_t trials = 100; const size_t p_bits = p.bits(); @@ -139,7 +149,7 @@ void nist_redc_test(Test_State& _test, for(size_t i = 0; i != trials; ++i) { - const BigInt x = test_integer(rng, 2*p_bits); + const BigInt x = test_integer(rng, 2*p_bits, p2); // TODO: time and report all three approaches const BigInt v1 = x % p; |