Update LMS API to support multiple parameter sets
Parameterise macros to allow variation of sizes
Signed-off-by: Raef Coles <raef.coles@arm.com>
diff --git a/library/lmots.c b/library/lmots.c
index bf66449..41ca042 100644
--- a/library/lmots.c
+++ b/library/lmots.c
@@ -45,7 +45,7 @@
#include "psa/crypto.h"
#define MBEDTLS_LMOTS_SIG_C_RANDOM_OFFSET (MBEDTLS_LMOTS_SIG_TYPE_OFFSET + MBEDTLS_LMOTS_TYPE_LEN)
-#define MBEDTLS_LMOTS_SIG_SIGNATURE_OFFSET (MBEDTLS_LMOTS_SIG_C_RANDOM_OFFSET + MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN)
+#define MBEDTLS_LMOTS_SIG_SIGNATURE_OFFSET(type) (MBEDTLS_LMOTS_SIG_C_RANDOM_OFFSET + MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN(type))
#define MBEDTLS_LMOTS_PUBLIC_KEY_TYPE_OFFSET (0)
#define MBEDTLS_LMOTS_PUBLIC_KEY_I_KEY_ID_OFFSET (MBEDTLS_LMOTS_PUBLIC_KEY_TYPE_OFFSET + MBEDTLS_LMOTS_TYPE_LEN)
@@ -60,6 +60,9 @@
#define J_HASH_IDX_LEN (1)
#define D_CONST_LEN (2)
+/* Currently only defined for SHA256, 32 is the max hash output size */
+#define MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN_MAX (MBEDTLS_LMOTS_N_HASH_LEN_MAX)
+
#define DIGIT_MAX_VALUE ((1u << W_WINTERNITZ_PARAMETER) - 1u)
#define D_CONST_LEN (2)
@@ -87,12 +90,13 @@
return val;
}
-static unsigned short lmots_checksum_calculate( const unsigned char* digest )
+static unsigned short lmots_checksum_calculate( const mbedtls_lmots_parameters_t *params,
+ const unsigned char* digest )
{
size_t idx;
unsigned sum = 0;
- for ( idx = 0; idx < MBEDTLS_LMOTS_N_HASH_LEN; idx++ )
+ for ( idx = 0; idx < MBEDTLS_LMOTS_N_HASH_LEN(params->type); idx++ )
{
sum += DIGIT_MAX_VALUE - digest[idx];
}
@@ -103,8 +107,8 @@
static int create_digit_array_with_checksum( const mbedtls_lmots_parameters_t *params,
const unsigned char *msg,
size_t msg_len,
- const unsigned char C_random_value[MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN],
- unsigned char out[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT] )
+ const unsigned char *C_random_value,
+ unsigned char *out )
{
psa_hash_operation_t op;
psa_status_t status;
@@ -135,7 +139,8 @@
if ( ret != 0 )
goto exit;
- status = psa_hash_update( &op, C_random_value, MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN );
+ status = psa_hash_update( &op, C_random_value,
+ MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN(params->type) );
ret = mbedtls_lms_error_from_psa( status );
if ( ret != 0 )
goto exit;
@@ -145,14 +150,16 @@
if ( ret != 0 )
goto exit;
- status = psa_hash_finish( &op, out, MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT,
+ status = psa_hash_finish( &op, out,
+ MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT(params->type),
&output_hash_len );
ret = mbedtls_lms_error_from_psa( status );
if ( ret != 0 )
goto exit;
- checksum = lmots_checksum_calculate( out );
- unsigned_int_to_network_bytes( checksum, CHECKSUM_LEN, out + MBEDTLS_LMOTS_N_HASH_LEN );
+ checksum = lmots_checksum_calculate( params, out );
+ unsigned_int_to_network_bytes( checksum, CHECKSUM_LEN,
+ out + MBEDTLS_LMOTS_N_HASH_LEN(params->type) );
exit:
psa_hash_abort( &op );
@@ -161,10 +168,10 @@
}
static int hash_digit_array( const mbedtls_lmots_parameters_t *params,
- const unsigned char x_digit_array[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT][MBEDTLS_LMOTS_N_HASH_LEN],
+ const unsigned char *x_digit_array,
const unsigned char *hash_idx_min_values,
const unsigned char *hash_idx_max_values,
- unsigned char output[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT][MBEDTLS_LMOTS_N_HASH_LEN] )
+ unsigned char *output )
{
unsigned char i_digit_idx;
unsigned char j_hash_idx;
@@ -178,15 +185,18 @@
psa_hash_operation_t op;
psa_status_t status;
size_t output_hash_len;
- unsigned char tmp_hash[MBEDTLS_LMOTS_N_HASH_LEN];
+ unsigned char tmp_hash[MBEDTLS_LMOTS_N_HASH_LEN_MAX];
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
op = psa_hash_operation_init();
- 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(params->type);
+ i_digit_idx++ )
{
- memcpy( tmp_hash, &x_digit_array[i_digit_idx], MBEDTLS_LMOTS_N_HASH_LEN );
+ memcpy( tmp_hash, &x_digit_array[i_digit_idx * MBEDTLS_LMOTS_N_HASH_LEN(params->type)],
+ MBEDTLS_LMOTS_N_HASH_LEN(params->type) );
j_hash_idx_min = hash_idx_min_values != NULL ? hash_idx_min_values[i_digit_idx] : 0;
j_hash_idx_max = hash_idx_max_values != NULL ? hash_idx_max_values[i_digit_idx] : DIGIT_MAX_VALUE;
@@ -224,7 +234,8 @@
if ( ret != 0 )
goto exit;
- status = psa_hash_update( &op, tmp_hash, MBEDTLS_LMOTS_N_HASH_LEN );
+ status = psa_hash_update( &op, tmp_hash,
+ MBEDTLS_LMOTS_N_HASH_LEN(params->type) );
ret = mbedtls_lms_error_from_psa( status );
if ( ret != 0 )
goto exit;
@@ -237,7 +248,8 @@
psa_hash_abort( &op );
}
- memcpy( &output[i_digit_idx], tmp_hash, MBEDTLS_LMOTS_N_HASH_LEN );
+ memcpy( &output[i_digit_idx * MBEDTLS_LMOTS_N_HASH_LEN(params->type)], tmp_hash,
+ MBEDTLS_LMOTS_N_HASH_LEN(params->type) );
}
exit:
@@ -253,7 +265,7 @@
}
static int public_key_from_hashed_digit_array( const mbedtls_lmots_parameters_t *params,
- const unsigned char y_hashed_digits[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT][MBEDTLS_LMOTS_N_HASH_LEN],
+ const unsigned char *y_hashed_digits,
unsigned char *pub_key )
{
psa_hash_operation_t op;
@@ -285,13 +297,15 @@
if ( ret != 0 )
goto exit;
- status = psa_hash_update( &op, ( unsigned char * )y_hashed_digits,
- MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT * MBEDTLS_LMOTS_N_HASH_LEN );
+ status = psa_hash_update( &op, y_hashed_digits,
+ MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT(params->type) *
+ MBEDTLS_LMOTS_N_HASH_LEN(params->type) );
ret = mbedtls_lms_error_from_psa( status );
if ( ret != 0 )
goto exit;
- status = psa_hash_finish( &op, pub_key, 32, &output_hash_len );
+ status = psa_hash_finish( &op, pub_key, MBEDTLS_LMOTS_N_HASH_LEN(params->type),
+ &output_hash_len );
ret = mbedtls_lms_error_from_psa( status );
exit:
@@ -330,15 +344,15 @@
int mbedtls_lmots_import_public_key( mbedtls_lmots_public_t *ctx,
const unsigned char *key, size_t key_len )
{
- if ( key_len < MBEDTLS_LMOTS_PUBLIC_KEY_LEN )
- {
- return( MBEDTLS_ERR_LMS_BAD_INPUT_DATA );
- }
-
ctx->params.type =
network_bytes_to_unsigned_int( MBEDTLS_LMOTS_TYPE_LEN,
key + MBEDTLS_LMOTS_SIG_TYPE_OFFSET );
+ if ( key_len < MBEDTLS_LMOTS_PUBLIC_KEY_LEN(ctx->params.type) )
+ {
+ return( MBEDTLS_ERR_LMS_BAD_INPUT_DATA );
+ }
+
memcpy( ctx->params.I_key_identifier,
key + MBEDTLS_LMOTS_PUBLIC_KEY_I_KEY_ID_OFFSET, MBEDTLS_LMOTS_I_KEY_ID_LEN );
@@ -347,7 +361,7 @@
memcpy( ctx->public_key,
key + MBEDTLS_LMOTS_PUBLIC_KEY_KEY_HASH_OFFSET,
- MBEDTLS_LMOTS_N_HASH_LEN );
+ MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type) );
ctx->have_public_key = 1;
@@ -363,8 +377,8 @@
size_t out_size,
size_t *out_len)
{
- unsigned char tmp_digit_array[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT];
- unsigned char y_hashed_digits[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT][MBEDTLS_LMOTS_N_HASH_LEN];
+ unsigned char tmp_digit_array[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT_MAX];
+ unsigned char y_hashed_digits[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT_MAX][MBEDTLS_LMOTS_N_HASH_LEN_MAX];
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
if ( msg == NULL && msg_size != 0 )
@@ -372,7 +386,8 @@
return ( MBEDTLS_ERR_LMS_BAD_INPUT_DATA );
}
- if ( sig_size != MBEDTLS_LMOTS_SIG_LEN || out_size < MBEDTLS_LMOTS_N_HASH_LEN )
+ if ( sig_size != MBEDTLS_LMOTS_SIG_LEN(params->type) ||
+ out_size < MBEDTLS_LMOTS_N_HASH_LEN(params->type) )
{
return( MBEDTLS_ERR_LMS_BAD_INPUT_DATA );
}
@@ -386,14 +401,16 @@
}
ret = hash_digit_array( params,
- ( const unsigned char( *)[MBEDTLS_LMOTS_N_HASH_LEN] )(sig + MBEDTLS_LMOTS_SIG_SIGNATURE_OFFSET),
- tmp_digit_array, NULL, y_hashed_digits );
+ sig + MBEDTLS_LMOTS_SIG_SIGNATURE_OFFSET(params->type),
+ tmp_digit_array, NULL, (unsigned char *)y_hashed_digits );
if ( ret )
{
return ( ret );
}
- ret = public_key_from_hashed_digit_array( params, y_hashed_digits, out );
+ ret = public_key_from_hashed_digit_array( params,
+ (unsigned char *)y_hashed_digits,
+ out );
if ( ret )
{
return ( ret );
@@ -401,7 +418,7 @@
if ( out_len != NULL )
{
- *out_len = MBEDTLS_LMOTS_N_HASH_LEN;
+ *out_len = MBEDTLS_LMOTS_N_HASH_LEN(params->type);
}
return( 0 );
@@ -411,7 +428,7 @@
size_t msg_size, const unsigned char *sig,
size_t sig_size )
{
- unsigned char Kc_public_key_candidate[MBEDTLS_LMOTS_N_HASH_LEN];
+ unsigned char Kc_public_key_candidate[MBEDTLS_LMOTS_N_HASH_LEN_MAX];
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
if ( msg == NULL && msg_size != 0 )
@@ -439,7 +456,7 @@
ret = mbedtls_lmots_calculate_public_key_candidate( &ctx->params,
msg, msg_size, sig, sig_size,
Kc_public_key_candidate,
- MBEDTLS_LMOTS_N_HASH_LEN,
+ MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type),
NULL);
if ( ret )
{
@@ -505,7 +522,9 @@
unsigned_int_to_network_bytes( 0xFF, sizeof( const_bytes ), const_bytes );
- 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(ctx->params.type);
+ i_digit_idx++ )
{
status = psa_hash_setup( &op, PSA_ALG_SHA_256 );
ret = mbedtls_lms_error_from_psa( status );
@@ -544,7 +563,8 @@
status = psa_hash_finish( &op,
ctx->private_key[i_digit_idx],
- 32, &output_hash_len );
+ MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type),
+ &output_hash_len );
ret = mbedtls_lms_error_from_psa( status );
if ( ret )
goto exit;
@@ -567,7 +587,7 @@
int mbedtls_lmots_calculate_public_key( mbedtls_lmots_public_t *ctx,
mbedtls_lmots_private_t *priv_ctx)
{
- unsigned char y_hashed_digits[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT][MBEDTLS_LMOTS_N_HASH_LEN];
+ unsigned char y_hashed_digits[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT_MAX][MBEDTLS_LMOTS_N_HASH_LEN_MAX];
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
/* Check that a private key is loaded */
@@ -576,15 +596,16 @@
return( MBEDTLS_ERR_LMS_BAD_INPUT_DATA );
}
- ret = hash_digit_array( &priv_ctx->params, priv_ctx->private_key, NULL,
- NULL, y_hashed_digits );
+ ret = hash_digit_array( &priv_ctx->params,
+ (unsigned char *)priv_ctx->private_key, NULL,
+ NULL, (unsigned char *)y_hashed_digits );
if ( ret )
{
return( ret );
}
ret = public_key_from_hashed_digit_array( &priv_ctx->params,
- y_hashed_digits,
+ (unsigned char *)y_hashed_digits,
ctx->public_key );
if ( ret )
{
@@ -604,7 +625,7 @@
unsigned char *key, size_t key_size,
size_t *key_len )
{
- if( key_size < MBEDTLS_LMS_PUBLIC_KEY_LEN )
+ if( key_size < MBEDTLS_LMOTS_PUBLIC_KEY_LEN(ctx->params.type) )
{
return( MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL );
}
@@ -627,11 +648,11 @@
MBEDTLS_LMOTS_Q_LEAF_ID_LEN);
memcpy( key + MBEDTLS_LMOTS_PUBLIC_KEY_KEY_HASH_OFFSET, ctx->public_key,
- MBEDTLS_LMOTS_N_HASH_LEN );
+ MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type) );
if( key_len != NULL )
{
- *key_len = MBEDTLS_LMS_PUBLIC_KEY_LEN;
+ *key_len = MBEDTLS_LMOTS_PUBLIC_KEY_LEN(ctx->params.type);
}
return( 0 );
@@ -642,7 +663,7 @@
void *p_rng, const unsigned char *msg, size_t msg_size,
unsigned char *sig, size_t sig_size, size_t* sig_len )
{
- unsigned char tmp_digit_array[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT];
+ unsigned char tmp_digit_array[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT_MAX];
/* Create a temporary buffer to prepare the signature in. This allows us to
* finish creating a signature (ensuring the process doesn't fail), and then
* erase the private key **before** writing any data into the sig parameter
@@ -650,8 +671,8 @@
* a partial signature on failure, which effectively compromises the private
* key.
*/
- unsigned char tmp_sig[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT][MBEDTLS_LMOTS_N_HASH_LEN];
- unsigned char tmp_c_random[MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN];
+ unsigned char tmp_sig[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT_MAX][MBEDTLS_LMOTS_N_HASH_LEN_MAX];
+ unsigned char tmp_c_random[MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN_MAX];
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
if ( msg == NULL && msg_size != 0 )
@@ -659,7 +680,7 @@
return( MBEDTLS_ERR_LMS_BAD_INPUT_DATA );
}
- if( sig_size < MBEDTLS_LMOTS_SIG_LEN )
+ if( sig_size < MBEDTLS_LMOTS_SIG_LEN(ctx->params.type) )
{
return( MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL );
}
@@ -670,7 +691,7 @@
return( MBEDTLS_ERR_LMS_BAD_INPUT_DATA );
}
- ret = f_rng( p_rng, tmp_c_random, MBEDTLS_LMOTS_N_HASH_LEN );
+ ret = f_rng( p_rng, tmp_c_random, MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type) );
if ( ret )
{
return( ret );
@@ -685,9 +706,8 @@
return( ret );
}
- ret = hash_digit_array( &ctx->params,
- ctx->private_key,
- NULL, tmp_digit_array, tmp_sig );
+ ret = hash_digit_array( &ctx->params, (unsigned char *)ctx->private_key,
+ NULL, tmp_digit_array, (unsigned char *)tmp_sig );
if ( ret )
{
return( ret );
@@ -705,14 +725,15 @@
sizeof(ctx->private_key));
memcpy( sig + MBEDTLS_LMOTS_SIG_C_RANDOM_OFFSET, tmp_c_random,
- MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN );
+ MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN(ctx->params.type) );
- memcpy( sig + MBEDTLS_LMOTS_SIG_SIGNATURE_OFFSET, tmp_sig,
- MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT * MBEDTLS_LMOTS_N_HASH_LEN );
+ memcpy( sig + MBEDTLS_LMOTS_SIG_SIGNATURE_OFFSET(ctx->params.type), tmp_sig,
+ MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT(ctx->params.type)
+ * MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type) );
if( sig_len != NULL )
{
- *sig_len = MBEDTLS_LMS_SIG_LEN;
+ *sig_len = MBEDTLS_LMOTS_SIG_LEN(ctx->params.type);
}
return( 0 );
diff --git a/library/lmots.h b/library/lmots.h
index e784bf5..6ada0ba 100644
--- a/library/lmots.h
+++ b/library/lmots.h
@@ -33,18 +33,25 @@
#include <stdint.h>
#include <stddef.h>
-#define MBEDTLS_LMOTS_N_HASH_LEN (32)
-#define MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT (34)
-#define MBEDTLS_LMOTS_TYPE_LEN (4)
-#define MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN (MBEDTLS_LMOTS_N_HASH_LEN)
-#define MBEDTLS_LMOTS_I_KEY_ID_LEN (16)
-#define MBEDTLS_LMOTS_Q_LEAF_ID_LEN (4)
+/* Currently only defined for SHA256, 32 is the max hash output size */
+#define MBEDTLS_LMOTS_N_HASH_LEN_MAX (32u)
+#define MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT_MAX (34u)
+#define MBEDTLS_LMOTS_N_HASH_LEN(type) (type == MBEDTLS_LMOTS_SHA256_N32_W8 ? 32u : 0)
+#define MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT(type) (type == MBEDTLS_LMOTS_SHA256_N32_W8 ? 34u : 0)
+#define MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN(type) (MBEDTLS_LMOTS_N_HASH_LEN(type))
+#define MBEDTLS_LMOTS_TYPE_LEN (4u)
+#define MBEDTLS_LMOTS_I_KEY_ID_LEN (16u)
+#define MBEDTLS_LMOTS_Q_LEAF_ID_LEN (4u)
-#define MBEDTLS_LMOTS_SIG_LEN (MBEDTLS_LMOTS_TYPE_LEN + MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN + \
- (MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT * MBEDTLS_LMOTS_N_HASH_LEN))
+#define MBEDTLS_LMOTS_SIG_LEN(type) (MBEDTLS_LMOTS_TYPE_LEN + \
+ MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN(type) + \
+ (MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT(type) * \
+ MBEDTLS_LMOTS_N_HASH_LEN(type)))
-#define MBEDTLS_LMOTS_PUBLIC_KEY_LEN (MBEDTLS_LMOTS_TYPE_LEN + MBEDTLS_LMOTS_I_KEY_ID_LEN + \
- MBEDTLS_LMOTS_Q_LEAF_ID_LEN + MBEDTLS_LMOTS_N_HASH_LEN)
+#define MBEDTLS_LMOTS_PUBLIC_KEY_LEN(type) (MBEDTLS_LMOTS_TYPE_LEN + \
+ MBEDTLS_LMOTS_I_KEY_ID_LEN + \
+ MBEDTLS_LMOTS_Q_LEAF_ID_LEN + \
+ MBEDTLS_LMOTS_N_HASH_LEN(type))
#define MBEDTLS_LMOTS_SIG_TYPE_OFFSET (0)
@@ -121,7 +128,7 @@
*/
typedef struct {
mbedtls_lmots_parameters_t MBEDTLS_PRIVATE(params);
- unsigned char MBEDTLS_PRIVATE(private_key)[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT][32];
+ unsigned char MBEDTLS_PRIVATE(private_key)[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT_MAX][32];
unsigned char MBEDTLS_PRIVATE(have_private_key); /*!< Whether the context contains a private key.
Boolean values only. */
} mbedtls_lmots_private_t;
diff --git a/library/lms.c b/library/lms.c
index cb56cb3..71921f7 100644
--- a/library/lms.c
+++ b/library/lms.c
@@ -54,10 +54,10 @@
#define mbedtls_free free
#endif
-#define MBEDTLS_LMS_SIG_Q_LEAF_ID_OFFSET (0)
-#define MBEDTLS_LMS_SIG_OTS_SIG_OFFSET (MBEDTLS_LMS_SIG_Q_LEAF_ID_OFFSET + MBEDTLS_LMOTS_Q_LEAF_ID_LEN)
-#define MBEDTLS_LMS_SIG_TYPE_OFFSET (MBEDTLS_LMS_SIG_OTS_SIG_OFFSET + MBEDTLS_LMOTS_SIG_LEN)
-#define MBEDTLS_LMS_SIG_PATH_OFFSET (MBEDTLS_LMS_SIG_TYPE_OFFSET + MBEDTLS_LMS_TYPE_LEN)
+#define MBEDTLS_LMS_SIG_Q_LEAF_ID_OFFSET (0)
+#define MBEDTLS_LMS_SIG_OTS_SIG_OFFSET (MBEDTLS_LMS_SIG_Q_LEAF_ID_OFFSET + MBEDTLS_LMOTS_Q_LEAF_ID_LEN)
+#define MBEDTLS_LMS_SIG_TYPE_OFFSET(otstype) (MBEDTLS_LMS_SIG_OTS_SIG_OFFSET + MBEDTLS_LMOTS_SIG_LEN(otstype))
+#define MBEDTLS_LMS_SIG_PATH_OFFSET(otstype) (MBEDTLS_LMS_SIG_TYPE_OFFSET(otstype) + MBEDTLS_LMS_TYPE_LEN)
#define MBEDTLS_LMS_PUBLIC_KEY_TYPE_OFFSET (0)
#define MBEDTLS_LMS_PUBLIC_KEY_OTSTYPE_OFFSET (MBEDTLS_LMS_PUBLIC_KEY_TYPE_OFFSET + MBEDTLS_LMS_TYPE_LEN)
@@ -65,18 +65,21 @@
#define MBEDTLS_LMS_PUBLIC_KEY_ROOT_NODE_OFFSET (MBEDTLS_LMS_PUBLIC_KEY_I_KEY_ID_OFFSET + MBEDTLS_LMOTS_I_KEY_ID_LEN)
-#define MERKLE_TREE_NODE_AM (1u << (MBEDTLS_LMS_H_TREE_HEIGHT + 1u))
-#define MERKLE_TREE_LEAF_NODE_AM (1u << MBEDTLS_LMS_H_TREE_HEIGHT)
-#define MERKLE_TREE_INTERNAL_NODE_AM (1u << MBEDTLS_LMS_H_TREE_HEIGHT)
+/* Currently only support H=10 */
+#define MBEDTLS_LMS_H_TREE_HEIGHT_MAX 10
+#define MERKLE_TREE_NODE_AM_MAX (1u << (MBEDTLS_LMS_H_TREE_HEIGHT_MAX + 1u))
+#define MERKLE_TREE_NODE_AM(type) (1u << (MBEDTLS_LMS_H_TREE_HEIGHT(type) + 1u))
+#define MERKLE_TREE_LEAF_NODE_AM(type) (1u << MBEDTLS_LMS_H_TREE_HEIGHT(type))
+#define MERKLE_TREE_INTERNAL_NODE_AM(type) (1u << MBEDTLS_LMS_H_TREE_HEIGHT(type))
#define D_CONST_LEN (2)
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 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],
+static int create_merkle_leaf_value( const mbedtls_lms_parameters_t *params,
+ unsigned char *pub_key,
unsigned int r_node_idx,
- unsigned char out[MBEDTLS_LMS_M_NODE_BYTES] )
+ unsigned char *out )
{
psa_hash_operation_t op;
psa_status_t status;
@@ -90,7 +93,8 @@
if ( ret != 0 )
goto exit;
- status = psa_hash_update( &op, I_key_identifier, MBEDTLS_LMOTS_I_KEY_ID_LEN );
+ status = psa_hash_update( &op, params->I_key_identifier,
+ MBEDTLS_LMOTS_I_KEY_ID_LEN );
ret = mbedtls_lms_error_from_psa( status );
if( ret )
goto exit;
@@ -106,12 +110,14 @@
if( ret )
goto exit;
- status = psa_hash_update( &op, pub_key, MBEDTLS_LMOTS_N_HASH_LEN );
+ status = psa_hash_update( &op, pub_key,
+ MBEDTLS_LMOTS_N_HASH_LEN(params->otstype) );
ret = mbedtls_lms_error_from_psa( status );
if( ret )
goto exit;
- status = psa_hash_finish( &op, out, MBEDTLS_LMS_M_NODE_BYTES, &output_hash_len);
+ status = psa_hash_finish( &op, out, MBEDTLS_LMS_M_NODE_BYTES(params->type),
+ &output_hash_len);
ret = mbedtls_lms_error_from_psa( status );
if( ret )
goto exit;
@@ -122,11 +128,11 @@
return( ret );
}
-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 right_node[MBEDTLS_LMS_M_NODE_BYTES],
+static int create_merkle_internal_value( const mbedtls_lms_parameters_t *params,
+ const unsigned char *left_node,
+ const unsigned char *right_node,
unsigned int r_node_idx,
- unsigned char out[MBEDTLS_LMS_M_NODE_BYTES] )
+ unsigned char *out )
{
psa_hash_operation_t op;
psa_status_t status;
@@ -140,7 +146,8 @@
if ( ret != 0 )
goto exit;
- status = psa_hash_update( &op, I_key_identifier, MBEDTLS_LMOTS_I_KEY_ID_LEN );
+ status = psa_hash_update( &op, params->I_key_identifier,
+ MBEDTLS_LMOTS_I_KEY_ID_LEN );
ret = mbedtls_lms_error_from_psa( status );
if( ret )
goto exit;
@@ -156,17 +163,20 @@
if( ret )
goto exit;
- status = psa_hash_update( &op, left_node, MBEDTLS_LMOTS_N_HASH_LEN );
+ status = psa_hash_update( &op, left_node,
+ MBEDTLS_LMS_M_NODE_BYTES(params->type) );
ret = mbedtls_lms_error_from_psa( status );
if( ret )
goto exit;
- status = psa_hash_update( &op, right_node, MBEDTLS_LMOTS_N_HASH_LEN );
+ status = psa_hash_update( &op, right_node,
+ MBEDTLS_LMS_M_NODE_BYTES(params->type) );
ret = mbedtls_lms_error_from_psa( status );
if( ret )
goto exit;
- ret = psa_hash_finish( &op, out, MBEDTLS_LMS_M_NODE_BYTES, &output_hash_len);
+ ret = psa_hash_finish( &op, out, MBEDTLS_LMS_M_NODE_BYTES(params->type),
+ &output_hash_len);
ret = mbedtls_lms_error_from_psa( status );
if( ret )
goto exit;
@@ -193,7 +203,7 @@
mbedtls_lms_algorithm_type_t type;
mbedtls_lmots_algorithm_type_t otstype;
- if( key_size < MBEDTLS_LMS_PUBLIC_KEY_LEN )
+ if( key_size < MBEDTLS_LMS_PUBLIC_KEY_LEN(ctx->params.type) )
{
return( MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL );
}
@@ -217,7 +227,7 @@
key + MBEDTLS_LMS_PUBLIC_KEY_I_KEY_ID_OFFSET,
MBEDTLS_LMOTS_I_KEY_ID_LEN );
memcpy( ctx->T_1_pub_key, key + MBEDTLS_LMS_PUBLIC_KEY_ROOT_NODE_OFFSET,
- MBEDTLS_LMOTS_N_HASH_LEN );
+ MBEDTLS_LMS_M_NODE_BYTES(ctx->params.type) );
ctx->have_public_key = 1;
@@ -229,8 +239,8 @@
const unsigned char *sig, size_t sig_size )
{
unsigned int q_leaf_identifier;
- unsigned char Kc_candidate_ots_pub_key[MBEDTLS_LMOTS_N_HASH_LEN];
- unsigned char Tc_candidate_root_node[MBEDTLS_LMS_M_NODE_BYTES];
+ unsigned char Kc_candidate_ots_pub_key[MBEDTLS_LMOTS_N_HASH_LEN_MAX];
+ unsigned char Tc_candidate_root_node[MBEDTLS_LMS_M_NODE_BYTES_MAX];
unsigned int height;
unsigned int curr_node_id;
unsigned int parent_node_id;
@@ -244,7 +254,7 @@
return( MBEDTLS_ERR_LMS_BAD_INPUT_DATA );
}
- if( sig_size != MBEDTLS_LMS_SIG_LEN )
+ if( sig_size != MBEDTLS_LMS_SIG_LEN(ctx->params.type, ctx->params.otstype) )
{
return( MBEDTLS_ERR_LMS_BAD_INPUT_DATA );
}
@@ -261,15 +271,16 @@
return( MBEDTLS_ERR_LMS_BAD_INPUT_DATA );
}
- if( network_bytes_to_unsigned_int( MBEDTLS_LMS_TYPE_LEN,
- sig + MBEDTLS_LMS_SIG_TYPE_OFFSET) != MBEDTLS_LMS_SHA256_M32_H10 )
+ if( network_bytes_to_unsigned_int( MBEDTLS_LMOTS_TYPE_LEN,
+ sig + MBEDTLS_LMS_SIG_OTS_SIG_OFFSET + MBEDTLS_LMOTS_SIG_TYPE_OFFSET)
+ != MBEDTLS_LMOTS_SHA256_N32_W8 )
{
return( MBEDTLS_ERR_LMS_VERIFY_FAILED );
}
- if( network_bytes_to_unsigned_int( MBEDTLS_LMOTS_TYPE_LEN,
- sig + MBEDTLS_LMS_SIG_OTS_SIG_OFFSET + MBEDTLS_LMOTS_SIG_TYPE_OFFSET)
- != MBEDTLS_LMOTS_SHA256_N32_W8 )
+ if( network_bytes_to_unsigned_int( MBEDTLS_LMS_TYPE_LEN,
+ sig + MBEDTLS_LMS_SIG_TYPE_OFFSET(ctx->params.otstype))
+ != MBEDTLS_LMS_SHA256_M32_H10 )
{
return( MBEDTLS_ERR_LMS_VERIFY_FAILED );
}
@@ -278,7 +289,7 @@
q_leaf_identifier = network_bytes_to_unsigned_int( MBEDTLS_LMOTS_Q_LEAF_ID_LEN,
sig + MBEDTLS_LMS_SIG_Q_LEAF_ID_OFFSET );
- if( q_leaf_identifier >= MERKLE_TREE_LEAF_NODE_AM )
+ if( q_leaf_identifier >= MERKLE_TREE_LEAF_NODE_AM(ctx->params.type) )
{
return( MBEDTLS_ERR_LMS_VERIFY_FAILED );
}
@@ -293,7 +304,7 @@
ret = mbedtls_lmots_calculate_public_key_candidate( &ots_params, msg, msg_size,
sig + MBEDTLS_LMS_SIG_OTS_SIG_OFFSET,
- MBEDTLS_LMOTS_SIG_LEN,
+ MBEDTLS_LMOTS_SIG_LEN(ctx->params.otstype),
Kc_candidate_ots_pub_key,
sizeof(Kc_candidate_ots_pub_key),
NULL );
@@ -303,37 +314,40 @@
}
create_merkle_leaf_value(
- ctx->params.I_key_identifier,
- Kc_candidate_ots_pub_key, MERKLE_TREE_INTERNAL_NODE_AM + q_leaf_identifier,
+ &ctx->params,
+ Kc_candidate_ots_pub_key,
+ MERKLE_TREE_INTERNAL_NODE_AM(ctx->params.type) + q_leaf_identifier,
Tc_candidate_root_node );
- curr_node_id = MERKLE_TREE_INTERNAL_NODE_AM + q_leaf_identifier;
+ curr_node_id = MERKLE_TREE_INTERNAL_NODE_AM(ctx->params.type) + q_leaf_identifier;
- for( height = 0; height < MBEDTLS_LMS_H_TREE_HEIGHT; height++ )
+ for( height = 0; height < MBEDTLS_LMS_H_TREE_HEIGHT(ctx->params.type);
+ height++ )
{
parent_node_id = curr_node_id / 2;
/* Left/right node ordering matters for the hash */
if( curr_node_id & 1 )
{
- left_node = ( ( const unsigned char( * )[MBEDTLS_LMS_M_NODE_BYTES] )( sig + MBEDTLS_LMS_SIG_PATH_OFFSET ) )[height];
+ left_node = sig + MBEDTLS_LMS_SIG_PATH_OFFSET(ctx->params.otstype) +
+ height * MBEDTLS_LMS_M_NODE_BYTES(ctx->params.type);
right_node = Tc_candidate_root_node;
}
else
{
left_node = Tc_candidate_root_node;
- right_node = ( ( const unsigned char( * )[MBEDTLS_LMS_M_NODE_BYTES] )( sig + MBEDTLS_LMS_SIG_PATH_OFFSET ) )[height];
+ right_node = sig + MBEDTLS_LMS_SIG_PATH_OFFSET(ctx->params.otstype) +
+ height * MBEDTLS_LMS_M_NODE_BYTES(ctx->params.type);
}
- create_merkle_internal_value(
- ctx->params.I_key_identifier,
- left_node, right_node, parent_node_id, Tc_candidate_root_node);
+ create_merkle_internal_value( &ctx->params, left_node, right_node,
+ parent_node_id, Tc_candidate_root_node);
curr_node_id /= 2;
}
if( memcmp( Tc_candidate_root_node, ctx->T_1_pub_key,
- MBEDTLS_LMOTS_N_HASH_LEN) )
+ MBEDTLS_LMS_M_NODE_BYTES(ctx->params.type)) )
{
return( MBEDTLS_ERR_LMS_VERIFY_FAILED );
}
@@ -344,22 +358,22 @@
#ifdef MBEDTLS_LMS_PRIVATE
static int calculate_merkle_tree( mbedtls_lms_private_t *ctx,
- unsigned char tree[MERKLE_TREE_NODE_AM][MBEDTLS_LMS_M_NODE_BYTES] )
+ unsigned char *tree )
{
unsigned int priv_key_idx;
unsigned int r_node_idx;
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
/* First create the leaf nodes, in ascending order */
- for( priv_key_idx = 0; priv_key_idx < MERKLE_TREE_INTERNAL_NODE_AM;
+ for( priv_key_idx = 0;
+ priv_key_idx < MERKLE_TREE_INTERNAL_NODE_AM(ctx->params.type);
priv_key_idx++ )
{
- r_node_idx = MERKLE_TREE_INTERNAL_NODE_AM + priv_key_idx;
+ r_node_idx = MERKLE_TREE_INTERNAL_NODE_AM(ctx->params.type) + priv_key_idx;
- ret = create_merkle_leaf_value(
- ctx->params.I_key_identifier,
- ctx->ots_public_keys[priv_key_idx].public_key,
- r_node_idx, tree[r_node_idx] );
+ ret = create_merkle_leaf_value( &ctx->params,
+ ctx->ots_public_keys[priv_key_idx].public_key, r_node_idx,
+ &tree[r_node_idx * MBEDTLS_LMS_M_NODE_BYTES(ctx->params.type)] );
if( ret )
{
return( ret );
@@ -368,12 +382,14 @@
/* Then the internal nodes, in reverse order so that we can guarantee the
* parent has been created */
- for( r_node_idx = MERKLE_TREE_INTERNAL_NODE_AM - 1; r_node_idx > 0;
+ for( r_node_idx = MERKLE_TREE_INTERNAL_NODE_AM(ctx->params.type) - 1;
+ r_node_idx > 0;
r_node_idx-- )
{
- ret = create_merkle_internal_value(
- ctx->params.I_key_identifier,
- tree[(r_node_idx * 2)], tree[(r_node_idx * 2 + 1)], r_node_idx, tree[r_node_idx] );
+ ret = create_merkle_internal_value( &ctx->params,
+ &tree[(r_node_idx * 2) * MBEDTLS_LMS_M_NODE_BYTES(ctx->params.type)],
+ &tree[(r_node_idx * 2 + 1) * MBEDTLS_LMS_M_NODE_BYTES(ctx->params.type)],
+ r_node_idx, &tree[r_node_idx * MBEDTLS_LMS_M_NODE_BYTES(ctx->params.type)] );
if( ret )
{
return( ret );
@@ -385,25 +401,28 @@
static int get_merkle_path( mbedtls_lms_private_t *ctx,
unsigned int leaf_node_id,
- unsigned char path[MBEDTLS_LMS_H_TREE_HEIGHT][MBEDTLS_LMS_M_NODE_BYTES] )
+ unsigned char *path )
{
- unsigned char tree[MERKLE_TREE_NODE_AM][MBEDTLS_LMS_M_NODE_BYTES];
+ unsigned char tree[MERKLE_TREE_NODE_AM_MAX][MBEDTLS_LMS_M_NODE_BYTES_MAX];
unsigned int curr_node_id = leaf_node_id;
unsigned int adjacent_node_id;
unsigned int height;
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
- ret = calculate_merkle_tree( ctx, tree);
+ ret = calculate_merkle_tree( ctx, (unsigned char *)tree);
if( ret )
{
return( ret );
}
- for( height = 0; height < MBEDTLS_LMS_H_TREE_HEIGHT; height++ )
+ for( height = 0; height < MBEDTLS_LMS_H_TREE_HEIGHT(ctx->params.type);
+ height++ )
{
adjacent_node_id = curr_node_id ^ 1;
- memcpy( &path[height], &tree[adjacent_node_id], MBEDTLS_LMOTS_N_HASH_LEN );
+ memcpy( &path[height * MBEDTLS_LMS_M_NODE_BYTES(ctx->params.type)],
+ &tree[adjacent_node_id],
+ MBEDTLS_LMS_M_NODE_BYTES(ctx->params.type) );
curr_node_id >>=1;
}
@@ -422,7 +441,7 @@
if( ctx->have_private_key )
{
- for( idx = 0; idx < MERKLE_TREE_LEAF_NODE_AM; idx++ )
+ for( idx = 0; idx < MERKLE_TREE_LEAF_NODE_AM(ctx->params.type); idx++ )
{
mbedtls_lmots_free_private( &ctx->ots_private_keys[idx] );
mbedtls_lmots_free_public( &ctx->ots_public_keys[idx] );
@@ -469,30 +488,30 @@
ctx->params.I_key_identifier,
MBEDTLS_LMOTS_I_KEY_ID_LEN );
- ctx->ots_private_keys = mbedtls_calloc( MERKLE_TREE_LEAF_NODE_AM,
- sizeof( mbedtls_lmots_private_t));
+ ctx->ots_private_keys = mbedtls_calloc( MERKLE_TREE_LEAF_NODE_AM(ctx->params.type),
+ sizeof( mbedtls_lmots_private_t));
if( ctx->ots_private_keys == NULL )
{
ret = MBEDTLS_ERR_LMS_ALLOC_FAILED;
goto exit;
}
- ctx->ots_public_keys = mbedtls_calloc( MERKLE_TREE_LEAF_NODE_AM,
- sizeof( mbedtls_lmots_public_t));
+ ctx->ots_public_keys = mbedtls_calloc( MERKLE_TREE_LEAF_NODE_AM(ctx->params.type),
+ sizeof( mbedtls_lmots_public_t));
if( ctx->ots_public_keys == NULL )
{
ret = MBEDTLS_ERR_LMS_ALLOC_FAILED;
goto exit;
}
- for( idx = 0; idx < MERKLE_TREE_LEAF_NODE_AM; idx++ )
+ for( idx = 0; idx < MERKLE_TREE_LEAF_NODE_AM(ctx->params.type); idx++ )
{
mbedtls_lmots_init_private( &ctx->ots_private_keys[idx] );
mbedtls_lmots_init_public( &ctx->ots_public_keys[idx] );
}
- for( idx = 0; idx < MERKLE_TREE_LEAF_NODE_AM; idx++ )
+ for( idx = 0; idx < MERKLE_TREE_LEAF_NODE_AM(ctx->params.type); idx++ )
{
ret = mbedtls_lmots_generate_private_key( &ctx->ots_private_keys[idx],
otstype,
@@ -529,7 +548,7 @@
int mbedtls_lms_calculate_public_key( mbedtls_lms_public_t *ctx,
mbedtls_lms_private_t *priv_ctx )
{
- unsigned char tree[MERKLE_TREE_NODE_AM][MBEDTLS_LMS_M_NODE_BYTES];
+ unsigned char tree[MERKLE_TREE_NODE_AM_MAX][MBEDTLS_LMS_M_NODE_BYTES_MAX];
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
if( ! priv_ctx->MBEDTLS_PRIVATE( have_private_key ) )
@@ -552,14 +571,15 @@
memcpy( &ctx->params, &priv_ctx->params,
sizeof(mbedtls_lmots_parameters_t) );
- ret = calculate_merkle_tree( priv_ctx, tree);
+ ret = calculate_merkle_tree( priv_ctx, (unsigned char *)tree);
if( ret )
{
return( ret );
}
/* Root node is always at position 1, due to 1-based indexing */
- memcpy( ctx->T_1_pub_key, &tree[1], MBEDTLS_LMOTS_N_HASH_LEN );
+ memcpy( ctx->T_1_pub_key, &tree[1],
+ MBEDTLS_LMS_M_NODE_BYTES(ctx->params.type));
ctx->have_public_key = 1;
@@ -570,7 +590,7 @@
int mbedtls_lms_export_public_key( mbedtls_lms_public_t *ctx, unsigned char *key,
size_t key_size, size_t *key_len )
{
- if( key_size < MBEDTLS_LMS_PUBLIC_KEY_LEN ) {
+ if( key_size < MBEDTLS_LMS_PUBLIC_KEY_LEN(ctx->params.type) ) {
return( MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL );
}
@@ -590,10 +610,10 @@
MBEDTLS_LMOTS_I_KEY_ID_LEN );
memcpy( key + MBEDTLS_LMS_PUBLIC_KEY_ROOT_NODE_OFFSET,
ctx->T_1_pub_key,
- MBEDTLS_LMOTS_N_HASH_LEN );
+ MBEDTLS_LMS_M_NODE_BYTES(ctx->params.type) );
if( key_len != NULL ) {
- *key_len = MBEDTLS_LMS_PUBLIC_KEY_LEN;
+ *key_len = MBEDTLS_LMS_PUBLIC_KEY_LEN(ctx->params.type);
}
return( 0 );
@@ -613,7 +633,7 @@
return( MBEDTLS_ERR_LMS_BAD_INPUT_DATA );
}
- if( sig_size < MBEDTLS_LMS_SIG_LEN )
+ if( sig_size < MBEDTLS_LMS_SIG_LEN(ctx->params.type, ctx->params.otstype) )
{
return( MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL );
}
@@ -629,7 +649,7 @@
return( MBEDTLS_ERR_LMS_BAD_INPUT_DATA );
}
- if( ctx->q_next_usable_key >= MERKLE_TREE_LEAF_NODE_AM )
+ if( ctx->q_next_usable_key >= MERKLE_TREE_LEAF_NODE_AM(ctx->params.type) )
{
return( MBEDTLS_ERR_LMS_OUT_OF_PRIVATE_KEYS );
}
@@ -644,26 +664,29 @@
ret = mbedtls_lmots_sign( &ctx->ots_private_keys[q_leaf_identifier],
f_rng, p_rng, msg, msg_size,
sig + MBEDTLS_LMS_SIG_OTS_SIG_OFFSET,
- MBEDTLS_LMS_SIG_LEN, NULL );
+ MBEDTLS_LMS_SIG_LEN(ctx->params.type, ctx->params.otstype),
+ NULL );
if( ret )
{
return( ret );
}
unsigned_int_to_network_bytes( ctx->params.type,
- MBEDTLS_LMS_TYPE_LEN, sig + MBEDTLS_LMS_SIG_TYPE_OFFSET );
+ MBEDTLS_LMS_TYPE_LEN,
+ sig + MBEDTLS_LMS_SIG_TYPE_OFFSET(ctx->params.otstype) );
unsigned_int_to_network_bytes( q_leaf_identifier, MBEDTLS_LMOTS_Q_LEAF_ID_LEN,
sig + MBEDTLS_LMS_SIG_Q_LEAF_ID_OFFSET);
- ret = get_merkle_path( ctx, MERKLE_TREE_INTERNAL_NODE_AM + q_leaf_identifier,
- ( unsigned char( * )[MBEDTLS_LMS_M_NODE_BYTES] )( sig + MBEDTLS_LMS_SIG_PATH_OFFSET ) );
+ ret = get_merkle_path( ctx,
+ MERKLE_TREE_INTERNAL_NODE_AM(ctx->params.type) + q_leaf_identifier,
+ sig + MBEDTLS_LMS_SIG_PATH_OFFSET(ctx->params.otstype) );
if( ret )
{
return( ret );
}
if( sig_len != NULL ) {
- *sig_len = MBEDTLS_LMS_SIG_LEN;
+ *sig_len = MBEDTLS_LMS_SIG_LEN(ctx->params.type, ctx->params.otstype);
}