@@ -1000,6 +1000,7 @@ mod tests {
1000
1000
use elliptic_curve:: Field ;
1001
1001
use hex_literal:: hex;
1002
1002
use rand_core:: TryRngCore ;
1003
+ use sha3:: Shake256 ;
1003
1004
1004
1005
fn hex_to_field ( hex : & ' static str ) -> FieldElement {
1005
1006
assert_eq ! ( hex. len( ) , 56 * 2 ) ;
@@ -1160,7 +1161,7 @@ mod tests {
1160
1161
] ;
1161
1162
1162
1163
for ( msg, x, y) in MSGS {
1163
- let p = Ed448 :: hash_from_bytes :: < ExpandMsgXof < sha3 :: Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
1164
+ let p = Ed448 :: hash_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
1164
1165
assert_eq ! ( p. is_on_curve( ) . unwrap_u8( ) , 1u8 ) ;
1165
1166
let p = p. to_affine ( ) ;
1166
1167
let mut xx = [ 0u8 ; 56 ] ;
@@ -1197,8 +1198,7 @@ mod tests {
1197
1198
] ;
1198
1199
1199
1200
for ( msg, x, y) in MSGS {
1200
- let p =
1201
- Ed448 :: encode_from_bytes :: < ExpandMsgXof < sha3:: Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
1201
+ let p = Ed448 :: encode_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] ) . unwrap ( ) ;
1202
1202
assert_eq ! ( p. is_on_curve( ) . unwrap_u8( ) , 1u8 ) ;
1203
1203
let p = p. to_affine ( ) ;
1204
1204
let mut xx = [ 0u8 ; 56 ] ;
@@ -1209,6 +1209,24 @@ mod tests {
1209
1209
yy. reverse ( ) ;
1210
1210
assert_eq ! ( p. x. to_bytes( ) , xx) ;
1211
1211
assert_eq ! ( p. y. to_bytes( ) , yy) ;
1212
+
1213
+ // Test Montgomery to Edwards conversion.
1214
+ // See https://github.com/cfrg/draft-irtf-cfrg-hash-to-curve/blob/664b13592116cecc9e52fb192dcde0ade36f904e/poc/ell2_opt_3mod4.sage#L243-L245.
1215
+ let conv_p =
1216
+ ProjectiveMontgomeryXpoint :: encode :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] )
1217
+ . to_affine ( ) ;
1218
+ let conv_p1 = conv_p. to_edwards ( Choice :: from ( 0 ) ) ;
1219
+ let conv_p2 = conv_p. to_edwards ( Choice :: from ( 1 ) ) ;
1220
+ assert ! ( conv_p1. x == p. x || conv_p2. x == p. x) ;
1221
+ assert ! ( conv_p1. y == p. y || conv_p2. y == p. y) ;
1222
+
1223
+ let conv_p = AffinePoint :: from (
1224
+ Curve448 :: encode_from_bytes :: < ExpandMsgXof < Shake256 > > ( & [ msg] , & [ DST ] )
1225
+ . unwrap ( )
1226
+ . to_affine ( ) ,
1227
+ ) ;
1228
+ assert_eq ! ( conv_p. x, p. x) ;
1229
+ assert_eq ! ( conv_p. y, p. y) ;
1212
1230
}
1213
1231
}
1214
1232
0 commit comments