@@ -915,8 +915,14 @@ impl Scalar {
915
915
916
916
let mut naf = [ 0i8 ; 256 ] ;
917
917
918
- let mut x_u64 = [ 0u64 ; 5 ] ;
919
- LittleEndian :: read_u64_into ( & self . bytes , & mut x_u64[ 0 ..4 ] ) ;
918
+ #[ repr( align( 32 ) ) ]
919
+ struct AlignedU64Slice < const N : usize > ( [ u64 ; N ] ) ;
920
+
921
+ let mut x_u64 = AlignedU64Slice ( [ 0u64 ; 5 ] ) ;
922
+ LittleEndian :: read_u64_into ( & self . bytes , & mut x_u64. 0 [ 0 ..4 ] ) ;
923
+
924
+ #[ cfg( feature = "betrusted" ) ]
925
+ log:: trace!( "x_u64: {:?}" , x_u64. 0 ) ;
920
926
921
927
let width = 1 << w;
922
928
let window_mask = width - 1 ;
@@ -930,10 +936,10 @@ impl Scalar {
930
936
let bit_buf: u64 ;
931
937
if bit_idx < 64 - w {
932
938
// This window's bits are contained in a single u64
933
- bit_buf = x_u64[ u64_idx] >> bit_idx;
939
+ bit_buf = x_u64. 0 [ u64_idx] >> bit_idx;
934
940
} else {
935
941
// Combine the current u64's bits with the bits from the next u64
936
- bit_buf = ( x_u64[ u64_idx] >> bit_idx) | ( x_u64[ 1 +u64_idx] << ( 64 - bit_idx) ) ;
942
+ bit_buf = ( x_u64. 0 [ u64_idx] >> bit_idx) | ( x_u64. 0 [ 1 +u64_idx] << ( 64 - bit_idx) ) ;
937
943
}
938
944
939
945
// Add the carry into the current window
@@ -949,9 +955,17 @@ impl Scalar {
949
955
}
950
956
951
957
if window < width/2 {
958
+ #[ cfg( feature = "betrusted" ) ]
959
+ log:: trace!( "carry 0 width {} naf[{}] = {}; c.{} bb.{:x} wm.{} idx64.{} idxbit.{} xu64[0].{:x}" , width, pos, window,
960
+ carry, bit_buf, window_mask, u64_idx, bit_idx, x_u64. 0 [ 0 ] ,
961
+ ) ;
952
962
carry = 0 ;
953
963
naf[ pos] = window as i8 ;
954
964
} else {
965
+ #[ cfg( feature = "betrusted" ) ]
966
+ log:: trace!( "carry 1 width {} naf[{}] = {}/{}; c.{} bb.{:x} wm.{} idx64.{} idxbit.{} xu64[0].{:x}" , width, pos, window, ( window as i8 ) . wrapping_sub( width as i8 ) ,
967
+ carry, bit_buf, window_mask, u64_idx, bit_idx, x_u64. 0 [ 0 ]
968
+ ) ;
955
969
carry = 1 ;
956
970
naf[ pos] = ( window as i8 ) . wrapping_sub ( width as i8 ) ;
957
971
}
0 commit comments