@@ -984,6 +984,7 @@ mod tests {
984984 use elliptic_curve:: Field ;
985985 use hex_literal:: hex;
986986 use rand_core:: TryRngCore ;
987+ use sha3:: Shake256 ;
987988
988989 fn hex_to_field ( hex : & ' static str ) -> FieldElement {
989990 assert_eq ! ( hex. len( ) , 56 * 2 ) ;
@@ -1144,7 +1145,7 @@ mod tests {
11441145 ] ;
11451146
11461147 for ( msg, x, y) in MSGS {
1147- let p = Ed448 :: hash_from_bytes :: < ExpandMsgXof < sha3 :: Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
1148+ let p = Ed448 :: hash_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
11481149 assert_eq ! ( p. is_on_curve( ) . unwrap_u8( ) , 1u8 ) ;
11491150 let p = p. to_affine ( ) ;
11501151 let mut xx = [ 0u8 ; 56 ] ;
@@ -1181,8 +1182,7 @@ mod tests {
11811182 ] ;
11821183
11831184 for ( msg, x, y) in MSGS {
1184- let p =
1185- Ed448 :: encode_from_bytes :: < ExpandMsgXof < sha3:: Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
1185+ let p = Ed448 :: encode_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
11861186 assert_eq ! ( p. is_on_curve( ) . unwrap_u8( ) , 1u8 ) ;
11871187 let p = p. to_affine ( ) ;
11881188 let mut xx = [ 0u8 ; 56 ] ;
@@ -1193,6 +1193,24 @@ mod tests {
11931193 yy. reverse ( ) ;
11941194 assert_eq ! ( p. x. to_bytes( ) , xx) ;
11951195 assert_eq ! ( p. y. to_bytes( ) , yy) ;
1196+
1197+ // Test Montgomery to Edwards conversion.
1198+ // See https://github.com/cfrg/draft-irtf-cfrg-hash-to-curve/blob/664b13592116cecc9e52fb192dcde0ade36f904e/poc/ell2_opt_3mod4.sage#L243-L245.
1199+ let conv_p =
1200+ ProjectiveMontgomeryXpoint :: encode :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] )
1201+ . to_affine ( ) ;
1202+ let conv_p1 = conv_p. to_edwards ( Choice :: from ( 0 ) ) ;
1203+ let conv_p2 = conv_p. to_edwards ( Choice :: from ( 1 ) ) ;
1204+ assert ! ( conv_p1. x == p. x || conv_p2. x == p. x) ;
1205+ assert ! ( conv_p1. y == p. y || conv_p2. y == p. y) ;
1206+
1207+ let conv_p = AffinePoint :: from (
1208+ Curve448 :: encode_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] )
1209+ . unwrap ( )
1210+ . to_affine ( ) ,
1211+ ) ;
1212+ assert_eq ! ( conv_p. x, p. x) ;
1213+ assert_eq ! ( conv_p. y, p. y) ;
11961214 }
11971215 }
11981216
0 commit comments