From 81a1f71a88f98907293c289829e42c7abd644646 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 22 Aug 2024 19:30:04 +0200 Subject: [PATCH] refactor: use explicit wrapping addition in Fp*::mul_assign Signed-off-by: ljedrz --- fields/src/fp_256.rs | 8 ++++---- fields/src/fp_384.rs | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fields/src/fp_256.rs b/fields/src/fp_256.rs index 80f69a635b..bb70c0cc4f 100644 --- a/fields/src/fp_256.rs +++ b/fields/src/fp_256.rs @@ -767,7 +767,7 @@ impl<'a, P: Fp256Parameters> MulAssign<&'a Self> for Fp256

{ r[3] = fa::mac_with_carry(r[3], (self.0).0[3], (other.0).0[0], &mut carry1); r[2] = fa::mac_with_carry(r[3], k, P::MODULUS.0[3], &mut carry2); - r[3] = carry1 + carry2; + r[3] = carry1.wrapping_add(carry2); // Iteration 1. r[0] = fa::mac(r[0], (self.0).0[0], (other.0).0[1], &mut carry1); @@ -781,7 +781,7 @@ impl<'a, P: Fp256Parameters> MulAssign<&'a Self> for Fp256

{ r[3] = fa::mac_with_carry(r[3], (self.0).0[3], (other.0).0[1], &mut carry1); r[2] = fa::mac_with_carry(r[3], k, P::MODULUS.0[3], &mut carry2); - r[3] = carry1 + carry2; + r[3] = carry1.wrapping_add(carry2); // Iteration 2. r[0] = fa::mac(r[0], (self.0).0[0], (other.0).0[2], &mut carry1); @@ -795,7 +795,7 @@ impl<'a, P: Fp256Parameters> MulAssign<&'a Self> for Fp256

{ r[3] = fa::mac_with_carry(r[3], (self.0).0[3], (other.0).0[2], &mut carry1); r[2] = fa::mac_with_carry(r[3], k, P::MODULUS.0[3], &mut carry2); - r[3] = carry1 + carry2; + r[3] = carry1.wrapping_add(carry2); // Iteration 3. r[0] = fa::mac(r[0], (self.0).0[0], (other.0).0[3], &mut carry1); @@ -809,7 +809,7 @@ impl<'a, P: Fp256Parameters> MulAssign<&'a Self> for Fp256

{ r[3] = fa::mac_with_carry(r[3], (self.0).0[3], (other.0).0[3], &mut carry1); r[2] = fa::mac_with_carry(r[3], k, P::MODULUS.0[3], &mut carry2); - r[3] = carry1 + carry2; + r[3] = carry1.wrapping_add(carry2); (self.0).0 = r; self.reduce(); diff --git a/fields/src/fp_384.rs b/fields/src/fp_384.rs index 1e60a18c2f..7f82ef6e53 100644 --- a/fields/src/fp_384.rs +++ b/fields/src/fp_384.rs @@ -790,7 +790,7 @@ impl<'a, P: Fp384Parameters> MulAssign<&'a Self> for Fp384

{ r[5] = fa::mac_with_carry(r[5], (self.0).0[5], (other.0).0[0], &mut carry1); r[4] = fa::mac_with_carry(r[5], k, P::MODULUS.0[5], &mut carry2); - r[5] = carry1 + carry2; + r[5] = carry1.wrapping_add(carry2); // Iteration 1. r[0] = fa::mac(r[0], (self.0).0[0], (other.0).0[1], &mut carry1); @@ -810,7 +810,7 @@ impl<'a, P: Fp384Parameters> MulAssign<&'a Self> for Fp384

{ r[5] = fa::mac_with_carry(r[5], (self.0).0[5], (other.0).0[1], &mut carry1); r[4] = fa::mac_with_carry(r[5], k, P::MODULUS.0[5], &mut carry2); - r[5] = carry1 + carry2; + r[5] = carry1.wrapping_add(carry2); // Iteration 2. r[0] = fa::mac(r[0], (self.0).0[0], (other.0).0[2], &mut carry1); @@ -830,7 +830,7 @@ impl<'a, P: Fp384Parameters> MulAssign<&'a Self> for Fp384

{ r[5] = fa::mac_with_carry(r[5], (self.0).0[5], (other.0).0[2], &mut carry1); r[4] = fa::mac_with_carry(r[5], k, P::MODULUS.0[5], &mut carry2); - r[5] = carry1 + carry2; + r[5] = carry1.wrapping_add(carry2); // Iteration 3. r[0] = fa::mac(r[0], (self.0).0[0], (other.0).0[3], &mut carry1); @@ -850,7 +850,7 @@ impl<'a, P: Fp384Parameters> MulAssign<&'a Self> for Fp384

{ r[5] = fa::mac_with_carry(r[5], (self.0).0[5], (other.0).0[3], &mut carry1); r[4] = fa::mac_with_carry(r[5], k, P::MODULUS.0[5], &mut carry2); - r[5] = carry1 + carry2; + r[5] = carry1.wrapping_add(carry2); // Iteration 4. r[0] = fa::mac(r[0], (self.0).0[0], (other.0).0[4], &mut carry1); @@ -870,7 +870,7 @@ impl<'a, P: Fp384Parameters> MulAssign<&'a Self> for Fp384

{ r[5] = fa::mac_with_carry(r[5], (self.0).0[5], (other.0).0[4], &mut carry1); r[4] = fa::mac_with_carry(r[5], k, P::MODULUS.0[5], &mut carry2); - r[5] = carry1 + carry2; + r[5] = carry1.wrapping_add(carry2); // Iteration 5. r[0] = fa::mac(r[0], (self.0).0[0], (other.0).0[5], &mut carry1); @@ -890,7 +890,7 @@ impl<'a, P: Fp384Parameters> MulAssign<&'a Self> for Fp384

{ r[5] = fa::mac_with_carry(r[5], (self.0).0[5], (other.0).0[5], &mut carry1); r[4] = fa::mac_with_carry(r[5], k, P::MODULUS.0[5], &mut carry2); - r[5] = carry1 + carry2; + r[5] = carry1.wrapping_add(carry2); (self.0).0 = r; self.reduce();