Use '*this >= m' for InverseMod reduction

The previous test used '*this > m', which did not capture 'm'
pull/611/head
Jeffrey Walton 2018-03-26 13:31:18 -04:00
parent 302d210ceb
commit a665e0825f
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
2 changed files with 4 additions and 4 deletions

View File

@ -4386,13 +4386,13 @@ Integer Integer::Gcd(const Integer &a, const Integer &b)
Integer Integer::InverseMod(const Integer &m) const
{
CRYPTOPP_ASSERT(m.NotNegative());
CRYPTOPP_ASSERT(m != 0);
CRYPTOPP_ASSERT(m.NotZero());
if (IsNegative())
return Modulo(m).InverseModNext(m);
// http://github.com/weidai11/cryptopp/issues/602
if (*this > m)
if (*this >= m)
return Modulo(m).InverseModNext(m);
return InverseModNext(m);
@ -4401,7 +4401,7 @@ Integer Integer::InverseMod(const Integer &m) const
Integer Integer::InverseModNext(const Integer &m) const
{
CRYPTOPP_ASSERT(m.NotNegative());
CRYPTOPP_ASSERT(m != 0);
CRYPTOPP_ASSERT(m.NotZero());
if (m.IsEven())
{

View File

@ -3374,7 +3374,7 @@ bool TestIntegerOps()
// ******************** Integer Modulo and InverseMod ********************
// http://github.com/weidai11/cryptopp/issues/602
// The bug report that uncovered the InverseMod problems
// The bug report that uncovered the InverseMod problems
{
Integer a("0x2F0500010000018000000000001C1C000000000000000A000B0000000000000000000000000000FDFFFFFF00000000");
Integer b("0x3D2F050001");