diff --git a/mod.go b/mod.go index 7126a36..f26d627 100644 --- a/mod.go +++ b/mod.go @@ -330,8 +330,8 @@ func Reciprocal(m *Int) (mu [5]uint64) { // reduce4 computes the least non-negative residue of x modulo m // -// requires a four-word modulus (m[3] > 1) and its inverse (mu) -func reduce4(x [8]uint64, m *Int, mu [5]uint64) (z Int) { +// requires a four-word modulus (m[3] != 0) and its inverse (mu) +func (z *Int) reduce4(x *[8]uint64, m *Int, mu *[5]uint64) *Int { // NB: Most variable names in the comments match the pseudocode for // Barrett reduction in the Handbook of Applied Cryptography. diff --git a/uint256.go b/uint256.go index 1f4de33..904bf4d 100644 --- a/uint256.go +++ b/uint256.go @@ -679,8 +679,7 @@ func (z *Int) MulModWithReciprocal(x, y, m *Int, mu *[5]uint64) *Int { umul(x, y, &p) if m[3] != 0 { - r := reduce4(p, m, *mu) - return z.Set(&r) + return z.reduce4(&p, m, mu) } var ( @@ -713,8 +712,7 @@ func (z *Int) MulMod(x, y, m *Int) *Int { if m[3] != 0 { mu := Reciprocal(m) - r := reduce4(p, m, mu) - return z.Set(&r) + return z.reduce4(&p, m, &mu) } var (