@@ -1003,6 +1003,7 @@ mod tests {
10031003 use elliptic_curve:: Field ;
10041004 use hex_literal:: hex;
10051005 use rand_core:: TryRngCore ;
1006+ use sha3:: Shake256 ;
10061007
10071008 fn hex_to_field ( hex : & ' static str ) -> FieldElement {
10081009 assert_eq ! ( hex. len( ) , 56 * 2 ) ;
@@ -1163,7 +1164,7 @@ mod tests {
11631164 ] ;
11641165
11651166 for ( msg, x, y) in MSGS {
1166- let p = Ed448 :: hash_from_bytes :: < ExpandMsgXof < sha3 :: Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
1167+ let p = Ed448 :: hash_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
11671168 assert_eq ! ( p. is_on_curve( ) . unwrap_u8( ) , 1u8 ) ;
11681169 let p = p. to_affine ( ) ;
11691170 let mut xx = [ 0u8 ; 56 ] ;
@@ -1200,8 +1201,7 @@ mod tests {
12001201 ] ;
12011202
12021203 for ( msg, x, y) in MSGS {
1203- let p =
1204- Ed448 :: encode_from_bytes :: < ExpandMsgXof < sha3:: Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
1204+ let p = Ed448 :: encode_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
12051205 assert_eq ! ( p. is_on_curve( ) . unwrap_u8( ) , 1u8 ) ;
12061206 let p = p. to_affine ( ) ;
12071207 let mut xx = [ 0u8 ; 56 ] ;
@@ -1212,6 +1212,24 @@ mod tests {
12121212 yy. reverse ( ) ;
12131213 assert_eq ! ( p. x. to_bytes( ) , xx) ;
12141214 assert_eq ! ( p. y. to_bytes( ) , yy) ;
1215+
1216+ // Test Montgomery to Edwards conversion.
1217+ // See https://github.com/cfrg/draft-irtf-cfrg-hash-to-curve/blob/664b13592116cecc9e52fb192dcde0ade36f904e/poc/ell2_opt_3mod4.sage#L243-L245.
1218+ let conv_p =
1219+ ProjectiveMontgomeryXpoint :: encode :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] )
1220+ . to_affine ( ) ;
1221+ let conv_p1 = conv_p. to_edwards ( Choice :: from ( 0 ) ) ;
1222+ let conv_p2 = conv_p. to_edwards ( Choice :: from ( 1 ) ) ;
1223+ assert ! ( conv_p1. x == p. x || conv_p2. x == p. x) ;
1224+ assert ! ( conv_p1. y == p. y || conv_p2. y == p. y) ;
1225+
1226+ let conv_p = AffinePoint :: from (
1227+ Curve448 :: encode_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] )
1228+ . unwrap ( )
1229+ . to_affine ( ) ,
1230+ ) ;
1231+ assert_eq ! ( conv_p. x, p. x) ;
1232+ assert_eq ! ( conv_p. y, p. y) ;
12151233 }
12161234 }
12171235
0 commit comments