From 9fc303a99a151806d2aca629609169cfc920b3d8 Mon Sep 17 00:00:00 2001 From: Raef Coles Date: Wed, 12 Oct 2022 10:32:15 +0100 Subject: [PATCH] Add extra LMOTS import negative tests And fix failures that are related to the new tests Signed-off-by: Raef Coles --- library/lmots.c | 2 +- tests/suites/test_suite_lmots.data | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/library/lmots.c b/library/lmots.c index f19871873d..a172f77d7c 100644 --- a/library/lmots.c +++ b/library/lmots.c @@ -415,7 +415,7 @@ int mbedtls_lmots_import_public_key( mbedtls_lmots_public_t *ctx, mbedtls_lms_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) ) + if( key_len != MBEDTLS_LMOTS_PUBLIC_KEY_LEN(ctx->params.type) ) { return( MBEDTLS_ERR_LMS_BAD_INPUT_DATA ); } diff --git a/tests/suites/test_suite_lmots.data b/tests/suites/test_suite_lmots.data index 3c28df7d05..fdb6e43f22 100644 --- a/tests/suites/test_suite_lmots.data +++ b/tests/suites/test_suite_lmots.data @@ -107,6 +107,33 @@ LMOTS key import / export test # buffer is too small. lmots_import_export_test:"0000000447cc5b29dd0cecd01c382434a6d1686400000001f337dde97685d008a4440b59550277390018d3f1d485fa4b8c91796032de494b":0 +LMOTS key import too large key test +# This test uses the valid public key for hsslms interop test 1, add an extra +# byte, and then imports it. This should fail. +lmots_import_export_test:"0000000447cc5b29dd0cecd01c382434a6d1686400000001f337dde97685d008a4440b59550277390018d3f1d485fa4b8c91796032de494b00":MBEDTLS_ERR_LMS_BAD_INPUT_DATA + +LMOTS key import too small key test +# This test uses the valid public key for hsslms interop test 1, removes a byte, +# and then imports it. This should fail. +lmots_import_export_test:"0000000447cc5b29dd0cecd01c382434a6d1686400000001f337dde97685d008a4440b59550277390018d3f1d485fa4b8c91796032de49":MBEDTLS_ERR_LMS_BAD_INPUT_DATA + +LMOTS key import no type test +# This test uses the valid public key for hsslms interop test 1, cuts it down so +# it's smaller than the LMOTS type offset, and imports it. This should fail, and +# not attempt to read invalidly outside the buffer. +lmots_import_export_test:"000000":MBEDTLS_ERR_LMS_BAD_INPUT_DATA + +LMOTS key import invalid type test #1 +# This test uses the valid public key for hsslms interop test 1, alters the +# LMOTS type to 0x3, and imports it. This should fail. +lmots_import_export_test:"0000000347cc5b29dd0cecd01c382434a6d1686400000001f337dde97685d008a4440b59550277390018d3f1d485fa4b8c91796032de494b":MBEDTLS_ERR_LMS_BAD_INPUT_DATA + +LMOTS key import invalid type test #2 +# This test uses the valid public key for hsslms interop test 1, alters the +# LMOTS type to 0x5, and imports it. This should fail, and not attempt to read +# invalidly outside the buffer. +lmots_import_export_test:"0000000547cc5b29dd0cecd01c382434a6d1686400000001f337dde97685d008a4440b59550277390018d3f1d485fa4b8c91796032de494b":MBEDTLS_ERR_LMS_BAD_INPUT_DATA + LMOTS key reuse test # This test uses a fixed message, and then generates a private key, signs the # message, and then attempts to sign the message again. The second signature