Re-introduction of key slot chekcs
Signed-off-by: TRodziewicz <tomasz.rodziewicz@mobica.com>
diff --git a/include/mbedtls/error.h b/include/mbedtls/error.h
index 9a8690d..d2d31a8 100644
--- a/include/mbedtls/error.h
+++ b/include/mbedtls/error.h
@@ -129,6 +129,7 @@
* 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 a60db7e..1ab0ade 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 6e73d12..c7186af 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -1002,6 +1002,10 @@
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 4131e3c..256408d 100644
--- a/library/psa_crypto_slot_management.c
+++ b/library/psa_crypto_slot_management.c
@@ -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 @@
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 3be94bd..c2b4b08 100644
--- a/scripts/data_files/error.fmt
+++ b/scripts/data_files/error.fmt
@@ -164,6 +164,7 @@
#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 27e5599..40fcb03 100644
--- a/tests/include/test/helpers.h
+++ b/tests/include/test/helpers.h
@@ -231,4 +231,13 @@
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 4d3d53d..bf25f21 100644
--- a/tests/src/helpers.c
+++ b/tests/src/helpers.c
@@ -274,3 +274,13 @@
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 52b586e..9ac5a4a 100644
--- a/tests/suites/main_test.function
+++ b/tests/suites/main_test.function
@@ -239,6 +239,7 @@
{
#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();