Skip to content

Commit

Permalink
fix for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dkostic committed Jul 9, 2024
1 parent e1fc1a7 commit 46dd057
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
8 changes: 3 additions & 5 deletions crypto/fipsmodule/ec/ec_nistp.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,10 @@ static void select_point_from_table(const ec_nistp_meth *ctx,
ec_nistp_felem_limb *xyz_out,
const ec_nistp_felem_limb *table,
const size_t idx) {
size_t entry_size = 3 * ctx->felem_num_limbs *
(sizeof(ec_nistp_felem_limb)/sizeof(crypto_word_t));
size_t entry_size = 3 * ctx->felem_num_limbs * sizeof(ec_nistp_felem_limb);

constant_time_select_entry_from_table_w(
(crypto_word_t*)xyz_out,
(crypto_word_t*)table,
constant_time_select_entry_from_table_8(
(uint8_t*)xyz_out, (uint8_t*)table,
idx, SCALAR_MUL_TABLE_NUM_POINTS, entry_size);
}

Expand Down
19 changes: 17 additions & 2 deletions crypto/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,17 +466,32 @@ static inline void constant_time_select_array_w(
}
}

static inline void constant_time_select_array_8(
uint8_t *c, uint8_t *a, uint8_t *b, uint8_t mask, size_t len) {
for (size_t i = 0; i < len; i++) {
c[i] = constant_time_select_8(mask, a[i], b[i]);
}
}

// constant_time_select_entry_from_table_w selects the idx-th entry from table.
static inline void constant_time_select_entry_from_table_w(
crypto_word_t *out, crypto_word_t *table,
size_t idx, size_t num_entries, size_t entry_size)
{
size_t idx, size_t num_entries, size_t entry_size) {
for (size_t i = 0; i < num_entries; i++) {
crypto_word_t mask = constant_time_eq_w(i, idx);
constant_time_select_array_w(out, &table[i * entry_size], out, mask, entry_size);
}
}

static inline void constant_time_select_entry_from_table_8(
uint8_t *out, uint8_t *table, size_t idx,
size_t num_entries, size_t entry_size) {
for (size_t i = 0; i < num_entries; i++) {
uint8_t mask = (uint8_t)(constant_time_eq_w(i, idx));
constant_time_select_array_8(out, &table[i * entry_size], out, mask, entry_size);
}
}

#if defined(BORINGSSL_CONSTANT_TIME_VALIDATION)

// CONSTTIME_SECRET takes a pointer and a number of bytes and marks that region
Expand Down

0 comments on commit 46dd057

Please sign in to comment.