Skip to content

Commit

Permalink
Move Mbed TLS self tests to a separate configuration
Browse files Browse the repository at this point in the history
There is no point building self tests unless we are testing Mbed TLS,
so unset MBEDTLS_SELF_TEST by default and provide a new
TESTS/configs/mbedtls.json to enable self tests.

In the newly created JSON file we also enable Mbed TLS timing so it
gets tested.
  • Loading branch information
LDong-Arm committed Jun 14, 2021
1 parent d6f825e commit da542bb
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions TESTS/configs/mbedtls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"macros": [
"MBEDTLS_SELF_TEST",
"MBEDTLS_TIMING_C",
"MBEDTLS_TIMING_ALT"
]
}
2 changes: 1 addition & 1 deletion connectivity/mbedtls/include/mbedtls/config-no-entropy.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#define MBEDTLS_PK_RSA_ALT_SUPPORT
#define MBEDTLS_PKCS1_V15
#define MBEDTLS_PKCS1_V21
#define MBEDTLS_SELF_TEST
//#define MBEDTLS_SELF_TEST
#define MBEDTLS_VERSION_FEATURES
#define MBEDTLS_X509_CHECK_KEY_USAGE
#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
Expand Down
2 changes: 1 addition & 1 deletion connectivity/mbedtls/include/mbedtls/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@
*
* Enable the checkup functions (*_self_test).
*/
#define MBEDTLS_SELF_TEST
//#define MBEDTLS_SELF_TEST

/**
* \def MBEDTLS_SHA256_SMALLER
Expand Down
4 changes: 4 additions & 0 deletions connectivity/mbedtls/tests/TESTS/mbedtls/selftest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ using namespace utest::v1;
#include MBEDTLS_CONFIG_FILE
#endif

#if !defined(MBEDTLS_SELF_TEST)
#error [NOT_SUPPORTED] MBEDTLS_SELF_TEST undefined
#endif

#include "mbedtls/sha256.h"
#include "mbedtls/sha512.h"
#include "mbedtls/entropy.h"
Expand Down
3 changes: 3 additions & 0 deletions connectivity/mbedtls/tools/importer/adjust-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ conf unset MBEDTLS_SSL_TRUNCATED_HMAC

conf unset MBEDTLS_PLATFORM_TIME_TYPE_MACRO

# potentially save flash space by not enabling self-tests by default
conf unset MBEDTLS_SELF_TEST

# The default size of MBEDTLS_MPI_MAX_SIZE is 1024 bytes.
# In some cases, this value is set to stack buffers.
# Reduce the maximal MBEDTLS_MPI_MAX_SIZE to 512 bytes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ add_code() {

conf set MBEDTLS_CMAC_C
conf unset MBEDTLS_CIPHER_MODE_XTS

# potentially save flash space by not enabling self-tests by default
conf unset MBEDTLS_SELF_TEST

0 comments on commit da542bb

Please sign in to comment.