From 4f7504c6b96ec8571ee01e4d833bdc5697ebf622 Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Wed, 20 Nov 2024 18:15:32 +0800 Subject: [PATCH] internal/bigmod: optimize SetOverflowedBytes #273 --- internal/bigmod/nat.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/bigmod/nat.go b/internal/bigmod/nat.go index 7ac6720..4f6b7e0 100644 --- a/internal/bigmod/nat.go +++ b/internal/bigmod/nat.go @@ -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