diff options
author | Jack Lloyd <[email protected]> | 2016-03-15 20:13:54 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-03-15 20:13:54 -0400 |
commit | 539170d9acbe73f9e3b6a17bec41dfeb817a9fb8 (patch) | |
tree | 3fc0a247a1859eb5184dc21dd675c5a206f2fda1 /src | |
parent | 8bbc2a99ddce2ef8a0ab0b8114ba0edf378d4f1a (diff) |
Fix off by one in ressol
Could attempt to allocate (size_t)-1 words with predicably bad_alloc
results.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/math/numbertheory/ressol.cpp | 2 | ||||
-rw-r--r-- | src/tests/data/bn/ressol.vec | 43 |
2 files changed, 44 insertions, 1 deletions
diff --git a/src/lib/math/numbertheory/ressol.cpp b/src/lib/math/numbertheory/ressol.cpp index 127dc899e..2c83cb0e0 100644 --- a/src/lib/math/numbertheory/ressol.cpp +++ b/src/lib/math/numbertheory/ressol.cpp @@ -66,7 +66,7 @@ BigInt ressol(const BigInt& a, const BigInt& p) q = mod_p.square(q); ++i; - if(i > s) + if(i >= s) { return -BigInt(1); } diff --git a/src/tests/data/bn/ressol.vec b/src/tests/data/bn/ressol.vec index a16f08c42..c21c337af 100644 --- a/src/tests/data/bn/ressol.vec +++ b/src/tests/data/bn/ressol.vec @@ -16,3 +16,46 @@ Input = 20749193632488214633180774027217139706413443729200940480695355894185 Modulus = 26959946667150639794667015087019630673557916260026308143510066298881 Output = 1825097171398375765346899906888660610489759292065918530856859649959 +Input = 64 +Modulus = 85 +Output = -1 + +Input = 206 +Modulus = 153 +Output = -1 + +Input = 181 +Modulus = 217 +Output = -1 + +Input = 166 +Modulus = 85 +Output = -1 + +Input = 4225 +Modulus = 33153 +Output = -1 + +Input = 57700 +Modulus = 153 +Output = -1 + +Input = 2048 +Modulus = 31417 +Output = -1 + +Input = 65151 +Modulus = 2405 +Output = -1 + +Input = 2 +Modulus = 4369 +Output = -1 + +Input = 61508 +Modulus = 4141 +Output = -1 + +Input = 6553700 +Modulus = 33153 +Output = -1 |