@@ -1010,6 +1010,7 @@ mod tests {
1010
1010
use elliptic_curve:: Field ;
1011
1011
use hex_literal:: hex;
1012
1012
use rand_core:: TryRngCore ;
1013
+ use sha3:: Shake256 ;
1013
1014
1014
1015
fn hex_to_field ( hex : & ' static str ) -> FieldElement {
1015
1016
assert_eq ! ( hex. len( ) , 56 * 2 ) ;
@@ -1170,7 +1171,7 @@ mod tests {
1170
1171
] ;
1171
1172
1172
1173
for ( msg, x, y) in MSGS {
1173
- let p = Ed448 :: hash_from_bytes :: < ExpandMsgXof < sha3 :: Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
1174
+ let p = Ed448 :: hash_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
1174
1175
assert_eq ! ( p. is_on_curve( ) . unwrap_u8( ) , 1u8 ) ;
1175
1176
let p = p. to_affine ( ) ;
1176
1177
let mut xx = [ 0u8 ; 56 ] ;
@@ -1207,8 +1208,7 @@ mod tests {
1207
1208
] ;
1208
1209
1209
1210
for ( msg, x, y) in MSGS {
1210
- let p =
1211
- Ed448 :: encode_from_bytes :: < ExpandMsgXof < sha3:: Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
1211
+ let p = Ed448 :: encode_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
1212
1212
assert_eq ! ( p. is_on_curve( ) . unwrap_u8( ) , 1u8 ) ;
1213
1213
let p = p. to_affine ( ) ;
1214
1214
let mut xx = [ 0u8 ; 56 ] ;
@@ -1219,6 +1219,24 @@ mod tests {
1219
1219
yy. reverse ( ) ;
1220
1220
assert_eq ! ( p. x. to_bytes( ) , xx) ;
1221
1221
assert_eq ! ( p. y. to_bytes( ) , yy) ;
1222
+
1223
+ // Test Montgomery to Edwards conversion.
1224
+ // See https://github.com/cfrg/draft-irtf-cfrg-hash-to-curve/blob/664b13592116cecc9e52fb192dcde0ade36f904e/poc/ell2_opt_3mod4.sage#L243-L245.
1225
+ let conv_p =
1226
+ ProjectiveMontgomeryXpoint :: encode :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] )
1227
+ . to_affine ( ) ;
1228
+ let conv_p1 = conv_p. to_edwards ( Choice :: from ( 0 ) ) ;
1229
+ let conv_p2 = conv_p. to_edwards ( Choice :: from ( 1 ) ) ;
1230
+ assert ! ( conv_p1. x == p. x || conv_p2. x == p. x) ;
1231
+ assert ! ( conv_p1. y == p. y || conv_p2. y == p. y) ;
1232
+
1233
+ let conv_p = AffinePoint :: from (
1234
+ Curve448 :: encode_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] )
1235
+ . unwrap ( )
1236
+ . to_affine ( ) ,
1237
+ ) ;
1238
+ assert_eq ! ( conv_p. x, p. x) ;
1239
+ assert_eq ! ( conv_p. y, p. y) ;
1222
1240
}
1223
1241
}
1224
1242
0 commit comments