Skip to content

Commit

Permalink
fixing negations for fiat and gt impl
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwample committed Jun 25, 2024
1 parent e6cdbff commit 852ae10
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
3 changes: 0 additions & 3 deletions curve25519-elligator2/src/backend/serial/fiat_u64/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions curve25519-elligator2/src/elligator2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

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

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

0 comments on commit 852ae10

Please sign in to comment.