Rename LMS internal tree-manipulation functions

Signed-off-by: Raef Coles <raef.coles@arm.com>
This commit is contained in:
Raef Coles 2022-09-01 11:52:17 +01:00
parent 891c613f31
commit ebd35b5b80
No known key found for this signature in database
GPG key ID: 1AAF1B43DF2086F4
2 changed files with 15 additions and 14 deletions

View file

@ -489,6 +489,8 @@ int mbedtls_lmots_generate_private_key( mbedtls_lmots_private_t *ctx,
return( MBEDTLS_ERR_LMS_BAD_INPUT_DATA ); return( MBEDTLS_ERR_LMS_BAD_INPUT_DATA );
} }
op = psa_hash_operation_init( );
ctx->params.type = type; ctx->params.type = type;
memcpy( ctx->params.I_key_identifier, memcpy( ctx->params.I_key_identifier,
@ -503,7 +505,6 @@ int mbedtls_lmots_generate_private_key( mbedtls_lmots_private_t *ctx,
for ( i_digit_idx = 0; i_digit_idx < MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT; i_digit_idx++ ) for ( i_digit_idx = 0; i_digit_idx < MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT; i_digit_idx++ )
{ {
op = psa_hash_operation_init( );
status = psa_hash_setup( &op, PSA_ALG_SHA_256 ); status = psa_hash_setup( &op, PSA_ALG_SHA_256 );
ret = mbedtls_lms_error_from_psa( status ); ret = mbedtls_lms_error_from_psa( status );
if ( ret != 0 ) if ( ret != 0 )

View file

@ -73,7 +73,7 @@
static const unsigned char D_LEAF_CONSTANT_BYTES[D_CONST_LEN] = {0x82, 0x82}; static const unsigned char D_LEAF_CONSTANT_BYTES[D_CONST_LEN] = {0x82, 0x82};
static const unsigned char D_INTERNAL_CONSTANT_BYTES[D_CONST_LEN] = {0x83, 0x83}; static const unsigned char D_INTERNAL_CONSTANT_BYTES[D_CONST_LEN] = {0x83, 0x83};
static int create_merkle_leaf_node( const unsigned char I_key_identifier[MBEDTLS_LMOTS_I_KEY_ID_LEN], static int create_merkle_leaf_value( const unsigned char I_key_identifier[MBEDTLS_LMOTS_I_KEY_ID_LEN],
unsigned char pub_key[MBEDTLS_LMOTS_N_HASH_LEN], unsigned char pub_key[MBEDTLS_LMOTS_N_HASH_LEN],
unsigned int r_node_idx, unsigned int r_node_idx,
unsigned char out[MBEDTLS_LMS_M_NODE_BYTES] ) unsigned char out[MBEDTLS_LMS_M_NODE_BYTES] )
@ -122,7 +122,7 @@ exit:
return( ret ); return( ret );
} }
static int create_merkle_internal_node( const unsigned char I_key_identifier[MBEDTLS_LMOTS_I_KEY_ID_LEN], static int create_merkle_internal_value( const unsigned char I_key_identifier[MBEDTLS_LMOTS_I_KEY_ID_LEN],
const unsigned char left_node[MBEDTLS_LMS_M_NODE_BYTES], const unsigned char left_node[MBEDTLS_LMS_M_NODE_BYTES],
const unsigned char right_node[MBEDTLS_LMS_M_NODE_BYTES], const unsigned char right_node[MBEDTLS_LMS_M_NODE_BYTES],
unsigned int r_node_idx, unsigned int r_node_idx,
@ -190,7 +190,7 @@ static int calculate_merkle_tree( mbedtls_lms_private_t *ctx,
{ {
r_node_idx = MERKLE_TREE_INTERNAL_NODE_AM + priv_key_idx; r_node_idx = MERKLE_TREE_INTERNAL_NODE_AM + priv_key_idx;
ret = create_merkle_leaf_node( ret = create_merkle_leaf_value(
ctx->params.I_key_identifier, ctx->params.I_key_identifier,
ctx->ots_public_keys[priv_key_idx].public_key, ctx->ots_public_keys[priv_key_idx].public_key,
r_node_idx, tree[r_node_idx] ); r_node_idx, tree[r_node_idx] );
@ -205,7 +205,7 @@ static int calculate_merkle_tree( mbedtls_lms_private_t *ctx,
for( r_node_idx = MERKLE_TREE_INTERNAL_NODE_AM - 1; r_node_idx > 0; for( r_node_idx = MERKLE_TREE_INTERNAL_NODE_AM - 1; r_node_idx > 0;
r_node_idx-- ) r_node_idx-- )
{ {
ret = create_merkle_internal_node( ret = create_merkle_internal_value(
ctx->params.I_key_identifier, ctx->params.I_key_identifier,
tree[(r_node_idx * 2)], tree[(r_node_idx * 2 + 1)], r_node_idx, tree[r_node_idx] ); tree[(r_node_idx * 2)], tree[(r_node_idx * 2 + 1)], r_node_idx, tree[r_node_idx] );
if( ret ) if( ret )
@ -370,7 +370,7 @@ int mbedtls_lms_verify( const mbedtls_lms_public_t *ctx,
return( ret ); return( ret );
} }
create_merkle_leaf_node( create_merkle_leaf_value(
ctx->params.I_key_identifier, ctx->params.I_key_identifier,
Kc_candidate_ots_pub_key, MERKLE_TREE_INTERNAL_NODE_AM + q_leaf_identifier, Kc_candidate_ots_pub_key, MERKLE_TREE_INTERNAL_NODE_AM + q_leaf_identifier,
Tc_candidate_root_node ); Tc_candidate_root_node );
@ -393,7 +393,7 @@ int mbedtls_lms_verify( const mbedtls_lms_public_t *ctx,
right_node = ( ( const unsigned char( * )[MBEDTLS_LMS_M_NODE_BYTES] )( sig + MBEDTLS_LMS_SIG_PATH_OFFSET ) )[height]; right_node = ( ( const unsigned char( * )[MBEDTLS_LMS_M_NODE_BYTES] )( sig + MBEDTLS_LMS_SIG_PATH_OFFSET ) )[height];
} }
create_merkle_internal_node( create_merkle_internal_value(
ctx->params.I_key_identifier, ctx->params.I_key_identifier,
left_node, right_node, parent_node_id, Tc_candidate_root_node); left_node, right_node, parent_node_id, Tc_candidate_root_node);