mirror of
https://github.com/saymrwulf/betrusted-curve25519-dalek-source.git
synced 2026-09-05 20:30:54 +00:00
work around compiler bug https://github.com/rust-lang/rust/issues/86693
thanks @xobs for the work-around!
This commit is contained in:
parent
1a79b76e90
commit
279bbc5287
1 changed files with 18 additions and 4 deletions
|
|
@ -915,8 +915,14 @@ impl Scalar {
|
|||
|
||||
let mut naf = [0i8; 256];
|
||||
|
||||
let mut x_u64 = [0u64; 5];
|
||||
LittleEndian::read_u64_into(&self.bytes, &mut x_u64[0..4]);
|
||||
#[repr(align(32))]
|
||||
struct AlignedU64Slice<const N: usize>([u64; N]);
|
||||
|
||||
let mut x_u64 = AlignedU64Slice([0u64; 5]);
|
||||
LittleEndian::read_u64_into(&self.bytes, &mut x_u64.0[0..4]);
|
||||
|
||||
#[cfg(feature = "betrusted")]
|
||||
log::trace!("x_u64: {:?}", x_u64.0);
|
||||
|
||||
let width = 1 << w;
|
||||
let window_mask = width - 1;
|
||||
|
|
@ -930,10 +936,10 @@ impl Scalar {
|
|||
let bit_buf: u64;
|
||||
if bit_idx < 64 - w {
|
||||
// This window's bits are contained in a single u64
|
||||
bit_buf = x_u64[u64_idx] >> bit_idx;
|
||||
bit_buf = x_u64.0[u64_idx] >> bit_idx;
|
||||
} else {
|
||||
// Combine the current u64's bits with the bits from the next u64
|
||||
bit_buf = (x_u64[u64_idx] >> bit_idx) | (x_u64[1+u64_idx] << (64 - bit_idx));
|
||||
bit_buf = (x_u64.0[u64_idx] >> bit_idx) | (x_u64.0[1+u64_idx] << (64 - bit_idx));
|
||||
}
|
||||
|
||||
// Add the carry into the current window
|
||||
|
|
@ -949,9 +955,17 @@ impl Scalar {
|
|||
}
|
||||
|
||||
if window < width/2 {
|
||||
#[cfg(feature = "betrusted")]
|
||||
log::trace!("carry 0 width {} naf[{}] = {}; c.{} bb.{:x} wm.{} idx64.{} idxbit.{} xu64[0].{:x}", width, pos, window,
|
||||
carry, bit_buf, window_mask, u64_idx, bit_idx, x_u64.0[0],
|
||||
);
|
||||
carry = 0;
|
||||
naf[pos] = window as i8;
|
||||
} else {
|
||||
#[cfg(feature = "betrusted")]
|
||||
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),
|
||||
carry, bit_buf, window_mask, u64_idx, bit_idx, x_u64.0[0]
|
||||
);
|
||||
carry = 1;
|
||||
naf[pos] = (window as i8).wrapping_sub(width as i8);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue