From 053b99b90b243f87dbba5a9ce439fc6499f9ed2d Mon Sep 17 00:00:00 2001 From: TRodziewicz Date: Fri, 2 Jul 2021 18:08:10 +0200 Subject: [PATCH 1/9] Re-introduction of key slot chekcs Signed-off-by: TRodziewicz --- include/mbedtls/error.h | 1 + include/mbedtls/mbedtls_config.h | 2 +- library/psa_crypto.c | 4 ++++ library/psa_crypto_slot_management.c | 8 ++++++++ scripts/data_files/error.fmt | 1 + tests/include/test/helpers.h | 9 +++++++++ tests/src/helpers.c | 10 ++++++++++ tests/suites/main_test.function | 1 + 8 files changed, 35 insertions(+), 1 deletion(-) diff --git a/include/mbedtls/error.h b/include/mbedtls/error.h index 9a8690dc1..d2d31a82a 100644 --- a/include/mbedtls/error.h +++ b/include/mbedtls/error.h @@ -129,6 +129,7 @@ extern "C" { * Only used when invasive testing is enabled via MBEDTLS_TEST_HOOKS. */ extern void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); +extern void (*mbedtls_test_hook_value)( int test, const char * file, int line ); #endif /** diff --git a/include/mbedtls/mbedtls_config.h b/include/mbedtls/mbedtls_config.h index a60db7e93..1ab0aded1 100644 --- a/include/mbedtls/mbedtls_config.h +++ b/include/mbedtls/mbedtls_config.h @@ -1683,7 +1683,7 @@ * * Uncomment to enable invasive tests. */ -//#define MBEDTLS_TEST_HOOKS +#define MBEDTLS_TEST_HOOKS /** * \def MBEDTLS_THREADING_ALT diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 6e73d12c6..c7186af97 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1002,6 +1002,10 @@ psa_status_t psa_wipe_key_slot( psa_key_slot_t *slot ) if( slot->lock_count != 1 ) { +#if defined(MBEDTLS_TEST_HOOKS) + if( *mbedtls_test_hook_value != NULL ) + ( *mbedtls_test_hook_value )( slot->lock_count == 1, __FILE__, __LINE__ ); +#endif status = PSA_ERROR_CORRUPTION_DETECTED; } diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c index 4131e3cc4..256408dfd 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -34,6 +34,7 @@ #include #include +#include "mbedtls/error.h" #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" #else @@ -412,6 +413,13 @@ psa_status_t psa_unlock_key_slot( psa_key_slot_t *slot ) return( PSA_SUCCESS ); } + slot->lock_count = 1; + +#if defined(MBEDTLS_TEST_HOOKS) + if( *mbedtls_test_hook_value != NULL ) + ( *mbedtls_test_hook_value )( slot->lock_count > 0, __FILE__, __LINE__ ); +#endif + return( PSA_ERROR_CORRUPTION_DETECTED ); } diff --git a/scripts/data_files/error.fmt b/scripts/data_files/error.fmt index 3be94bd2c..c2b4b0877 100644 --- a/scripts/data_files/error.fmt +++ b/scripts/data_files/error.fmt @@ -164,6 +164,7 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) #if defined(MBEDTLS_TEST_HOOKS) void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); +void (*mbedtls_test_hook_value)( int, const char *, int ); #endif #endif /* MBEDTLS_ERROR_C || MBEDTLS_ERROR_STRERROR_DUMMY */ diff --git a/tests/include/test/helpers.h b/tests/include/test/helpers.h index 27e5599ed..40fcb03dd 100644 --- a/tests/include/test/helpers.h +++ b/tests/include/test/helpers.h @@ -231,4 +231,13 @@ void mbedtls_test_err_add_check( int high, int low, int mbedtls_test_read_mpi( mbedtls_mpi *X, int radix, const char *s ); #endif /* MBEDTLS_BIGNUM_C */ +/** + * \brief Check value in first parameter. + * + * \note If the check fails, fail the test currently being run. + */ +#if defined(MBEDTLS_TEST_HOOKS) +void mbedtls_test_hook_value_check( int test, const char * file, int line ); +#endif + #endif /* TEST_HELPERS_H */ diff --git a/tests/src/helpers.c b/tests/src/helpers.c index 4d3d53da5..bf25f21ad 100644 --- a/tests/src/helpers.c +++ b/tests/src/helpers.c @@ -274,3 +274,13 @@ int mbedtls_test_read_mpi( mbedtls_mpi *X, int radix, const char *s ) return( mbedtls_mpi_read_string( X, radix, s ) ); } #endif + +#if defined(MBEDTLS_TEST_HOOKS) +void mbedtls_test_hook_value_check( int test, const char * file, int line ) +{ + if ( !test ) + { + mbedtls_test_fail( "Wrong value in test", line, file ); + } +} +#endif diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function index 52b586eaa..9ac5a4a31 100644 --- a/tests/suites/main_test.function +++ b/tests/suites/main_test.function @@ -239,6 +239,7 @@ int main( int argc, const char *argv[] ) { #if defined(MBEDTLS_TEST_HOOKS) && defined (MBEDTLS_ERROR_C) mbedtls_test_hook_error_add = &mbedtls_test_err_add_check; + mbedtls_test_hook_value = &mbedtls_test_hook_value_check; #endif int ret = mbedtls_test_platform_setup(); From d9be65277d84dd2ebcd66976d80984f0310a9def Mon Sep 17 00:00:00 2001 From: TRodziewicz Date: Mon, 5 Jul 2021 15:16:00 +0200 Subject: [PATCH 2/9] Corrections to the new functions names and error message wording Signed-off-by: TRodziewicz --- include/mbedtls/error.h | 2 +- include/mbedtls/mbedtls_config.h | 2 +- library/psa_crypto.c | 4 ++-- library/psa_crypto_slot_management.c | 4 ++-- scripts/data_files/error.fmt | 2 +- tests/include/test/helpers.h | 2 +- tests/src/helpers.c | 4 ++-- tests/suites/main_test.function | 6 +++++- 8 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/mbedtls/error.h b/include/mbedtls/error.h index d2d31a82a..49a641614 100644 --- a/include/mbedtls/error.h +++ b/include/mbedtls/error.h @@ -129,7 +129,7 @@ extern "C" { * Only used when invasive testing is enabled via MBEDTLS_TEST_HOOKS. */ extern void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); -extern void (*mbedtls_test_hook_value)( int test, const char * file, int line ); +extern void (*mbedtls_test_hook_assert_test)( int test, const char * file, int line ); #endif /** diff --git a/include/mbedtls/mbedtls_config.h b/include/mbedtls/mbedtls_config.h index 1ab0aded1..a60db7e93 100644 --- a/include/mbedtls/mbedtls_config.h +++ b/include/mbedtls/mbedtls_config.h @@ -1683,7 +1683,7 @@ * * Uncomment to enable invasive tests. */ -#define MBEDTLS_TEST_HOOKS +//#define MBEDTLS_TEST_HOOKS /** * \def MBEDTLS_THREADING_ALT diff --git a/library/psa_crypto.c b/library/psa_crypto.c index c7186af97..f5a879361 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1003,8 +1003,8 @@ psa_status_t psa_wipe_key_slot( psa_key_slot_t *slot ) if( slot->lock_count != 1 ) { #if defined(MBEDTLS_TEST_HOOKS) - if( *mbedtls_test_hook_value != NULL ) - ( *mbedtls_test_hook_value )( slot->lock_count == 1, __FILE__, __LINE__ ); + if( *mbedtls_test_hook_assert_test != NULL ) + ( *mbedtls_test_hook_assert_test )( slot->lock_count == 1, __FILE__, __LINE__ ); #endif status = PSA_ERROR_CORRUPTION_DETECTED; } diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c index 256408dfd..4a0763f00 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -416,8 +416,8 @@ psa_status_t psa_unlock_key_slot( psa_key_slot_t *slot ) slot->lock_count = 1; #if defined(MBEDTLS_TEST_HOOKS) - if( *mbedtls_test_hook_value != NULL ) - ( *mbedtls_test_hook_value )( slot->lock_count > 0, __FILE__, __LINE__ ); + if( *mbedtls_test_hook_assert_test != NULL ) + ( *mbedtls_test_hook_assert_test )( slot->lock_count > 0, __FILE__, __LINE__ ); #endif return( PSA_ERROR_CORRUPTION_DETECTED ); diff --git a/scripts/data_files/error.fmt b/scripts/data_files/error.fmt index c2b4b0877..8651a7b39 100644 --- a/scripts/data_files/error.fmt +++ b/scripts/data_files/error.fmt @@ -164,7 +164,7 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) #if defined(MBEDTLS_TEST_HOOKS) void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); -void (*mbedtls_test_hook_value)( int, const char *, int ); +void (*mbedtls_test_hook_assert_test)( int, const char *, int ); #endif #endif /* MBEDTLS_ERROR_C || MBEDTLS_ERROR_STRERROR_DUMMY */ diff --git a/tests/include/test/helpers.h b/tests/include/test/helpers.h index 40fcb03dd..8ee699668 100644 --- a/tests/include/test/helpers.h +++ b/tests/include/test/helpers.h @@ -237,7 +237,7 @@ int mbedtls_test_read_mpi( mbedtls_mpi *X, int radix, const char *s ); * \note If the check fails, fail the test currently being run. */ #if defined(MBEDTLS_TEST_HOOKS) -void mbedtls_test_hook_value_check( int test, const char * file, int line ); +void mbedtls_test_assert_test( int test, const char * file, int line ); #endif #endif /* TEST_HELPERS_H */ diff --git a/tests/src/helpers.c b/tests/src/helpers.c index bf25f21ad..e35ed62d6 100644 --- a/tests/src/helpers.c +++ b/tests/src/helpers.c @@ -276,11 +276,11 @@ int mbedtls_test_read_mpi( mbedtls_mpi *X, int radix, const char *s ) #endif #if defined(MBEDTLS_TEST_HOOKS) -void mbedtls_test_hook_value_check( int test, const char * file, int line ) +void mbedtls_test_assert_test( int test, const char * file, int line ) { if ( !test ) { - mbedtls_test_fail( "Wrong value in test", line, file ); + mbedtls_test_fail( "Test hook - test assertion failed.", line, file ); } } #endif diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function index 9ac5a4a31..f34c1bd2f 100644 --- a/tests/suites/main_test.function +++ b/tests/suites/main_test.function @@ -239,9 +239,13 @@ int main( int argc, const char *argv[] ) { #if defined(MBEDTLS_TEST_HOOKS) && defined (MBEDTLS_ERROR_C) mbedtls_test_hook_error_add = &mbedtls_test_err_add_check; - mbedtls_test_hook_value = &mbedtls_test_hook_value_check; #endif +#if defined(MBEDTLS_TEST_HOOKS) + mbedtls_test_hook_assert_test = &mbedtls_test_assert_test; +#endif + + int ret = mbedtls_test_platform_setup(); if( ret != 0 ) { From 5f58dfc9d94d1615c45fa2d24050cbc6abd7843f Mon Sep 17 00:00:00 2001 From: TRodziewicz Date: Mon, 5 Jul 2021 15:33:27 +0200 Subject: [PATCH 3/9] Addition of the changelog file. Signed-off-by: TRodziewicz --- ChangeLog.d/issue4680.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 ChangeLog.d/issue4680.txt diff --git a/ChangeLog.d/issue4680.txt b/ChangeLog.d/issue4680.txt new file mode 100644 index 000000000..e37e4142c --- /dev/null +++ b/ChangeLog.d/issue4680.txt @@ -0,0 +1,2 @@ +Changes + * Re-introduce extended checks for psa unlock/wipe key slot. Fixes #4680. From 7871c2e736eae72a92d2260259dcf41d3c282e80 Mon Sep 17 00:00:00 2001 From: TRodziewicz Date: Wed, 7 Jul 2021 17:29:43 +0200 Subject: [PATCH 4/9] Adding new macro for tests failing Signed-off-by: TRodziewicz --- ChangeLog.d/issue4680.txt | 2 -- include/mbedtls/error.h | 2 +- library/common.h | 13 +++++++++++++ library/psa_crypto.c | 5 +---- library/psa_crypto_slot_management.c | 9 +-------- scripts/data_files/error.fmt | 2 +- tests/include/test/helpers.h | 9 --------- tests/src/helpers.c | 10 ---------- tests/suites/main_test.function | 3 +-- 9 files changed, 18 insertions(+), 37 deletions(-) delete mode 100644 ChangeLog.d/issue4680.txt diff --git a/ChangeLog.d/issue4680.txt b/ChangeLog.d/issue4680.txt deleted file mode 100644 index e37e4142c..000000000 --- a/ChangeLog.d/issue4680.txt +++ /dev/null @@ -1,2 +0,0 @@ -Changes - * Re-introduce extended checks for psa unlock/wipe key slot. Fixes #4680. diff --git a/include/mbedtls/error.h b/include/mbedtls/error.h index 49a641614..f00b4f5b2 100644 --- a/include/mbedtls/error.h +++ b/include/mbedtls/error.h @@ -129,7 +129,7 @@ extern "C" { * Only used when invasive testing is enabled via MBEDTLS_TEST_HOOKS. */ extern void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); -extern void (*mbedtls_test_hook_assert_test)( int test, const char * file, int line ); +extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const char * file ); #endif /** diff --git a/library/common.h b/library/common.h index a2c8a1e72..9e4b0312b 100644 --- a/library/common.h +++ b/library/common.h @@ -46,6 +46,19 @@ #define MBEDTLS_STATIC_TESTABLE static #endif +#if defined(MBEDTLS_TEST_HOOKS) +extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const char * file ); +#define MBEDTLS_TEST_HOOK_TEST_ASSERT( TEST ) \ + do { \ + if( ( ! ( TEST ) ) && ( ( *mbedtls_test_hook_test_fail ) != NULL ) ) \ + { \ + ( *mbedtls_test_hook_test_fail )( #TEST, __LINE__, __FILE__ ); \ + } \ + } while( 0 ) +#else +#define MBEDTLS_TEST_HOOK_TEST_ASSERT( TEST ) +#endif /* defined(MBEDTLS_TEST_HOOKS) */ + /** Allow library to access its structs' private members. * * Although structs defined in header files are publicly available, diff --git a/library/psa_crypto.c b/library/psa_crypto.c index f5a879361..8312c0750 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1002,10 +1002,7 @@ psa_status_t psa_wipe_key_slot( psa_key_slot_t *slot ) if( slot->lock_count != 1 ) { -#if defined(MBEDTLS_TEST_HOOKS) - if( *mbedtls_test_hook_assert_test != NULL ) - ( *mbedtls_test_hook_assert_test )( slot->lock_count == 1, __FILE__, __LINE__ ); -#endif + MBEDTLS_TEST_HOOK_TEST_ASSERT( slot->lock_count == 1 ); status = PSA_ERROR_CORRUPTION_DETECTED; } diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c index 4a0763f00..cb10f6e06 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -34,7 +34,6 @@ #include #include -#include "mbedtls/error.h" #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" #else @@ -413,13 +412,7 @@ psa_status_t psa_unlock_key_slot( psa_key_slot_t *slot ) return( PSA_SUCCESS ); } - slot->lock_count = 1; - -#if defined(MBEDTLS_TEST_HOOKS) - if( *mbedtls_test_hook_assert_test != NULL ) - ( *mbedtls_test_hook_assert_test )( slot->lock_count > 0, __FILE__, __LINE__ ); -#endif - + MBEDTLS_TEST_HOOK_TEST_ASSERT( slot->lock_count > 0 ); return( PSA_ERROR_CORRUPTION_DETECTED ); } diff --git a/scripts/data_files/error.fmt b/scripts/data_files/error.fmt index 8651a7b39..fd491b858 100644 --- a/scripts/data_files/error.fmt +++ b/scripts/data_files/error.fmt @@ -164,7 +164,7 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) #if defined(MBEDTLS_TEST_HOOKS) void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); -void (*mbedtls_test_hook_assert_test)( int, const char *, int ); +void (*mbedtls_test_hook_test_fail)( const char *, int, const char *); #endif #endif /* MBEDTLS_ERROR_C || MBEDTLS_ERROR_STRERROR_DUMMY */ diff --git a/tests/include/test/helpers.h b/tests/include/test/helpers.h index 8ee699668..27e5599ed 100644 --- a/tests/include/test/helpers.h +++ b/tests/include/test/helpers.h @@ -231,13 +231,4 @@ void mbedtls_test_err_add_check( int high, int low, int mbedtls_test_read_mpi( mbedtls_mpi *X, int radix, const char *s ); #endif /* MBEDTLS_BIGNUM_C */ -/** - * \brief Check value in first parameter. - * - * \note If the check fails, fail the test currently being run. - */ -#if defined(MBEDTLS_TEST_HOOKS) -void mbedtls_test_assert_test( int test, const char * file, int line ); -#endif - #endif /* TEST_HELPERS_H */ diff --git a/tests/src/helpers.c b/tests/src/helpers.c index e35ed62d6..4d3d53da5 100644 --- a/tests/src/helpers.c +++ b/tests/src/helpers.c @@ -274,13 +274,3 @@ int mbedtls_test_read_mpi( mbedtls_mpi *X, int radix, const char *s ) return( mbedtls_mpi_read_string( X, radix, s ) ); } #endif - -#if defined(MBEDTLS_TEST_HOOKS) -void mbedtls_test_assert_test( int test, const char * file, int line ) -{ - if ( !test ) - { - mbedtls_test_fail( "Test hook - test assertion failed.", line, file ); - } -} -#endif diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function index f34c1bd2f..3044bed35 100644 --- a/tests/suites/main_test.function +++ b/tests/suites/main_test.function @@ -242,10 +242,9 @@ int main( int argc, const char *argv[] ) #endif #if defined(MBEDTLS_TEST_HOOKS) - mbedtls_test_hook_assert_test = &mbedtls_test_assert_test; + mbedtls_test_hook_test_fail = &mbedtls_test_fail; #endif - int ret = mbedtls_test_platform_setup(); if( ret != 0 ) { From 18cddc08c748c5e4ff839a93dd245bd63204a7c3 Mon Sep 17 00:00:00 2001 From: TRodziewicz Date: Tue, 13 Jul 2021 12:19:15 +0200 Subject: [PATCH 5/9] Reverting comments deleted in previous PR Signed-off-by: TRodziewicz --- library/psa_crypto.c | 7 +++++++ library/psa_crypto_slot_management.c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 8312c0750..a8f36745c 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1000,6 +1000,13 @@ psa_status_t psa_wipe_key_slot( psa_key_slot_t *slot ) { psa_status_t status = psa_remove_key_data_from_memory( slot ); + /* + * As the return error code may not be handled in case of multiple errors, + * do our best to report an unexpected lock counter: if available call + * MBEDTLS_TEST_HOOK_TEST_ASSERT that may terminate execution (if called as + * part of the execution of a test suite this will stop the test suite + * execution). + */ if( slot->lock_count != 1 ) { MBEDTLS_TEST_HOOK_TEST_ASSERT( slot->lock_count == 1 ); diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c index cb10f6e06..49e6b873b 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -412,6 +412,13 @@ psa_status_t psa_unlock_key_slot( psa_key_slot_t *slot ) return( PSA_SUCCESS ); } + /* + * As the return error code may not be handled in case of multiple errors, + * do our best to report if the lock counter is equal to zero: if available + * call MBEDTLS_TEST_HOOK_TEST_ASSERT that may terminate execution (if called + * as part of the execution of a unit test suite this will stop the test + * suite execution). + */ MBEDTLS_TEST_HOOK_TEST_ASSERT( slot->lock_count > 0 ); return( PSA_ERROR_CORRUPTION_DETECTED ); } From 829fe7038d69811e7e126c56ed5e89625eaf2202 Mon Sep 17 00:00:00 2001 From: TRodziewicz Date: Tue, 13 Jul 2021 12:23:12 +0200 Subject: [PATCH 6/9] Correction to callback declaration and usage Signed-off-by: TRodziewicz --- library/platform_util.c | 5 +++++ scripts/data_files/error.fmt | 1 - tests/suites/main_test.function | 7 +++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/library/platform_util.c b/library/platform_util.c index 4e97e4d1b..3d5cb5baa 100644 --- a/library/platform_util.c +++ b/library/platform_util.c @@ -131,3 +131,8 @@ struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt, #endif /* _WIN32 && !EFIX64 && !EFI32 */ } #endif /* MBEDTLS_HAVE_TIME_DATE && MBEDTLS_PLATFORM_GMTIME_R_ALT */ + +#if defined(MBEDTLS_TEST_HOOKS) +void (*mbedtls_test_hook_test_fail)( const char *, int, const char *); +#endif /* MBEDTLS_TEST_HOOKS */ + diff --git a/scripts/data_files/error.fmt b/scripts/data_files/error.fmt index fd491b858..3be94bd2c 100644 --- a/scripts/data_files/error.fmt +++ b/scripts/data_files/error.fmt @@ -164,7 +164,6 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) #if defined(MBEDTLS_TEST_HOOKS) void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); -void (*mbedtls_test_hook_test_fail)( const char *, int, const char *); #endif #endif /* MBEDTLS_ERROR_C || MBEDTLS_ERROR_STRERROR_DUMMY */ diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function index 3044bed35..80c730b8a 100644 --- a/tests/suites/main_test.function +++ b/tests/suites/main_test.function @@ -237,12 +237,11 @@ $platform_code */ int main( int argc, const char *argv[] ) { -#if defined(MBEDTLS_TEST_HOOKS) && defined (MBEDTLS_ERROR_C) - mbedtls_test_hook_error_add = &mbedtls_test_err_add_check; -#endif - #if defined(MBEDTLS_TEST_HOOKS) mbedtls_test_hook_test_fail = &mbedtls_test_fail; +#if defined(MBEDTLS_ERROR_C) + mbedtls_test_hook_error_add = &mbedtls_test_err_add_check; +#endif #endif int ret = mbedtls_test_platform_setup(); From c9890e9a8c42251c4d3fac389d7833bf364064ce Mon Sep 17 00:00:00 2001 From: TRodziewicz Date: Wed, 14 Jul 2021 10:16:26 +0200 Subject: [PATCH 7/9] Rewording comments Signed-off-by: TRodziewicz --- library/psa_crypto.c | 9 +++++---- library/psa_crypto_slot_management.c | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index a8f36745c..3574b9842 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1002,10 +1002,11 @@ psa_status_t psa_wipe_key_slot( psa_key_slot_t *slot ) /* * As the return error code may not be handled in case of multiple errors, - * do our best to report an unexpected lock counter: if available call - * MBEDTLS_TEST_HOOK_TEST_ASSERT that may terminate execution (if called as - * part of the execution of a test suite this will stop the test suite - * execution). + * do our best to report an unexpected lock counter. Assert with + * MBEDTLS_TEST_HOOK_TEST_ASSERT that the lock counter is equal to one: + * if the MBEDTLS_TEST_HOOKS configuration option is enabled and the + * function is called as part of the execution of a test suite, the + * execution of the test suite is stopped in error if the assertion fails. */ if( slot->lock_count != 1 ) { diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c index 49e6b873b..a5c43b1b2 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -414,10 +414,11 @@ psa_status_t psa_unlock_key_slot( psa_key_slot_t *slot ) /* * As the return error code may not be handled in case of multiple errors, - * do our best to report if the lock counter is equal to zero: if available - * call MBEDTLS_TEST_HOOK_TEST_ASSERT that may terminate execution (if called - * as part of the execution of a unit test suite this will stop the test - * suite execution). + * do our best to report if the lock counter is equal to zero. Assert with + * MBEDTLS_TEST_HOOK_TEST_ASSERT that the lock counter is strictly greater + * than zero: if the MBEDTLS_TEST_HOOKS configuration option is enabled and + * the function is called as part of the execution of a test suite, the + * execution of the test suite is stopped in error if the assertion fails. */ MBEDTLS_TEST_HOOK_TEST_ASSERT( slot->lock_count > 0 ); return( PSA_ERROR_CORRUPTION_DETECTED ); From 12c77410eb9a97b123af3bab531f02893cf8ca29 Mon Sep 17 00:00:00 2001 From: TRodziewicz Date: Thu, 15 Jul 2021 16:12:54 +0200 Subject: [PATCH 8/9] Removing unneded extern declaration of a callback and including common.h where the cb is needed Signed-off-by: TRodziewicz --- include/mbedtls/error.h | 1 - tests/suites/main_test.function | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mbedtls/error.h b/include/mbedtls/error.h index f00b4f5b2..9a8690dc1 100644 --- a/include/mbedtls/error.h +++ b/include/mbedtls/error.h @@ -129,7 +129,6 @@ extern "C" { * Only used when invasive testing is enabled via MBEDTLS_TEST_HOOKS. */ extern void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); -extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const char * file ); #endif /** diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function index 80c730b8a..6a87e8099 100644 --- a/tests/suites/main_test.function +++ b/tests/suites/main_test.function @@ -24,6 +24,7 @@ #endif #include "mbedtls/build_info.h" +#include "common.h" /* Test code may use deprecated identifiers only if the preprocessor symbol * MBEDTLS_TEST_DEPRECATED is defined. When building tests, set From 3daaea858b7f7385b737dbce834c3314710397bf Mon Sep 17 00:00:00 2001 From: TRodziewicz Date: Tue, 20 Jul 2021 13:36:16 +0200 Subject: [PATCH 9/9] Changing the places of the mbedtls_test_hook_test_fail callback declaration Signed-off-by: TRodziewicz --- tests/suites/main_test.function | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function index 6a87e8099..e01686534 100644 --- a/tests/suites/main_test.function +++ b/tests/suites/main_test.function @@ -24,7 +24,6 @@ #endif #include "mbedtls/build_info.h" -#include "common.h" /* Test code may use deprecated identifiers only if the preprocessor symbol * MBEDTLS_TEST_DEPRECATED is defined. When building tests, set @@ -239,6 +238,7 @@ $platform_code int main( int argc, const char *argv[] ) { #if defined(MBEDTLS_TEST_HOOKS) + extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const char * file ); mbedtls_test_hook_test_fail = &mbedtls_test_fail; #if defined(MBEDTLS_ERROR_C) mbedtls_test_hook_error_add = &mbedtls_test_err_add_check;