Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] Use explicit wrapping addition in Fp*::mul_assign #2533

Draft
wants to merge 1 commit into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions fields/src/fp_256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ impl<'a, P: Fp256Parameters> MulAssign<&'a Self> for Fp256<P> {

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);
Expand All @@ -781,7 +781,7 @@ impl<'a, P: Fp256Parameters> MulAssign<&'a Self> for Fp256<P> {

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);
Expand All @@ -795,7 +795,7 @@ impl<'a, P: Fp256Parameters> MulAssign<&'a Self> for Fp256<P> {

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);
Expand All @@ -809,7 +809,7 @@ impl<'a, P: Fp256Parameters> MulAssign<&'a Self> for Fp256<P> {

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();
Expand Down
12 changes: 6 additions & 6 deletions fields/src/fp_384.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ impl<'a, P: Fp384Parameters> MulAssign<&'a Self> for Fp384<P> {

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);
Expand All @@ -810,7 +810,7 @@ impl<'a, P: Fp384Parameters> MulAssign<&'a Self> for Fp384<P> {

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);
Expand All @@ -830,7 +830,7 @@ impl<'a, P: Fp384Parameters> MulAssign<&'a Self> for Fp384<P> {

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);
Expand All @@ -850,7 +850,7 @@ impl<'a, P: Fp384Parameters> MulAssign<&'a Self> for Fp384<P> {

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);
Expand All @@ -870,7 +870,7 @@ impl<'a, P: Fp384Parameters> MulAssign<&'a Self> for Fp384<P> {

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);
Expand All @@ -890,7 +890,7 @@ impl<'a, P: Fp384Parameters> MulAssign<&'a Self> for Fp384<P> {

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();
Expand Down