@@ -1000,6 +1000,7 @@ mod tests {
10001000 use elliptic_curve:: Field ;
10011001 use hex_literal:: hex;
10021002 use rand_core:: TryRngCore ;
1003+ use sha3:: Shake256 ;
10031004
10041005 fn hex_to_field ( hex : & ' static str ) -> FieldElement {
10051006 assert_eq ! ( hex. len( ) , 56 * 2 ) ;
@@ -1160,7 +1161,7 @@ mod tests {
11601161 ] ;
11611162
11621163 for ( msg, x, y) in MSGS {
1163- let p = Ed448 :: hash_from_bytes :: < ExpandMsgXof < sha3 :: Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
1164+ let p = Ed448 :: hash_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
11641165 assert_eq ! ( p. is_on_curve( ) . unwrap_u8( ) , 1u8 ) ;
11651166 let p = p. to_affine ( ) ;
11661167 let mut xx = [ 0u8 ; 56 ] ;
@@ -1197,8 +1198,7 @@ mod tests {
11971198 ] ;
11981199
11991200 for ( msg, x, y) in MSGS {
1200- let p =
1201- Ed448 :: encode_from_bytes :: < ExpandMsgXof < sha3:: Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
1201+ let p = Ed448 :: encode_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
12021202 assert_eq ! ( p. is_on_curve( ) . unwrap_u8( ) , 1u8 ) ;
12031203 let p = p. to_affine ( ) ;
12041204 let mut xx = [ 0u8 ; 56 ] ;
@@ -1209,6 +1209,24 @@ mod tests {
12091209 yy. reverse ( ) ;
12101210 assert_eq ! ( p. x. to_bytes( ) , xx) ;
12111211 assert_eq ! ( p. y. to_bytes( ) , yy) ;
1212+
1213+ // Test Montgomery to Edwards conversion.
1214+ // See https://github.com/cfrg/draft-irtf-cfrg-hash-to-curve/blob/664b13592116cecc9e52fb192dcde0ade36f904e/poc/ell2_opt_3mod4.sage#L243-L245.
1215+ let conv_p =
1216+ ProjectiveMontgomeryXpoint :: encode :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] )
1217+ . to_affine ( ) ;
1218+ let conv_p1 = conv_p. to_edwards ( Choice :: from ( 0 ) ) ;
1219+ let conv_p2 = conv_p. to_edwards ( Choice :: from ( 1 ) ) ;
1220+ assert ! ( conv_p1. x == p. x || conv_p2. x == p. x) ;
1221+ assert ! ( conv_p1. y == p. y || conv_p2. y == p. y) ;
1222+
1223+ let conv_p = AffinePoint :: from (
1224+ Curve448 :: encode_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] )
1225+ . unwrap ( )
1226+ . to_affine ( ) ,
1227+ ) ;
1228+ assert_eq ! ( conv_p. x, p. x) ;
1229+ assert_eq ! ( conv_p. y, p. y) ;
12121230 }
12131231 }
12141232
0 commit comments