@@ -984,6 +984,7 @@ mod tests {
984
984
use elliptic_curve:: Field ;
985
985
use hex_literal:: hex;
986
986
use rand_core:: TryRngCore ;
987
+ use sha3:: Shake256 ;
987
988
988
989
fn hex_to_field ( hex : & ' static str ) -> FieldElement {
989
990
assert_eq ! ( hex. len( ) , 56 * 2 ) ;
@@ -1144,7 +1145,7 @@ mod tests {
1144
1145
] ;
1145
1146
1146
1147
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 ( ) ;
1148
1149
assert_eq ! ( p. is_on_curve( ) . unwrap_u8( ) , 1u8 ) ;
1149
1150
let p = p. to_affine ( ) ;
1150
1151
let mut xx = [ 0u8 ; 56 ] ;
@@ -1181,8 +1182,7 @@ mod tests {
1181
1182
] ;
1182
1183
1183
1184
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 ( ) ;
1186
1186
assert_eq ! ( p. is_on_curve( ) . unwrap_u8( ) , 1u8 ) ;
1187
1187
let p = p. to_affine ( ) ;
1188
1188
let mut xx = [ 0u8 ; 56 ] ;
@@ -1193,6 +1193,24 @@ mod tests {
1193
1193
yy. reverse ( ) ;
1194
1194
assert_eq ! ( p. x. to_bytes( ) , xx) ;
1195
1195
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) ;
1196
1214
}
1197
1215
}
1198
1216
0 commit comments