Skip to content

Commit fd41d29

Browse files
author
dkostic
committed
try to make windows happy
1 parent 250905a commit fd41d29

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

crypto/fipsmodule/ec/ec_nistp.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,16 @@ static int16_t get_bit(const EC_SCALAR *in, size_t in_bit_size, size_t i) {
282282
// i.e. signed odd digits with _no zeroes_ -- that makes it "regular".
283283
void scalar_rwnaf(int16_t *out, size_t window_size,
284284
const EC_SCALAR *scalar, size_t scalar_bit_size) {
285-
int16_t window, d;
285+
assert(window_size < 14);
286286

287-
const BN_ULONG window_mask = (1 << (window_size + 1)) - 1;
288-
const size_t num_windows = DIV_AND_CEIL(scalar_bit_size, window_size);
287+
// The assert above ensures this works correctly.
288+
const int16_t window_mask = (1 << (window_size + 1)) - 1;
289+
int16_t window = (int16_t)(scalar->words[0] & (BN_ULONG)window_mask);
290+
window |= 1;
289291

290-
window = (scalar->words[0] & window_mask) | 1;
292+
const size_t num_windows = DIV_AND_CEIL(scalar_bit_size, window_size);
291293
for (size_t i = 0; i < num_windows - 1; i++) {
292-
d = (window & window_mask) - (1 << window_size);
294+
int16_t d = (window & window_mask) - (int16_t)(1 << window_size);
293295
out[i] = d;
294296
window = (window - d) >> window_size;
295297
for (size_t j = 1; j <= window_size; j++) {

0 commit comments

Comments
 (0)