Use SEC1 for the encoding of secq256k1 points, like secp256k1 does

This commit is contained in:
Luke Parker
2025-08-28 23:51:27 -04:00
parent beac35c119
commit 5526b8d439
6 changed files with 33 additions and 28 deletions

View File

@@ -158,16 +158,20 @@ pub fn test_encoding<G: PrimeGroup>() {
let bytes = point.to_bytes();
let mut repr = G::Repr::default();
repr.as_mut().copy_from_slice(bytes.as_ref());
let decoded = G::from_bytes(&repr).unwrap();
let decoded = G::from_bytes(&repr).expect("couldn't decode encoded point");
assert_eq!(point, decoded, "{msg} couldn't be encoded and decoded");
assert_eq!(
point,
G::from_bytes_unchecked(&repr).unwrap(),
"{msg} couldn't be encoded and decoded",
G::from_bytes_unchecked(&repr)
.expect("couldn't decode encoded point with `from_bytes_unchecked`"),
"{msg} couldn't be encoded and decoded with `from_bytes_unchecked`",
);
decoded
};
assert!(bool::from(test(G::identity(), "identity").is_identity()));
assert!(
bool::from(test(G::identity(), "identity").is_identity()),
"decoded identity was no longer the identity"
);
test(G::generator(), "generator");
test(G::generator() + G::generator(), "(generator * 2)");
}