Skip to content

Commit

Permalink
fix: Adjust LE usage for ReprFp & add test
Browse files Browse the repository at this point in the history
  • Loading branch information
CPerezz committed Oct 24, 2023
1 parent fedb948 commit b05ceae
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,10 @@ impl Default for ReprFp {
impl PrimeField for Fp {
type Repr = ReprFp;

fn from_repr(r: Self::Repr) -> CtOption<Self> {
fn from_repr(mut r: Self::Repr) -> CtOption<Self> {
// This uses little endian and so, assumes the array passed in is
// in that format.
r.0.reverse();
Self::from_bytes(&r.0)
}

Expand Down Expand Up @@ -1236,6 +1237,13 @@ fn test_lexicographic_largest() {
));
}

#[test]
fn test_repr() {
for value in [Fp::ZERO, Fp::ONE, Fp::ROOT_OF_UNITY] {
assert_eq!(Fp::from_repr(value.to_repr()).unwrap(), value);
}
}

#[cfg(feature = "zeroize")]
#[test]
fn test_zeroize() {
Expand Down

0 comments on commit b05ceae

Please sign in to comment.