@@ -1003,6 +1003,7 @@ mod tests {
1003
1003
use elliptic_curve:: Field ;
1004
1004
use hex_literal:: hex;
1005
1005
use rand_core:: TryRngCore ;
1006
+ use sha3:: Shake256 ;
1006
1007
1007
1008
fn hex_to_field ( hex : & ' static str ) -> FieldElement {
1008
1009
assert_eq ! ( hex. len( ) , 56 * 2 ) ;
@@ -1163,7 +1164,7 @@ mod tests {
1163
1164
] ;
1164
1165
1165
1166
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 ( ) ;
1167
1168
assert_eq ! ( p. is_on_curve( ) . unwrap_u8( ) , 1u8 ) ;
1168
1169
let p = p. to_affine ( ) ;
1169
1170
let mut xx = [ 0u8 ; 56 ] ;
@@ -1200,8 +1201,7 @@ mod tests {
1200
1201
] ;
1201
1202
1202
1203
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 ( ) ;
1205
1205
assert_eq ! ( p. is_on_curve( ) . unwrap_u8( ) , 1u8 ) ;
1206
1206
let p = p. to_affine ( ) ;
1207
1207
let mut xx = [ 0u8 ; 56 ] ;
@@ -1212,6 +1212,24 @@ mod tests {
1212
1212
yy. reverse ( ) ;
1213
1213
assert_eq ! ( p. x. to_bytes( ) , xx) ;
1214
1214
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) ;
1215
1233
}
1216
1234
}
1217
1235
0 commit comments