Re-introduction of key slot chekcs

Signed-off-by: TRodziewicz <tomasz.rodziewicz@mobica.com>
This commit is contained in:
TRodziewicz 2021-07-02 18:08:10 +02:00
parent bd3bfbf5c2
commit 053b99b90b
8 changed files with 35 additions and 1 deletions

View File

@ -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
/**

View File

@ -1683,7 +1683,7 @@
*
* Uncomment to enable invasive tests.
*/
//#define MBEDTLS_TEST_HOOKS
#define MBEDTLS_TEST_HOOKS
/**
* \def MBEDTLS_THREADING_ALT

View File

@ -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;
}

View File

@ -34,6 +34,7 @@
#include <stdlib.h>
#include <string.h>
#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 );
}

View File

@ -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 */

View File

@ -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 */

View File

@ -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

View File

@ -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();