Skip to content

Commit ebfa4c9

Browse files
authored
ed448-goldilocks: remove ability to construct invalid Scalars (#1281)
1 parent 67756d7 commit ebfa4c9

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

ed448-goldilocks/src/field/scalar.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,6 @@ impl Scalar {
698698
bits
699699
}
700700

701-
/// Construct a `Scalar` from a little-endian byte representation.
702-
pub fn from_bytes(bytes: &[u8; 56]) -> Scalar {
703-
Self(U448::from_le_slice(bytes))
704-
}
705-
706701
/// Convert this `Scalar` to a little-endian byte array.
707702
pub fn to_bytes(&self) -> [u8; 56] {
708703
let bytes = self.0.to_le_bytes();
@@ -780,7 +775,7 @@ impl Scalar {
780775
// Check that the 10 high bits are not set
781776
let is_valid = is_zero(bytes[56]) | is_zero(bytes[55] >> 6);
782777
let bytes: [u8; 56] = core::array::from_fn(|i| bytes[i]);
783-
let candidate = Scalar::from_bytes(&bytes);
778+
let candidate = Scalar(U448::from_le_slice(&bytes));
784779

785780
// underflow means candidate < ORDER, thus canonical
786781
let (_, underflow) = candidate.0.borrowing_sub(&ORDER, Limb::ZERO);
@@ -971,7 +966,7 @@ mod test {
971966
let scalar = Scalar(U448::from_be_hex(
972967
"0d79f6e375d3395ed9a6c4c3c49a1433fd7c58aa38363f74e9ab2c22a22347d79988f8e01e8a309f862a9f1052fcd042b9b1ed7115598f62",
973968
));
974-
let got = Scalar::from_bytes(&scalar.to_bytes());
969+
let got = Scalar::from_canonical_bytes(&scalar.into()).unwrap();
975970
assert_eq!(scalar, got)
976971
}
977972
#[test]

0 commit comments

Comments
 (0)