Update LMS/LMOTS tests
Document tests and source of data, use test RNG, pass more parameters
into each test
Signed-off-by: Raef Coles <raef.coles@arm.com>
diff --git a/tests/suites/test_suite_lms.function b/tests/suites/test_suite_lms.function
index 92a5a07..148075d 100644
--- a/tests/suites/test_suite_lms.function
+++ b/tests/suites/test_suite_lms.function
@@ -1,55 +1,44 @@
/* BEGIN_HEADER */
#include "mbedtls/lms.h"
-#include "mbedtls/entropy.h"
-#include "mbedtls/ctr_drbg.h"
/* END_HEADER */
/* BEGIN_DEPENDENCIES
- * depends_on:MBEDTLS_LMS_C:MBEDTLS_LMS_PRIVATE:MBEDTLS_PSA_CRYPTO_C:MBEDTLS_CTR_DRBG_C
+ * depends_on:MBEDTLS_LMS_C:MBEDTLS_LMS_PRIVATE:MBEDTLS_PSA_CRYPTO_C
* END_DEPENDENCIES
*/
/* BEGIN_CASE */
-void lms_sign_verify_test ( data_t * msg )
+void lms_sign_verify_test ( data_t *msg, data_t *seed )
{
mbedtls_lms_public_t pub_ctx;
mbedtls_lms_private_t priv_ctx;
unsigned char sig[MBEDTLS_LMS_SIG_LEN(MBEDTLS_LMS_SHA256_M32_H10, MBEDTLS_LMOTS_SHA256_N32_W8)];
- mbedtls_entropy_context entropy_ctx;
- mbedtls_ctr_drbg_context drbg_ctx;
- uint8_t seed[16];
int rc;
- mbedtls_entropy_init( &entropy_ctx );
- mbedtls_ctr_drbg_init( &drbg_ctx );
mbedtls_lms_init_public( &pub_ctx );
mbedtls_lms_init_private( &priv_ctx );
- TEST_ASSERT( mbedtls_ctr_drbg_seed( &drbg_ctx, mbedtls_entropy_func,
- &entropy_ctx, ( uint8_t* )"", 0 ) == 0 );
- TEST_ASSERT( mbedtls_ctr_drbg_random( &drbg_ctx, seed, sizeof( seed ) ) == 0 );
-
- /* Allocation failure isn't a test failure, since it likely just means there's not enough memory to run the test */
+ /* Allocation failure isn't a test failure, since it likely just means
+ * there's not enough memory to run the test.
+ */
rc = mbedtls_lms_generate_private_key( &priv_ctx, MBEDTLS_LMS_SHA256_M32_H10,
MBEDTLS_LMOTS_SHA256_N32_W8,
- mbedtls_ctr_drbg_random, &drbg_ctx, seed,
- sizeof( seed ) );
+ mbedtls_test_rnd_std_rand, NULL,
+ seed->x, seed->len );
TEST_ASSUME( rc != MBEDTLS_ERR_LMS_ALLOC_FAILED );
TEST_ASSERT( rc == 0 );
TEST_ASSERT( mbedtls_lms_calculate_public_key( &pub_ctx, &priv_ctx ) == 0 );
- TEST_ASSERT( mbedtls_lms_sign( &priv_ctx, mbedtls_ctr_drbg_random,
- &drbg_ctx, msg->x, msg->len, sig,
- sizeof( sig ), NULL ) == 0 );
+ TEST_ASSERT( mbedtls_lms_sign( &priv_ctx, mbedtls_test_rnd_std_rand, NULL,
+ msg->x, msg->len, sig, sizeof( sig ),
+ NULL ) == 0 );
TEST_ASSERT( mbedtls_lms_verify( &pub_ctx, msg->x, msg->len, sig,
sizeof( sig ) ) == 0 );
exit:
- mbedtls_entropy_free( &entropy_ctx );
- mbedtls_ctr_drbg_free( &drbg_ctx );
mbedtls_lms_free_public( &pub_ctx );
mbedtls_lms_free_private( &priv_ctx );
}