File tree 2 files changed +8
-9
lines changed
fastcrypto/src/groups/bn254
2 files changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -63,21 +63,18 @@ impl groups::Scalar for Scalar {
63
63
64
64
impl ToFromByteArray < SCALAR_LENGTH > for Scalar {
65
65
fn from_byte_array ( bytes : & [ u8 ; SCALAR_LENGTH ] ) -> Result < Self , FastCryptoError > {
66
- // Arkworks uses little-endian byte order for serialization, but we use big-endian.
67
- let mut reversed = * bytes;
68
- reversed. reverse ( ) ;
69
- Fr :: deserialize_compressed ( reversed. as_slice ( ) )
66
+ // Note that arkworks uses little-endian byte order for serialization here.
67
+ Fr :: deserialize_compressed ( bytes. as_slice ( ) )
70
68
. map_err ( |_| FastCryptoError :: InvalidInput )
71
69
. map ( Scalar )
72
70
}
73
71
74
72
fn to_byte_array ( & self ) -> [ u8 ; SCALAR_LENGTH ] {
73
+ // Note that arkworks uses little-endian byte order for serialization here.
75
74
let mut bytes = [ 0u8 ; SCALAR_LENGTH ] ;
76
75
self . 0
77
76
. serialize_compressed ( bytes. as_mut_slice ( ) )
78
77
. expect ( "Never fails" ) ;
79
- // Arkworks uses little-endian byte order for serialization, but we use big-endian.
80
- bytes. reverse ( ) ;
81
78
bytes
82
79
}
83
80
}
Original file line number Diff line number Diff line change @@ -184,7 +184,7 @@ fn test_serde_and_regression() {
184
184
verify_serialization (
185
185
& s1,
186
186
Some (
187
- hex:: decode ( "0000000000000000000000000000000000000000000000000000000000000001 " )
187
+ hex:: decode ( "0100000000000000000000000000000000000000000000000000000000000000 " )
188
188
. unwrap ( )
189
189
. as_slice ( ) ,
190
190
) ,
@@ -225,13 +225,15 @@ fn test_serialization_scalar() {
225
225
assert_eq ! ( Scalar :: from_byte_array( & bytes) . unwrap( ) , Scalar :: zero( ) ) ;
226
226
227
227
// Scalar::from_byte_array should not accept the order or above it.
228
- let order =
228
+ let mut order =
229
229
hex:: decode ( "30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001" ) . unwrap ( ) ;
230
+ order. reverse ( ) ; // Little-endian
230
231
assert ! ( Scalar :: from_byte_array( <& [ u8 ; 32 ] >:: try_from( order. as_slice( ) ) . unwrap( ) ) . is_err( ) ) ;
231
232
232
233
// Scalar::from_byte_array should accept the order - 1.
233
- let order_minus_one =
234
+ let mut order_minus_one =
234
235
hex:: decode ( "30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000" ) . unwrap ( ) ;
236
+ order_minus_one. reverse ( ) ; // Little-endian
235
237
assert_eq ! (
236
238
Scalar :: from_byte_array( <& [ u8 ; 32 ] >:: try_from( order_minus_one. as_slice( ) ) . unwrap( ) )
237
239
. unwrap( ) ,
You can’t perform that action at this time.
0 commit comments