Skip to content

Commit

Permalink
Fix Build Errors (#1635)
Browse files Browse the repository at this point in the history
* Fix build err when built with no thread

* Enable KAT

* Add Generated test

* Fix typo

* update formatting

* Fix typo

* Fix build issues

* Fix undefined error

* Fixed SA issue

* Fixed warnings

* Skip variant that exceeds timeout

* Fix style format

* Fix various build issues
  • Loading branch information
ashman-p authored and SWilson4 committed Apr 12, 2024
1 parent f4d0b22 commit 2d5a603
Show file tree
Hide file tree
Showing 36 changed files with 374 additions and 166 deletions.
20 changes: 20 additions & 0 deletions .CMake/alg_support.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,26 @@ cmake_dependent_option(OQS_ENABLE_SIG_STFL_xmssmt_shake128_h60_12 "" ON "OQS_ENA


option(OQS_ENABLE_SIG_STFL_LMS "Enable LMS algorithm family" ON)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h5_w1 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h5_w2 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h5_w4 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h5_w8 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h10_w1 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h10_w2 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h10_w4 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h10_w8 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h15_w1 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h15_w2 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h15_w4 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h15_w8 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h20_w1 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h20_w2 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h20_w4 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h20_w8 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h25_w1 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h25_w2 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h25_w4 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h25_w8 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h5_w8_h5_w8 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)
cmake_dependent_option(OQS_ENABLE_SIG_STFL_lms_sha256_h10_w4_h5_w8 "" ON "OQS_ENABLE_SIG_STFL_LMS" OFF)

Expand Down
32 changes: 16 additions & 16 deletions src/common/sha2/sha2_armv8.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,27 +290,27 @@ void oqs_sha2_sha256_inc_armv8(sha256ctx *state, const uint8_t *in, size_t len)
incr = len;
}

for (size_t i = 0; i < incr; ++i, state->data_len++, in_index++)) {
state->data[state->data_len] = in[in_index++)];
for (size_t i = 0; i < incr; ++i, state->data_len++, in_index++) {
state->data[state->data_len] = in[in_index++];
}

if (state->data_len < 64) {
break;
}
break;
}

/*
* Process a complete block now
*/
bytes = load_bigendian_64(state->ctx + 32) + 64;
crypto_hashblocks_sha256_armv8(state->ctx, state->data, 64);
store_bigendian_64(state->ctx + 32, bytes);
/*
* Process a complete block now
*/
bytes = load_bigendian_64(state->ctx + 32) + 64;
crypto_hashblocks_sha256_armv8(state->ctx, state->data, 64);
store_bigendian_64(state->ctx + 32, bytes);

/*
* update the remaining input
*/
len -= incr;
state->data_len = 0;
}
/*
* update the remaining input
*/
len -= incr;
state->data_len = 0;
}
}

void oqs_sha2_sha224_inc_blocks_armv8(sha224ctx *state, const uint8_t *in, size_t inblocks) {
Expand Down
13 changes: 13 additions & 0 deletions src/oqsconfig.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,18 @@
#cmakedefine OQS_ENABLE_SIG_STFL_xmssmt_shake128_h60_12 1

#cmakedefine OQS_ENABLE_SIG_STFL_LMS 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h5_w1 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h5_w2 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h5_w4 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h5_w8 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h10_w1 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h10_w2 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h10_w4 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h10_w8 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h15_w1 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h15_w2 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h15_w4 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h15_w8 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h20_w1 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h5_w8_h5_w8 1
#cmakedefine OQS_ENABLE_SIG_STFL_lms_sha256_h10_w4_h5_w8 1
2 changes: 1 addition & 1 deletion src/sig_stfl/lms/external/endian.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ void put_bigendian( void *target, unsigned long long value, size_t bytes ) {
unsigned char *b = target;
int i;

for (i = bytes-1; i >= 0; i--) {
for (i = (int)(bytes-1); i >= 0; i--) {
b[i] = value & 0xff;
value >>= 8;
}
Expand Down
10 changes: 5 additions & 5 deletions src/sig_stfl/lms/external/hss_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ struct hss_working_key *allocate_working_key(
if (memory_target > LONG_MAX) {
mem_target = LONG_MAX;
} else {
mem_target = memory_target;
mem_target = (unsigned long)memory_target;
}
#if 0
signed long initial_mem_target = mem_target; /* DEBUG HACK */
Expand All @@ -178,7 +178,7 @@ signed long initial_mem_target = mem_target; /* DEBUG HACK */
info->error_code = hss_error_out_of_memory;
return NULL;
}
mem_target -= sizeof(*w) + MALLOC_OVERHEAD;
mem_target -= (unsigned long)sizeof(*w) + MALLOC_OVERHEAD;
unsigned i;
w->levels = levels;
w->status = hss_error_key_uninitialized; /* Not usable until we see a */
Expand Down Expand Up @@ -220,13 +220,13 @@ signed long initial_mem_target = mem_target; /* DEBUG HACK */
info->error_code = hss_error_out_of_memory;
return 0;
}
mem_target -= w->signed_pk_len[i] + MALLOC_OVERHEAD;
mem_target -= (unsigned long)w->signed_pk_len[i] + MALLOC_OVERHEAD;
}
w->signature_len = signature_len;

/* Also account for the overhead for the stack allocation (the memory */
/* used by the stack will be accounted as a part of the tree level size */
mem_target -= MALLOC_OVERHEAD;
mem_target -= (unsigned long)MALLOC_OVERHEAD;

/*
* Plot out how many subtree sizes we have at each level. We start by
Expand Down Expand Up @@ -305,7 +305,7 @@ signed long initial_mem_target = mem_target; /* DEBUG HACK */
level_height[i], hash_size[i], &subtree_levels[i],
&stack_used );

