Skip to content

Commit

Permalink
Remove sgn0 method
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Jan 14, 2022
1 parent be9b41f commit 8a44a3f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 20 deletions.
8 changes: 0 additions & 8 deletions k256/src/arithmetic/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions k256/src/arithmetic/hash2curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl FromOkm for FieldElement {

impl Sgn0 for FieldElement {
fn sgn0(&self) -> Choice {
FieldElement::sgn0(self)
self.is_odd()
}
}

Expand Down Expand Up @@ -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)
}
}
Expand Down
11 changes: 2 additions & 9 deletions p256/src/arithmetic/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<FieldElement> for FieldElement {
Expand Down
2 changes: 1 addition & 1 deletion p256/src/arithmetic/hash2curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl FromOkm for FieldElement {

impl Sgn0 for FieldElement {
fn sgn0(&self) -> Choice {
FieldElement::sgn0(self)
self.is_odd()
}
}

Expand Down

0 comments on commit 8a44a3f

Please sign in to comment.