From 852ae10ffb11c2b955dc323f5b1d6b777c8d29fc Mon Sep 17 00:00:00 2001 From: jmwample <8297368+jmwample@users.noreply.github.com> Date: Tue, 25 Jun 2024 10:47:30 -0600 Subject: [PATCH] fixing negations for fiat and gt impl --- .../src/backend/serial/fiat_u64/field.rs | 3 --- curve25519-elligator2/src/elligator2.rs | 10 +++++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/curve25519-elligator2/src/backend/serial/fiat_u64/field.rs b/curve25519-elligator2/src/backend/serial/fiat_u64/field.rs index ff88f437..05728c06 100644 --- a/curve25519-elligator2/src/backend/serial/fiat_u64/field.rs +++ b/curve25519-elligator2/src/backend/serial/fiat_u64/field.rs @@ -263,9 +263,6 @@ impl FieldElement51 { /// Returns 1 if self is greater than the other and 0 otherwise // implementation based on C libgmp -> mpn_sub_n pub(crate) fn gt(&self, other: &Self) -> Choice { - let mut result_loose = fiat_25519_loose_field_element([0; 5]); - fiat_25519_sub(&mut result_loose, &self.0, &rhs.0); - let mut _ul = 0_u64; let mut _vl = 0_u64; let mut _rl = 0_u64; diff --git a/curve25519-elligator2/src/elligator2.rs b/curve25519-elligator2/src/elligator2.rs index 3905aba9..d1eba6c5 100644 --- a/curve25519-elligator2/src/elligator2.rs +++ b/curve25519-elligator2/src/elligator2.rs @@ -129,6 +129,8 @@ use crate::field::FieldElement; use crate::montgomery::MontgomeryPoint; use crate::EdwardsPoint; +use core::ops::Neg; + use cfg_if::cfg_if; use subtle::{ Choice, ConditionallyNegatable, ConditionallySelectable, ConstantTimeEq, ConstantTimeGreater, @@ -504,8 +506,7 @@ pub(crate) fn point_to_representative( // a := point let a = &FieldElement::from_bytes(&point.0); - let mut a_neg = *a; - a_neg.negate(); + let a_neg = -&*a; let is_encodable = is_encodable(a); @@ -541,7 +542,7 @@ fn is_encodable(u: &FieldElement) -> Choice { let b2 = &(&b0.square().square().square() * &b0.square().square()) * &b0.square(); // (u + A)^14 let mut chi = &(&c.square().square() * &u.square()) * &b2; // chi = -c^4 * u^2 * (u + A)^14 - chi.negate(); + chi = -χ let chi_bytes = chi.as_bytes(); @@ -630,8 +631,7 @@ fn map_to_curve_parts( ) -> (FieldElement, FieldElement, FieldElement, FieldElement) { let zero = FieldElement::ZERO; let one = FieldElement::ONE; - let mut minus_one = FieldElement::ONE; - minus_one.negate(); + let minus_one = -&FieldElement::ONE; // Exceptional case 2u^2 == -1 let mut tv1 = r.square2();