mem_target -= mem;
mem_target -= (unsigned long)mem;
stack_usage += stack_used;
}

Expand Down
2 changes: 1 addition & 1 deletion src/sig_stfl/lms/external/hss_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct expanded_aux_data *hss_expand_aux_data( const unsigned char *aux_data,
if (!aux_data || aux_data[AUX_DATA_MARKER] == NO_AUX_DATA) return 0;

const unsigned char *orig_aux_data = aux_data;
unsigned long aux_level = get_bigendian( aux_data, 4 );
unsigned long aux_level = (unsigned long)get_bigendian( aux_data, 4 );
aux_data += 4;
aux_level &= 0x7ffffffffL; /* Turn off the 'used' marker */

Expand Down
2 changes: 1 addition & 1 deletion src/sig_stfl/lms/external/hss_compute.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static enum hss_error_code hss_compute_internal_node( unsigned char *dest,
merkle_index_t q = r - tree_size;

merkle_index_t i;
unsigned ots_len = lm_ots_get_public_key_len(lm_ots_type);
unsigned ots_len = (unsigned)lm_ots_get_public_key_len(lm_ots_type);
unsigned char pub_key[ LEAF_MAX_LEN ];
memcpy( pub_key + LEAF_I, I, I_LEN );
SET_D( pub_key + LEAF_D, D_LEAF );
Expand Down
2 changes: 1 addition & 1 deletion src/sig_stfl/lms/external/hss_generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ bool hss_generate_working_key(
if (ratio > 1000) {
core_target = 1;
} else {
core_target = core_target / ratio;
core_target = (unsigned)(core_target / ratio);
if (core_target == 0) core_target = 1;
}
prev_cost = p_order->cost;
Expand Down
2 changes: 1 addition & 1 deletion src/sig_stfl/lms/external/hss_keygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ bool hss_generate_private_key(
return false;
}

unsigned len_ots_pub = lm_ots_get_public_key_len(lm_ots_type[0]);
unsigned len_ots_pub = (unsigned)lm_ots_get_public_key_len(lm_ots_type[0]);
if (len_ots_pub == 0) {
info->error_code = hss_error_bad_param_set;
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/sig_stfl/lms/external/hss_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static enum subtree_build_status subtree_add_next_node(

/* Compute the leaf node */
merkle_index_t i;
unsigned ots_len = lm_ots_get_public_key_len(tree->lm_ots_type);
unsigned ots_len = (unsigned int)lm_ots_get_public_key_len(tree->lm_ots_type);
unsigned char pub_key[ LEAF_MAX_LEN ];
const unsigned char *I = (next_tree ? tree->I_next : tree->I);
memcpy( pub_key + LEAF_I, I, I_LEN );
Expand Down Expand Up @@ -253,7 +253,7 @@ bool hss_create_signed_public_key(unsigned char *signed_key,
unsigned len_public_key = 8 + I_LEN + hash_size;

/* Now, generate the signature */
if (!generate_merkle_signature( signed_key, len_signature,
if (!(unsigned int)generate_merkle_signature( signed_key, len_signature,
parent, w, public_key, len_public_key)) {
return false;
}
Expand Down Expand Up @@ -303,7 +303,7 @@ static void do_gen_sig( const void *detail, struct thread_collection *col) {
const unsigned char *message = d->message;
size_t message_len = d->message_len;

if (!generate_merkle_signature(signature, signature_len,
if (!(unsigned int)generate_merkle_signature(signature, signature_len,
w->tree[ levels-1 ], w, message, message_len)) {
goto failed;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sig_stfl/lms/external/hss_sign_inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ bool hss_sign_finalize(

int i;
for (i=0; i<L-1; i++) {
merkle_index_t q = get_bigendian( signature, 4 );
merkle_index_t q = (merkle_index_t)get_bigendian( signature, 4 );
if (q > working_key->tree[i]->max_index) {
hss_zeroize( seed_buff, sizeof seed_buff );
return 0;
Expand Down
16 changes: 8 additions & 8 deletions src/sig_stfl/lms/external/hss_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ bool hss_validate_signature(
info->error_code = hss_error_bad_signature;
return false;
}
uint_fast32_t levels = get_bigendian( signature, 4 ) + 1;
uint_fast32_t levels = (uint_fast32_t)get_bigendian( signature, 4 ) + 1;
/* +1 because what's in the signature is levels-1 */
signature += 4; signature_len -= 4;
if (levels < MIN_HSS_LEVELS || levels > MAX_HSS_LEVELS ||
levels != get_bigendian( public_key, 4 )) {
levels != (uint_fast32_t)get_bigendian( public_key, 4 )) {
info->error_code = hss_error_bad_signature;
return false;
}

/* Compare that to what the public key says */
uint_fast32_t pub_levels = get_bigendian( public_key, 4 );
uint_fast32_t pub_levels = (uint_fast32_t)get_bigendian( public_key, 4 );
if (levels != pub_levels) {
/* Signature and public key don't agree */
info->error_code = hss_error_bad_signature;
Expand Down Expand Up @@ -109,9 +109,9 @@ bool hss_validate_signature(
*/

/* Get the length of Signature A */
param_set_t lm_type = get_bigendian( public_key, 4 );
param_set_t lm_ots_type = get_bigendian( public_key+4, 4 );
unsigned l_siglen = lm_get_signature_len(lm_type, lm_ots_type);
param_set_t lm_type = (param_set_t)get_bigendian( public_key, 4 );
param_set_t lm_ots_type = (param_set_t)get_bigendian( public_key+4, 4 );
unsigned l_siglen = (unsigned)lm_get_signature_len(lm_type, lm_ots_type);
if (l_siglen == 0 || l_siglen > signature_len) {
info->error_code = hss_error_bad_signature;
goto failed;
Expand All @@ -134,8 +134,8 @@ bool hss_validate_signature(
* someone other than the valid signer modified it), then
* Signature A will not validate, and so we'll catch that
*/
lm_type = get_bigendian( signature, 4 );
unsigned l_pubkeylen = lm_get_public_key_len(lm_type);
lm_type = (param_set_t)get_bigendian( signature, 4 );
unsigned l_pubkeylen = (unsigned)lm_get_public_key_len(lm_type);
if (l_pubkeylen == 0 || l_pubkeylen > signature_len) {
info->error_code = hss_error_bad_signature;
goto failed;
Expand Down
16 changes: 8 additions & 8 deletions src/sig_stfl/lms/external/hss_verify_inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ bool hss_validate_signature_init(
ctx->status = info->error_code = hss_error_bad_signature;
return false;
}
uint_fast32_t levels = get_bigendian( signature, 4 ) + 1;
uint_fast32_t levels = (uint_fast32_t)get_bigendian( signature, 4 ) + 1;
/* +1 because what's in the signature is levels-1 */
signature += 4; signature_len -= 4;
if (levels < MIN_HSS_LEVELS || levels > MAX_HSS_LEVELS ||
levels != get_bigendian( public_key, 4 )) {
levels != (uint_fast32_t)get_bigendian( public_key, 4 )) {
ctx->status = info->error_code = hss_error_bad_signature;
return false;
}
uint_fast32_t pub_levels = get_bigendian( public_key, 4 );
uint_fast32_t pub_levels = (uint_fast32_t)get_bigendian( public_key, 4 );
if (levels != pub_levels) {
/* Signature and public key don't agree */
ctx->status = info->error_code = hss_error_bad_signature;
Expand All @@ -72,17 +72,17 @@ bool hss_validate_signature_init(
/* as we go. Note that we don't validate the bottom level yet */
for (i=0; i<levels-1; i++) {
/* The next thing is the signature of this public key */
param_set_t lm_type = get_bigendian( public_key, 4 );
param_set_t lm_ots_type = get_bigendian( public_key+4, 4 );
unsigned l_siglen = lm_get_signature_len(lm_type, lm_ots_type);
param_set_t lm_type = (param_set_t)get_bigendian( public_key, 4 );
param_set_t lm_ots_type = (param_set_t)get_bigendian( public_key+4, 4 );
unsigned l_siglen = (unsigned)lm_get_signature_len(lm_type, lm_ots_type);
if (l_siglen == 0 || l_siglen > signature_len) goto failed;
const unsigned char *l_sig = signature;
signature += l_siglen; signature_len -= l_siglen;

/* The next thing is the next level public key (which we need */
/* to validate) */
if (signature_len < 4) goto failed;
lm_type = get_bigendian( signature, 4 );
lm_type = (param_set_t)get_bigendian( signature, 4 );
unsigned l_pubkeylen = lm_get_public_key_len(lm_type);
if (l_pubkeylen == 0 || l_pubkeylen > signature_len) goto failed;
const unsigned char *l_pubkey = signature;
Expand Down Expand Up @@ -122,7 +122,7 @@ bool hss_validate_signature_init(
memcpy( ctx->final_public_key, public_key, 8 + I_LEN + MAX_HASH );

/* Now, initialize the context */
param_set_t ots_type = get_bigendian( public_key+4, 4 );
param_set_t ots_type = (param_set_t)get_bigendian( public_key+4, 4 );

unsigned h, n;
if (!lm_ots_look_up_parameter_set(ots_type, &h, &n, NULL, NULL, NULL)) {
Expand Down
2 changes: 1 addition & 1 deletion src/sig_stfl/lms/external/lm_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ size_t lm_get_signature_len(param_set_t lm_type,
if (!lm_look_up_parameter_set( lm_type, 0, &n, &height ))
return 0;

int ots_sig_len = lm_ots_get_signature_len(lm_ots_type);
int ots_sig_len = (int)lm_ots_get_signature_len(lm_ots_type);
if (ots_sig_len == 0)
return 0;

Expand Down
2 changes: 1 addition & 1 deletion src/sig_stfl/lms/external/lm_ots_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool lm_ots_validate_signature_compute(
if (signature_len < 4) return false; /* Ha, ha, very funny... */

/* We don't trust the parameter set that's in the signature; verify it */
param_set_t parameter_set = get_bigendian( signature, 4 );
param_set_t parameter_set = (param_set_t)get_bigendian( signature, 4 );
if (parameter_set != expected_parameter_set) {
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/sig_stfl/lms/external/lm_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ bool lm_validate_signature(
const unsigned char *signature, size_t signature_len) {
union hash_context ctx;

param_set_t lm_type = get_bigendian( public_key + LM_PUB_PARM_SET, 4 );
param_set_t ots_type = get_bigendian( public_key + LM_PUB_OTS_PARM_SET, 4 );
param_set_t lm_type = (param_set_t)get_bigendian( public_key + LM_PUB_PARM_SET, 4 );
param_set_t ots_type = (param_set_t)get_bigendian( public_key + LM_PUB_OTS_PARM_SET, 4 );

unsigned h, n, height;
if (!lm_look_up_parameter_set(lm_type, &h, &n, &height)) return false;
Expand All @@ -47,7 +47,7 @@ bool lm_validate_signature(
const unsigned char *I = public_key + LM_PUB_I;

if (signature_len < 8) return false;
merkle_index_t count = get_bigendian( signature, 4 );
merkle_index_t count = (param_set_t)get_bigendian( signature, 4 );
signature += 4; signature_len -= 4; /* 4 bytes, rather then 8 */
/* the OTS type is expected to be a part of the OTS signature, */
/* which lm_ots_validate_signature_compute will expect */
Expand All @@ -67,7 +67,7 @@ bool lm_validate_signature(
/* Get the parameter set declared in the sigature; make sure it matches */
/* what we expect */
if (signature_len < 4) return false;
param_set_t parameter_set = get_bigendian( signature, 4 );
param_set_t parameter_set = (param_set_t)get_bigendian( signature, 4 );
if (parameter_set != lm_type) return false;
signature += 4; signature_len -= 4;

Expand Down
Loading

0 comments on commit 2d5a603

Please sign in to comment.