internal/bigmod: optimize SetOverflowedBytes #273

This commit is contained in:
Sun Yimin 2024-11-20 18:15:32 +08:00 committed by GitHub
parent 9624b43515
commit 4f7504c6b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -196,8 +196,9 @@ func (x *Nat) SetOverflowedBytes(b []byte, m *Modulus) *Nat {
one := NewNat().resetFor(m)
one.limbs[0] = 1
x.resetToBytes(b)
x = NewNat().modNat(x, mMinusOne)
return x.Add(one, m)
x = NewNat().modNat(x, mMinusOne) // x = x mod (m-1)
x.add(one) // we can safely add 1, no need to check overflow
return x
}
// bigEndianUint returns the contents of buf interpreted as a