diff --git a/k256/src/arithmetic/field.rs b/k256/src/arithmetic/field.rs index 5a4ef2b4f..c2ebc87e8 100644 --- a/k256/src/arithmetic/field.rs +++ b/k256/src/arithmetic/field.rs @@ -265,14 +265,6 @@ impl FieldElement { pub fn modulus_as_biguint() -> BigUint { Self::one().negate(1).to_biguint().unwrap() + 1.to_biguint().unwrap() } - - /// Return the parity of the field - /// 1 == negative - /// 0 == non-negative - pub fn sgn0(&self) -> Choice { - let bytes = self.to_bytes(); - (bytes[31] & 1).into() - } } impl ConditionallySelectable for FieldElement { diff --git a/k256/src/arithmetic/hash2curve.rs b/k256/src/arithmetic/hash2curve.rs index 2cfb92735..6ff837c35 100644 --- a/k256/src/arithmetic/hash2curve.rs +++ b/k256/src/arithmetic/hash2curve.rs @@ -46,7 +46,7 @@ impl FromOkm for FieldElement { impl Sgn0 for FieldElement { fn sgn0(&self) -> Choice { - FieldElement::sgn0(self) + self.is_odd() } } @@ -126,7 +126,7 @@ impl OsswuMap for FieldElement { // if e2, y = y1, else y = y2 let mut y = Self::conditional_select(&y2, &y1, e2); - y.conditional_assign(&-y, self.sgn0() ^ y.sgn0()); + y.conditional_assign(&-y, self.normalize().sgn0() ^ y.normalize().sgn0()); (x, y) } } diff --git a/p256/src/arithmetic/field.rs b/p256/src/arithmetic/field.rs index d95e5ff24..25a18cb4d 100644 --- a/p256/src/arithmetic/field.rs +++ b/p256/src/arithmetic/field.rs @@ -194,7 +194,8 @@ impl FieldElement { /// /// If odd, return `Choice(1)`. Otherwise, return `Choice(0)`. pub fn is_odd(&self) -> Choice { - self.sgn0() + let bytes = self.to_bytes(); + (bytes[31] & 1).into() } /// Returns self + rhs mod p @@ -465,14 +466,6 @@ impl FieldElement { (&sqrt * &sqrt).ct_eq(self), // Only return Some if it's the square root. ) } - - /// Return the parity of the field - /// 1 == negative - /// 0 == non-negative - pub fn sgn0(&self) -> Choice { - let bytes = self.to_bytes(); - (bytes[31] & 1).into() - } } impl Add for FieldElement { diff --git a/p256/src/arithmetic/hash2curve.rs b/p256/src/arithmetic/hash2curve.rs index e07f34c15..819b043a2 100644 --- a/p256/src/arithmetic/hash2curve.rs +++ b/p256/src/arithmetic/hash2curve.rs @@ -48,7 +48,7 @@ impl FromOkm for FieldElement { impl Sgn0 for FieldElement { fn sgn0(&self) -> Choice { - FieldElement::sgn0(self) + self.is_odd() } }