Skip to content

Commit 70b3a75

Browse files
committed
Test Montgomery -> Edwards through hash2curve
1 parent 55df86c commit 70b3a75

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

ed448-goldilocks/src/edwards/extended.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ mod tests {
809809
use proptest::prelude::any;
810810
use proptest::proptest;
811811
use rand_core::{OsRng, TryRngCore};
812+
use sha3::Shake256;
812813

813814
fn hex_to_field(hex: &'static str) -> FieldElement {
814815
assert_eq!(hex.len(), 56 * 2);
@@ -969,9 +970,7 @@ mod tests {
969970
];
970971

971972
for (msg, x, y) in MSGS {
972-
let p =
973-
hash2curve::hash_from_bytes::<Ed448, ExpandMsgXof<sha3::Shake256>>(&[msg], &[DST])
974-
.unwrap();
973+
let p = Ed448::hash_from_bytes(msg, DST).unwrap();
975974
assert_eq!(p.is_on_curve().unwrap_u8(), 1u8);
976975
let p = p.to_affine();
977976
let mut xx = [0u8; 56];
@@ -1008,11 +1007,7 @@ mod tests {
10081007
];
10091008

10101009
for (msg, x, y) in MSGS {
1011-
let p = hash2curve::encode_from_bytes::<Ed448, ExpandMsgXof<sha3::Shake256>>(
1012-
&[msg],
1013-
&[DST],
1014-
)
1015-
.unwrap();
1010+
let p = Ed448::encode_from_bytes(msg, DST).unwrap();
10161011
assert_eq!(p.is_on_curve().unwrap_u8(), 1u8);
10171012
let p = p.to_affine();
10181013
let mut xx = [0u8; 56];
@@ -1023,6 +1018,22 @@ mod tests {
10231018
yy.reverse();
10241019
assert_eq!(p.x.to_bytes(), xx);
10251020
assert_eq!(p.y.to_bytes(), yy);
1021+
1022+
// Test Montgomery to Edwards conversion.
1023+
// See https://github.com/cfrg/draft-irtf-cfrg-hash-to-curve/blob/664b13592116cecc9e52fb192dcde0ade36f904e/poc/ell2_opt_3mod4.sage#L243-L245.
1024+
let conv_p =
1025+
ProjectiveMontgomeryXpoint::encode::<ExpandMsgXof<Shake256>>(&[msg], &[DST])
1026+
.unwrap()
1027+
.to_affine();
1028+
let conv_p1 = conv_p.to_edwards(Choice::from(0));
1029+
let conv_p2 = conv_p.to_edwards(Choice::from(1));
1030+
assert!(conv_p1.x == p.x || conv_p2.x == p.x);
1031+
assert!(conv_p1.y == p.y || conv_p2.y == p.y);
1032+
1033+
let conv_p =
1034+
AffinePoint::from(Curve448::encode_from_bytes(msg, DST).unwrap().to_affine());
1035+
assert_eq!(conv_p.x, p.x);
1036+
assert_eq!(conv_p.y, p.y);
10261037
}
10271038
}
10281039

0 commit comments

Comments
 (0)