Merge pull request #9445 from ronald-cron-arm/tf-psa-crypto-cmake-build
Add crypto only CMake build system
diff --git a/.mypy.ini b/.mypy.ini
index 6b831dd..f727cc2 100644
--- a/.mypy.ini
+++ b/.mypy.ini
@@ -1,4 +1,4 @@
[mypy]
-mypy_path = scripts
+mypy_path = framework/scripts:scripts
namespace_packages = True
warn_unused_configs = True
diff --git a/.pylintrc b/.pylintrc
index f395fb9..f9c97d5 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -1,5 +1,5 @@
[MASTER]
-init-hook='import sys; sys.path.append("scripts")'
+init-hook='import sys; sys.path.append("scripts"); sys.path.append("framework/scripts")'
min-similarity-lines=10
[BASIC]
diff --git a/docs/proposed/Makefile b/docs/proposed/Makefile
index 1c31464..7f5254f 100644
--- a/docs/proposed/Makefile
+++ b/docs/proposed/Makefile
@@ -3,6 +3,7 @@
default: all
all_markdown = \
+ config-split.md \
psa-conditional-inclusion-c.md \
psa-driver-developer-guide.md \
psa-driver-integration-guide.md \
diff --git a/docs/proposed/config-split.md b/docs/proposed/config-split.md
new file mode 100644
index 0000000..fd8a8c7
--- /dev/null
+++ b/docs/proposed/config-split.md
@@ -0,0 +1,468 @@
+Configuration file split
+========================
+
+## Why split the configuration file?
+
+The objective of the repository split is to reach the point where in Mbed TLS
+all the cryptography code and its tests are located in a `tf-psa-crypto`
+directory that just contains the TF-PSA-Crypto repository as a submodule.
+The cryptography APIs exposed by Mbed TLS are just the TF-PSA-Crypto ones.
+Mbed TLS relies solely on the TF-PSA-Crypto build system to build its
+cryptography library and its tests.
+
+The TF-PSA-Crypto configuration file `tf_psa_crypto_config.h` configures
+entirely the cryptography interface exposed by Mbed TLS through TF-PSA-Crypto.
+Mbed TLS configuration is split in two files: `mbedtls_config.h` for TLS and
+x509, `tf_psa_crypto_config.h` for the cryptography.
+
+## How do we split the configuration file?
+
+We extend the so-called PSA cryptographic configuration scheme based on
+`mbedtls_config.h` and `crypto_config.h`. The configuration file `crypto_config.h`
+is extended to become the TF-PSA-Crypto configuration file, `mbedtls_config.h`
+becomes the configuration file for the TLS and x509 libraries. All the options
+to select the cryptographic mechanisms and to configure their implementation
+are moved from `mbedtls_config.h` to `(tf_psa_)crypto_config.h`.
+
+The configuration options that are relevant to both Mbed TLS and TF-PSA-Crypto
+like platform or system ones are moved to `(tf_psa_)crypto_config.h`. That way
+they are available in both repositories (as Mbed TLS includes
+`tf_psa_crypto_config.h`) without duplication. Later, we may duplicate or
+create aliases for some of them to align with the naming conventions of the
+repositories.
+
+The cryptographic configuration options in `tf_psa_crypto_config.h` are
+organized into sections that are different from the ones in the pre-split
+`mbedtls_config.h` (see below). This is first to take into account the
+specifics of TF-PSA-Crypto, for example a specific section for the
+configuration of builtin drivers. We also get rid of the grouping of non
+boolean options into a dedicated section: related boolean and non boolean
+configuration options are rather grouped together into the same section.
+
+Finally, for consistency, the sections in `mbedtls_config.h` are reorganized
+to be better aligned with the `tf_psa_crypto_config.h` ones.
+
+
+## Configuration files and `config.py`
+
+Each repository contains a `config.py` script to create and modify
+configurations.
+
+In Mbed TLS, `config.py` handles both `mbedtls_config.h` and
+`tf_psa_crypto_config.h`. It can set or unset TLS, x509 and cryptographic
+configuration options without having to specify the configuration file the
+options belong to. Commands like full and baremetal affect both configuration
+files.
+
+In TF-PSA-Crypto, `config.py` addresses only `tf_psa_crypto_config.h`.
+
+## Sections in `tf_psa_crypto_config.h`
+
+The `tf_psa_crypto_config.h` configuration file is organized into eight
+sections.
+
+The pre-split `mbedtls_config.h` configuration file contains configuration
+options that apply to the whole code base (TLS, x509, crypto and tests) mostly
+related to the platform abstraction layer and testing. In
+`tf_psa_crypto_config.h` these configurations options are organized into two
+sections, one for the platform abstraction layer options and one for the others,
+respectively named ["Platform abstraction layer"](#section-platform-abstraction-layer)
+and ["General and test configuration options"](#section-general-and-test-configuration-options).
+
+Then, the ["Cryptographic mechanism selection (PSA API)"](#section-cryptographic-mechanism-selection-PSA-API)
+section is the equivalent of the pre-split `crypto_config.h` configuration file
+containing the PSA_WANT_ prefixed macros.
+
+The following section named
+["Cryptographic mechanism selection (extended API)"](#section-cryptographic-mechanism-selection-extended-API)
+contains the configuration options for the cryptography mechanisms that are not
+yet part of the PSA cryptography API (like LMS or PK).
+
+It is followed by the ["Data format support"](#section-data-format-support)
+section that contains configuration options of utilities related to various data
+formats (like Base64 or ASN.1 APIs). These utilities aim to facilitate the
+usage of the PSA cryptography API in other cryptography projects.
+
+Compared to Mbed TLS, the cryptography code in TF-PSA-Crypto is not located
+in a single directory but split between the PSA core (core directory) and the
+PSA builtin drivers (drivers/builtin/src directory). This is reflected in
+`tf_psa_crypto_config.h` with two sections respectively named ["PSA core"](#section-psa-core)
+and ["Builtin drivers"](#section-builtin-drivers).
+
+Finally, the last section named ["Legacy cryptography"](#section-legacy-cryptography)
+contains the configuration options that will eventually be removed as duplicates
+of PSA_WANT_\* and MBEDTLS_PSA_ACCEL_\* configuration options.
+
+## Sections in `mbedtls_config.h`
+
+The sections in `mbedtls_config.h` are reorganized to be better aligned with
+the ones in `tf_psa_crypto_config.h`. The main change is the reorganization
+of the "Mbed TLS modules", "Mbed TLS feature support" and
+"Module configuration options" sections into the
+["TLS feature selection"](#section-tls-feature-selection) and
+["X.509 feature selection"](#section-x-509-feature-selection) sections. That
+way all TLS/x509 options are grouped into one section and there is no
+section dedicated to non boolean configuration options anymore.
+
+
+## Repartition of the configuration options
+
+### In `tf_psa_crypto_config.h`, we have:
+#### SECTION Platform abstraction layer
+```
+#define MBEDTLS_FS_IO
+#define MBEDTLS_HAVE_TIME
+#define MBEDTLS_HAVE_TIME_DATE
+//#define MBEDTLS_MEMORY_BACKTRACE
+//#define MBEDTLS_MEMORY_DEBUG
+#define MBEDTLS_PLATFORM_C
+//#define MBEDTLS_PLATFORM_EXIT_ALT
+//#define MBEDTLS_PLATFORM_FPRINTF_ALT
+//#define MBEDTLS_PLATFORM_GMTIME_R_ALT
+//#define MBEDTLS_PLATFORM_MEMORY
+//#define MBEDTLS_PLATFORM_MS_TIME_ALT
+//#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
+//#define MBEDTLS_PLATFORM_NV_SEED_ALT
+//#define MBEDTLS_PLATFORM_PRINTF_ALT
+//#define MBEDTLS_PLATFORM_SETBUF_ALT
+//#define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT
+//#define MBEDTLS_PLATFORM_SNPRINTF_ALT
+//#define MBEDTLS_PLATFORM_TIME_ALT
+//#define MBEDTLS_PLATFORM_VSNPRINTF_ALT
+//#define MBEDTLS_PLATFORM_ZEROIZE_ALT
+//#define MBEDTLS_THREADING_ALT
+//#define MBEDTLS_THREADING_C
+//#define MBEDTLS_THREADING_PTHREAD
+
+//#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4
+//#define MBEDTLS_PLATFORM_CALLOC_MACRO calloc
+//#define MBEDTLS_PLATFORM_EXIT_MACRO exit
+//#define MBEDTLS_PLATFORM_FREE_MACRO free
+//#define MBEDTLS_PLATFORM_FPRINTF_MACRO fprintf
+//#define MBEDTLS_PLATFORM_MS_TIME_TYPE_MACRO int64_t
+//#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_platform_std_nv_seed_read
+//#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_platform_std_nv_seed_write
+//#define MBEDTLS_PLATFORM_PRINTF_MACRO printf
+//#define MBEDTLS_PLATFORM_SETBUF_MACRO setbuf
+//#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf
+//#define MBEDTLS_PLATFORM_STD_CALLOC calloc
+//#define MBEDTLS_PLATFORM_STD_EXIT exit
+//#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE 1
+//#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS 0
+//#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf
+//#define MBEDTLS_PLATFORM_STD_FREE free
+//#define MBEDTLS_PLATFORM_STD_MEM_HDR <stdlib.h>
+//#define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile"
+//#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read
+//#define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write
+//#define MBEDTLS_PLATFORM_STD_PRINTF printf
+//#define MBEDTLS_PLATFORM_STD_SETBUF setbuf
+//#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf
+//#define MBEDTLS_PLATFORM_STD_TIME time
+//#define MBEDTLS_PLATFORM_TIME_MACRO time
+//#define MBEDTLS_PLATFORM_TIME_TYPE_MACRO time_t
+//#define MBEDTLS_PLATFORM_VSNPRINTF_MACRO vsnprintf
+//#define MBEDTLS_PRINTF_MS_TIME PRId64
+```
+
+#### SECTION General and test configuration options
+Note: for consistency with the configuration file name change from
+`crypto_config.h` to `tf_psa_crypto_config.h`, the configuration options
+`MBEDTLS_PSA_CRYPTO_CONFIG_FILE` and `MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE` are
+respectively renamed `TF_PSA_CRYPTO_CONFIG_FILE` and
+`TF_PSA_CRYPTO_USER_CONFIG_FILE`. These are the only configuration options
+renamed by this document.
+```
+//#define MBEDTLS_CHECK_RETURN_WARNING
+//#define MBEDTLS_DEPRECATED_REMOVED
+//#define MBEDTLS_DEPRECATED_WARNING
+#define MBEDTLS_SELF_TEST
+//#define MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
+//#define MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
+//#define MBEDTLS_TEST_HOOKS
+
+//#define MBEDTLS_CHECK_RETURN __attribute__((__warn_unused_result__))
+//#define MBEDTLS_IGNORE_RETURN( result ) ((void) !(result))
+//#define TF_PSA_CRYPTO_CONFIG_FILE "psa/tf_psa_crypto_config.h"
+//#define TF_PSA_CRYPTO_USER_CONFIG_FILE "/dev/null"
+```
+
+#### SECTION Cryptographic mechanism selection (PSA API)
+PSA_WANT_\* macros as in current `crypto_config.h`.
+
+
+#### SECTION Cryptographic mechanism selection (extended API)
+```
+#define MBEDTLS_LMS_C
+//#define MBEDTLS_LMS_PRIVATE
+#define MBEDTLS_MD_C
+#define MBEDTLS_NIST_KW_C
+#define MBEDTLS_PKCS5_C
+#define MBEDTLS_PKCS12_C
+#define MBEDTLS_PK_C
+#define MBEDTLS_PK_PARSE_C
+#define MBEDTLS_PK_PARSE_EC_COMPRESSED
+#define MBEDTLS_PK_PARSE_EC_EXTENDED
+#define MBEDTLS_PK_RSA_ALT_SUPPORT
+#define MBEDTLS_PK_WRITE_C
+
+//#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48
+//#define MBEDTLS_CTR_DRBG_MAX_INPUT 256
+//#define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024
+//#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384
+//#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
+//#define MBEDTLS_HMAC_DRBG_MAX_INPUT 256
+//#define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024
+//#define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384
+//#define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000
+//#define MBEDTLS_PSA_HMAC_DRBG_MD_TYPE MBEDTLS_MD_SHA256
+```
+
+
+#### SECTION Data format support
+```
+#define MBEDTLS_ASN1_PARSE_C
+#define MBEDTLS_ASN1_WRITE_C
+#define MBEDTLS_BASE64_C
+#define MBEDTLS_OID_C
+#define MBEDTLS_PEM_PARSE_C
+#define MBEDTLS_PEM_WRITE_C
+```
+
+
+#### SECTION PSA core
+```
+#define MBEDTLS_ENTROPY_C
+//#define MBEDTLS_ENTROPY_FORCE_SHA256
+//#define MBEDTLS_ENTROPY_HARDWARE_ALT
+//#define MBEDTLS_ENTROPY_NV_SEED
+//#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
+//#define MBEDTLS_NO_PLATFORM_ENTROPY
+//#define MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
+//#define MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
+#define MBEDTLS_PSA_CRYPTO_C
+//#define MBEDTLS_PSA_CRYPTO_CLIENT
+//#define MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
+//#define MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
+//#define MBEDTLS_PSA_CRYPTO_SPM
+#define MBEDTLS_PSA_CRYPTO_STORAGE_C
+//#define MBEDTLS_PSA_INJECT_ENTROPY
+#define MBEDTLS_PSA_ITS_FILE_C
+
+//#define MBEDTLS_ENTROPY_MAX_GATHER 128
+//#define MBEDTLS_ENTROPY_MAX_SOURCES 20
+//#define MBEDTLS_ENTROPY_MIN_HARDWARE 32
+//#define MBEDTLS_PSA_CRYPTO_PLATFORM_FILE "psa/crypto_platform_alt.h"
+//#define MBEDTLS_PSA_CRYPTO_STRUCT_FILE "psa/crypto_struct_alt.h"
+//#define MBEDTLS_PSA_KEY_SLOT_COUNT 32
+```
+
+#### SECTION Builtin drivers
+```
+#define MBEDTLS_AESCE_C
+#define MBEDTLS_AESNI_C
+//#define MBEDTLS_AES_FEWER_TABLES
+//#define MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
+//#define MBEDTLS_AES_ROM_TABLES
+//#define MBEDTLS_AES_USE_HARDWARE_ONLY
+//#define MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
+//#define MBEDTLS_CAMELLIA_SMALL_MEMORY
+//#define MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
+#define MBEDTLS_ECP_NIST_OPTIM
+//#define MBEDTLS_ECP_RESTARTABLE
+//#define MBEDTLS_ECP_WITH_MPI_UINT
+//#define MBEDTLS_GCM_LARGE_TABLE
+#define MBEDTLS_HAVE_ASM
+//#define MBEDTLS_HAVE_SSE2
+//#define MBEDTLS_NO_UDBL_DIVISION
+//#define MBEDTLS_NO_64BIT_MULTIPLICATION
+//#define MBEDTLS_PSA_P256M_DRIVER_ENABLED
+//#define MBEDTLS_RSA_NO_CRT
+//#define MBEDTLS_SHA256_SMALLER
+//#define MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
+//#define MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
+//#define MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
+//#define MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
+//#define MBEDTLS_SHA512_SMALLER
+//#define MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
+//#define MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
+//#define MBEDTLS_USE_PSA_CRYPTO
+
+//#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1
+//#define MBEDTLS_ECP_WINDOW_SIZE 4
+//#define MBEDTLS_MPI_MAX_SIZE 1024
+//#define MBEDTLS_MPI_WINDOW_SIZE 2
+//#define MBEDTLS_RSA_GEN_KEY_MIN_BITS 1024
+```
+
+
+#### SECTION Legacy cryptography
+```
+#define MBEDTLS_AES_C
+#define MBEDTLS_ARIA_C
+#define MBEDTLS_BIGNUM_C
+#define MBEDTLS_CAMELLIA_C
+#define MBEDTLS_CCM_C
+#define MBEDTLS_CHACHA20_C
+#define MBEDTLS_CHACHAPOLY_C
+#define MBEDTLS_CIPHER_C
+#define MBEDTLS_CIPHER_MODE_CBC
+#define MBEDTLS_CIPHER_MODE_CFB
+#define MBEDTLS_CIPHER_MODE_CTR
+#define MBEDTLS_CIPHER_MODE_OFB
+#define MBEDTLS_CIPHER_MODE_XTS
+#define MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS
+#define MBEDTLS_CIPHER_PADDING_PKCS7
+#define MBEDTLS_CIPHER_PADDING_ZEROS
+#define MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN
+#define MBEDTLS_CMAC_C
+#define MBEDTLS_CTR_DRBG_C
+//#define MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
+#define MBEDTLS_DES_C
+#define MBEDTLS_DHM_C
+#define MBEDTLS_ECDH_C
+#define MBEDTLS_ECP_C
+#define MBEDTLS_ECP_DP_BP256R1_ENABLED
+#define MBEDTLS_ECP_DP_BP384R1_ENABLED
+#define MBEDTLS_ECP_DP_BP512R1_ENABLED
+#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
+#define MBEDTLS_ECP_DP_CURVE448_ENABLED
+#define MBEDTLS_ECP_DP_SECP192K1_ENABLED
+#define MBEDTLS_ECP_DP_SECP192R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP224K1_ENABLED
+#define MBEDTLS_ECP_DP_SECP224R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
+#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
+#define MBEDTLS_ECP_DP_SECP521R1_ENABLED
+#define MBEDTLS_ECDSA_C
+#define MBEDTLS_ECDSA_DETERMINISTIC
+#define MBEDTLS_ECJPAKE_C
+#define MBEDTLS_GCM_C
+#define MBEDTLS_GENPRIME
+#define MBEDTLS_HKDF_C
+#define MBEDTLS_HMAC_DRBG_C
+#define MBEDTLS_MD5_C
+#define MBEDTLS_PADLOCK_C
+#define MBEDTLS_PKCS1_V15
+#define MBEDTLS_PKCS1_V21
+#define MBEDTLS_POLY1305_C
+//#define MBEDTLS_PSA_CRYPTO_CONFIG
+//#define MBEDTLS_PSA_CRYPTO_SE_C
+#define MBEDTLS_RIPEMD160_C
+#define MBEDTLS_RSA_C
+#define MBEDTLS_SHA1_C
+#define MBEDTLS_SHA224_C
+#define MBEDTLS_SHA256_C
+#define MBEDTLS_SHA384_C
+#define MBEDTLS_SHA3_C
+#define MBEDTLS_SHA512_C
+```
+
+
+### In `mbedtls_config.h`, we have:
+#### SECTION Platform abstraction layer
+```
+#define MBEDTLS_NET_C
+//#define MBEDTLS_TIMING_ALT
+#define MBEDTLS_TIMING_C
+```
+
+
+#### SECTION General configuration options
+```
+#define MBEDTLS_ERROR_C
+#define MBEDTLS_ERROR_STRERROR_DUMMY
+#define MBEDTLS_VERSION_C
+#define MBEDTLS_VERSION_FEATURES
+
+//#define MBEDTLS_CONFIG_FILE "mbedtls/mbedtls_config.h"
+//#define MBEDTLS_USER_CONFIG_FILE "/dev/null"
+```
+
+
+#### SECTION TLS feature selection
+```
+//#define MBEDTLS_CIPHER_NULL_CIPHER
+#define MBEDTLS_DEBUG_C
+#define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
+#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
+#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
+#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
+#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
+#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
+#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
+//#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
+#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
+#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
+#define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
+#define MBEDTLS_SSL_ALL_ALERT_MESSAGES
+#define MBEDTLS_SSL_ALPN
+//#define MBEDTLS_SSL_ASYNC_PRIVATE
+#define MBEDTLS_SSL_CACHE_C
+#define MBEDTLS_SSL_CLI_C
+#define MBEDTLS_SSL_CONTEXT_SERIALIZATION
+#define MBEDTLS_SSL_COOKIE_C
+//#define MBEDTLS_SSL_DEBUG_ALL
+#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
+#define MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE
+#define MBEDTLS_SSL_DTLS_CONNECTION_ID
+#define MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 0
+#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
+//#define MBEDTLS_SSL_DTLS_SRTP
+//#define MBEDTLS_SSL_EARLY_DATA
+#define MBEDTLS_SSL_ENCRYPT_THEN_MAC
+#define MBEDTLS_SSL_EXTENDED_MASTER_SECRET
+#define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
+#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
+#define MBEDTLS_SSL_PROTO_DTLS
+#define MBEDTLS_SSL_PROTO_TLS1_2
+#define MBEDTLS_SSL_PROTO_TLS1_3
+//#define MBEDTLS_SSL_RECORD_SIZE_LIMIT
+#define MBEDTLS_SSL_RENEGOTIATION
+#define MBEDTLS_SSL_SERVER_NAME_INDICATION
+#define MBEDTLS_SSL_SESSION_TICKETS
+#define MBEDTLS_SSL_SRV_C
+#define MBEDTLS_SSL_TICKET_C
+#define MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
+#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
+#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
+#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
+#define MBEDTLS_SSL_TLS_C
+//#define MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
+
+//#define MBEDTLS_PSK_MAX_LEN 32
+//#define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50
+//#define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400
+//#define MBEDTLS_SSL_CID_IN_LEN_MAX 32
+//#define MBEDTLS_SSL_CID_OUT_LEN_MAX 32
+//#define MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 16
+//#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
+//#define MBEDTLS_SSL_COOKIE_TIMEOUT 60
+//#define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768
+//#define MBEDTLS_SSL_IN_CONTENT_LEN 16384
+//#define MBEDTLS_SSL_MAX_EARLY_DATA_SIZE 1024
+//#define MBEDTLS_SSL_OUT_CONTENT_LEN 16384
+//#define MBEDTLS_SSL_TLS1_3_DEFAULT_NEW_SESSION_TICKETS 1
+//#define MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE 6000
+//#define MBEDTLS_SSL_TLS1_3_TICKET_NONCE_LENGTH 32
+```
+
+
+#### SECTION X.509 feature selection
+```
+#define MBEDTLS_PKCS7_C
+#define MBEDTLS_X509_CREATE_C
+#define MBEDTLS_X509_CRL_PARSE_C
+#define MBEDTLS_X509_CRT_PARSE_C
+#define MBEDTLS_X509_CRT_WRITE_C
+#define MBEDTLS_X509_CSR_PARSE_C
+#define MBEDTLS_X509_CSR_WRITE_C
+//#define MBEDTLS_X509_REMOVE_INFO
+#define MBEDTLS_X509_RSASSA_PSS_SUPPORT
+//#define MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
+#define MBEDTLS_X509_USE_C
+
+//#define MBEDTLS_X509_MAX_FILE_PATH_LEN 512
+//#define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8
+```
diff --git a/programs/ssl/dtls_server.c b/programs/ssl/dtls_server.c
index 20e53d3..6430ed2 100644
--- a/programs/ssl/dtls_server.c
+++ b/programs/ssl/dtls_server.c
@@ -289,7 +289,14 @@
ret = 0;
goto reset;
} else if (ret != 0) {
- printf(" failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", (unsigned int) -ret);
+ printf(" failed\n ! mbedtls_ssl_handshake returned -0x%x\n", (unsigned int) -ret);
+ if (ret == MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) {
+ printf(" An unexpected message was received from our peer. If this happened at\n");
+ printf(" the beginning of the handshake, this is likely a duplicated packet or\n");
+ printf(" a close_notify alert from the previous connection, which is harmless.\n");
+ ret = 0;
+ }
+ printf("\n");
goto reset;
}
diff --git a/tests/opt-testcases/sample.sh b/tests/opt-testcases/sample.sh
index e2eaf24..88f3b12 100644
--- a/tests/opt-testcases/sample.sh
+++ b/tests/opt-testcases/sample.sh
@@ -334,11 +334,6 @@
-S "error" \
-C "ERROR"
-# The server complains of extra data after it closes the connection
-# because the client keeps sending data, so the server receives
-# more application data when it expects a new handshake. We consider
-# the test a success if both sides have sent and received application
-# data, no matter what happens afterwards.
run_test "Sample: dtls_client with dtls_server" \
-P 4433 \
"$PROGRAMS_DIR/dtls_server" \
@@ -348,13 +343,9 @@
-s "[1-9][0-9]* bytes written" \
-c "[1-9][0-9]* bytes read" \
-c "[1-9][0-9]* bytes written" \
+ -S "error" \
-C "error"
-# The server complains of extra data after it closes the connection
-# because the client keeps sending data, so the server receives
-# more application data when it expects a new handshake. We consider
-# the test a success if both sides have sent and received application
-# data, no matter what happens afterwards.
run_test "Sample: ssl_client2, dtls_server" \
-P 4433 \
"$PROGRAMS_DIR/dtls_server" \
@@ -364,6 +355,7 @@
-s "[1-9][0-9]* bytes written" \
-c "[1-9][0-9]* bytes read" \
-c "[1-9][0-9]* bytes written" \
+ -S "error" \
-C "error"
requires_protocol_version dtls12
diff --git a/tests/scripts/analyze_outcomes.py b/tests/scripts/analyze_outcomes.py
index e78e90c..188b68d 100755
--- a/tests/scripts/analyze_outcomes.py
+++ b/tests/scripts/analyze_outcomes.py
@@ -82,39 +82,9 @@
if ret_val != 0:
results.error("failed to run reference/driver components")
-def analyze_coverage(results: Results, outcomes: Outcomes,
- allow_list: typing.List[str], full_coverage: bool) -> None:
- """Check that all available test cases are executed at least once."""
- # Make sure that the generated data files are present (and up-to-date).
- # This allows analyze_outcomes.py to run correctly on a fresh Git
- # checkout.
- cp = subprocess.run(['make', 'generated_files'],
- cwd='tests',
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
- check=False)
- if cp.returncode != 0:
- sys.stderr.write(cp.stdout.decode('utf-8'))
- results.error("Failed \"make generated_files\" in tests. "
- "Coverage analysis may be incorrect.")
- available = check_test_cases.collect_available_test_cases()
- for suite_case in available:
- hit = any(suite_case in comp_outcomes.successes or
- suite_case in comp_outcomes.failures
- for comp_outcomes in outcomes.values())
+IgnoreEntry = typing.Union[str, typing.Pattern]
- if not hit and suite_case not in allow_list:
- if full_coverage:
- results.error('Test case not executed: {}', suite_case)
- else:
- results.warning('Test case not executed: {}', suite_case)
- elif hit and suite_case in allow_list:
- # Test Case should be removed from the allow list.
- if full_coverage:
- results.error('Allow listed test case was executed: {}', suite_case)
- else:
- results.warning('Allow listed test case was executed: {}', suite_case)
-
-def name_matches_pattern(name: str, str_or_re) -> bool:
+def name_matches_pattern(name: str, str_or_re: IgnoreEntry) -> bool:
"""Check if name matches a pattern, that may be a string or regex.
- If the pattern is a string, name must be equal to match.
- If the pattern is a regex, name must fully match.
@@ -126,55 +96,6 @@
else:
return str_or_re == name
-def analyze_driver_vs_reference(results: Results, outcomes: Outcomes,
- component_ref: str, component_driver: str,
- ignored_suites: typing.List[str], ignored_tests=None) -> None:
- """Check that all tests passing in the driver component are also
- passing in the corresponding reference component.
- Skip:
- - full test suites provided in ignored_suites list
- - only some specific test inside a test suite, for which the corresponding
- output string is provided
- """
- ref_outcomes = outcomes.get("component_" + component_ref)
- driver_outcomes = outcomes.get("component_" + component_driver)
-
- if ref_outcomes is None or driver_outcomes is None:
- results.error("required components are missing: bad outcome file?")
- return
-
- if not ref_outcomes.successes:
- results.error("no passing test in reference component: bad outcome file?")
- return
-
- for suite_case in ref_outcomes.successes:
- # suite_case is like "test_suite_foo.bar;Description of test case"
- (full_test_suite, test_string) = suite_case.split(';')
- test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name
-
- # Immediately skip fully-ignored test suites
- if test_suite in ignored_suites or full_test_suite in ignored_suites:
- continue
-
- # For ignored test cases inside test suites, just remember and:
- # don't issue an error if they're skipped with drivers,
- # but issue an error if they're not (means we have a bad entry).
- ignored = False
- for str_or_re in (ignored_tests.get(full_test_suite, []) +
- ignored_tests.get(test_suite, [])):
- if name_matches_pattern(test_string, str_or_re):
- ignored = True
-
- if not ignored and not suite_case in driver_outcomes.successes:
- results.error("SKIP/FAIL -> PASS: {}", suite_case)
- if ignored and suite_case in driver_outcomes.successes:
- results.error("uselessly ignored: {}", suite_case)
-
-def analyze_outcomes(results: Results, outcomes: Outcomes, args) -> None:
- """Run all analyses on the given outcome collection."""
- analyze_coverage(results, outcomes, args['allow_list'],
- args['full_coverage'])
-
def read_outcome_file(outcome_file: str) -> Outcomes:
"""Parse an outcome file and return an outcome collection.
"""
@@ -195,530 +116,659 @@
return outcomes
-def do_analyze_coverage(results: Results, outcomes: Outcomes, args) -> None:
- """Perform coverage analysis."""
- results.new_section("Analyze coverage")
- analyze_outcomes(results, outcomes, args)
-def do_analyze_driver_vs_reference(results: Results, outcomes: Outcomes, args) -> None:
- """Perform driver vs reference analyze."""
- results.new_section("Analyze driver {} vs reference {}",
- args['component_driver'], args['component_ref'])
+class Task:
+ """Base class for outcome analysis tasks."""
- ignored_suites = ['test_suite_' + x for x in args['ignored_suites']]
+ # Override the following in child classes.
+ # Map test suite names (with the test_suite_prefix) to a list of ignored
+ # test cases. Each element in the list can be either a string or a regex;
+ # see the `name_matches_pattern` function.
+ IGNORED_TESTS = {} #type: typing.Dict[str, typing.List[IgnoreEntry]]
- analyze_driver_vs_reference(results, outcomes,
- args['component_ref'], args['component_driver'],
- ignored_suites, args['ignored_tests'])
+ def __init__(self, options) -> None:
+ """Pass command line options to the tasks.
+
+ Each task decides which command line options it cares about.
+ """
+ pass
+
+ def section_name(self) -> str:
+ """The section name to use in results."""
+
+ def ignored_tests(self, test_suite: str) -> typing.Iterator[IgnoreEntry]:
+ """Generate the ignore list for the specified test suite."""
+ if test_suite in self.IGNORED_TESTS:
+ yield from self.IGNORED_TESTS[test_suite]
+ pos = test_suite.find('.')
+ if pos != -1:
+ base_test_suite = test_suite[:pos]
+ if base_test_suite in self.IGNORED_TESTS:
+ yield from self.IGNORED_TESTS[base_test_suite]
+
+ def is_test_case_ignored(self, test_suite: str, test_string: str) -> bool:
+ """Check if the specified test case is ignored."""
+ for str_or_re in self.ignored_tests(test_suite):
+ if name_matches_pattern(test_string, str_or_re):
+ return True
+ return False
+
+ def run(self, results: Results, outcomes: Outcomes):
+ """Run the analysis on the specified outcomes.
+
+ Signal errors via the results objects
+ """
+ raise NotImplementedError
+
+
+class CoverageTask(Task):
+ """Analyze test coverage."""
+
+ # Test cases whose suite and description are matched by an entry in
+ # IGNORED_TESTS are expected to be never executed.
+ # All other test cases are expected to be executed at least once.
+ IGNORED_TESTS = {
+ 'test_suite_psa_crypto_metadata': [
+ # Algorithm not supported yet
+ 'Asymmetric signature: pure EdDSA',
+ # Algorithm not supported yet
+ 'Cipher: XTS',
+ ],
+ }
+
+ def __init__(self, options) -> None:
+ super().__init__(options)
+ self.full_coverage = options.full_coverage #type: bool
+
+ @staticmethod
+ def section_name() -> str:
+ return "Analyze coverage"
+
+ def run(self, results: Results, outcomes: Outcomes) -> None:
+ """Check that all available test cases are executed at least once."""
+ # Make sure that the generated data files are present (and up-to-date).
+ # This allows analyze_outcomes.py to run correctly on a fresh Git
+ # checkout.
+ cp = subprocess.run(['make', 'generated_files'],
+ cwd='tests',
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+ check=False)
+ if cp.returncode != 0:
+ sys.stderr.write(cp.stdout.decode('utf-8'))
+ results.error("Failed \"make generated_files\" in tests. "
+ "Coverage analysis may be incorrect.")
+ available = check_test_cases.collect_available_test_cases()
+ for suite_case in available:
+ hit = any(suite_case in comp_outcomes.successes or
+ suite_case in comp_outcomes.failures
+ for comp_outcomes in outcomes.values())
+ (test_suite, test_description) = suite_case.split(';')
+ ignored = self.is_test_case_ignored(test_suite, test_description)
+
+ if not hit and not ignored:
+ if self.full_coverage:
+ results.error('Test case not executed: {}', suite_case)
+ else:
+ results.warning('Test case not executed: {}', suite_case)
+ elif hit and ignored:
+ # If a test case is no longer always skipped, we should remove
+ # it from the ignore list.
+ if self.full_coverage:
+ results.error('Test case was executed but marked as ignored for coverage: {}',
+ suite_case)
+ else:
+ results.warning('Test case was executed but marked as ignored for coverage: {}',
+ suite_case)
+
+
+class DriverVSReference(Task):
+ """Compare outcomes from testing with and without a driver.
+
+ There are 2 options to use analyze_driver_vs_reference_xxx locally:
+ 1. Run tests and then analysis:
+ - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver>
+ - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
+ 2. Let this script run both automatically:
+ - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
+ """
+
+ # Override the following in child classes.
+ # Configuration name (all.sh component) used as the reference.
+ REFERENCE = ''
+ # Configuration name (all.sh component) used as the driver.
+ DRIVER = ''
+ # Ignored test suites (without the test_suite_ prefix).
+ IGNORED_SUITES = [] #type: typing.List[str]
+
+ def __init__(self, options) -> None:
+ super().__init__(options)
+ self.ignored_suites = frozenset('test_suite_' + x
+ for x in self.IGNORED_SUITES)
+
+ def section_name(self) -> str:
+ return f"Analyze driver {self.DRIVER} vs reference {self.REFERENCE}"
+
+ def run(self, results: Results, outcomes: Outcomes) -> None:
+ """Check that all tests passing in the driver component are also
+ passing in the corresponding reference component.
+ Skip:
+ - full test suites provided in ignored_suites list
+ - only some specific test inside a test suite, for which the corresponding
+ output string is provided
+ """
+ ref_outcomes = outcomes.get("component_" + self.REFERENCE)
+ driver_outcomes = outcomes.get("component_" + self.DRIVER)
+
+ if ref_outcomes is None or driver_outcomes is None:
+ results.error("required components are missing: bad outcome file?")
+ return
+
+ if not ref_outcomes.successes:
+ results.error("no passing test in reference component: bad outcome file?")
+ return
+
+ for suite_case in ref_outcomes.successes:
+ # suite_case is like "test_suite_foo.bar;Description of test case"
+ (full_test_suite, test_string) = suite_case.split(';')
+ test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name
+
+ # Immediately skip fully-ignored test suites
+ if test_suite in self.ignored_suites or \
+ full_test_suite in self.ignored_suites:
+ continue
+
+ # For ignored test cases inside test suites, just remember and:
+ # don't issue an error if they're skipped with drivers,
+ # but issue an error if they're not (means we have a bad entry).
+ ignored = self.is_test_case_ignored(full_test_suite, test_string)
+
+ if not ignored and not suite_case in driver_outcomes.successes:
+ results.error("SKIP/FAIL -> PASS: {}", suite_case)
+ if ignored and suite_case in driver_outcomes.successes:
+ results.error("uselessly ignored: {}", suite_case)
+
+
+# The names that we give to classes derived from DriverVSReference do not
+# follow the usual naming convention, because it's more readable to use
+# underscores and parts of the configuration names. Also, these classes
+# are just there to specify some data, so they don't need repetitive
+# documentation.
+#pylint: disable=invalid-name,missing-class-docstring
+
+class DriverVSReference_hash(DriverVSReference):
+ REFERENCE = 'test_psa_crypto_config_reference_hash_use_psa'
+ DRIVER = 'test_psa_crypto_config_accel_hash_use_psa'
+ IGNORED_SUITES = [
+ 'shax', 'mdx', # the software implementations that are being excluded
+ 'md.psa', # purposefully depends on whether drivers are present
+ 'psa_crypto_low_hash.generated', # testing the builtins
+ ]
+ IGNORED_TESTS = {
+ 'test_suite_config': [
+ re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
+ ],
+ 'test_suite_platform': [
+ # Incompatible with sanitizers (e.g. ASan). If the driver
+ # component uses a sanitizer but the reference component
+ # doesn't, we have a PASS vs SKIP mismatch.
+ 'Check mbedtls_calloc overallocation',
+ ],
+ }
+
+class DriverVSReference_hmac(DriverVSReference):
+ REFERENCE = 'test_psa_crypto_config_reference_hmac'
+ DRIVER = 'test_psa_crypto_config_accel_hmac'
+ IGNORED_SUITES = [
+ # These suites require legacy hash support, which is disabled
+ # in the accelerated component.
+ 'shax', 'mdx',
+ # This suite tests builtins directly, but these are missing
+ # in the accelerated case.
+ 'psa_crypto_low_hash.generated',
+ ]
+ IGNORED_TESTS = {
+ 'test_suite_config': [
+ re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
+ re.compile(r'.*\bMBEDTLS_MD_C\b')
+ ],
+ 'test_suite_md': [
+ # Builtin HMAC is not supported in the accelerate component.
+ re.compile('.*HMAC.*'),
+ # Following tests make use of functions which are not available
+ # when MD_C is disabled, as it happens in the accelerated
+ # test component.
+ re.compile('generic .* Hash file .*'),
+ 'MD list',
+ ],
+ 'test_suite_md.psa': [
+ # "legacy only" tests require hash algorithms to be NOT
+ # accelerated, but this of course false for the accelerated
+ # test component.
+ re.compile('PSA dispatch .* legacy only'),
+ ],
+ 'test_suite_platform': [
+ # Incompatible with sanitizers (e.g. ASan). If the driver
+ # component uses a sanitizer but the reference component
+ # doesn't, we have a PASS vs SKIP mismatch.
+ 'Check mbedtls_calloc overallocation',
+ ],
+ }
+
+class DriverVSReference_cipher_aead_cmac(DriverVSReference):
+ REFERENCE = 'test_psa_crypto_config_reference_cipher_aead_cmac'
+ DRIVER = 'test_psa_crypto_config_accel_cipher_aead_cmac'
+ # Modules replaced by drivers.
+ IGNORED_SUITES = [
+ # low-level (block/stream) cipher modules
+ 'aes', 'aria', 'camellia', 'des', 'chacha20',
+ # AEAD modes and CMAC
+ 'ccm', 'chachapoly', 'cmac', 'gcm',
+ # The Cipher abstraction layer
+ 'cipher',
+ ]
+ IGNORED_TESTS = {
+ 'test_suite_config': [
+ re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA|CHACHA20|DES)_.*'),
+ re.compile(r'.*\bMBEDTLS_(CCM|CHACHAPOLY|CMAC|GCM)_.*'),
+ re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
+ re.compile(r'.*\bMBEDTLS_CIPHER_.*'),
+ ],
+ # PEM decryption is not supported so far.
+ # The rest of PEM (write, unencrypted read) works though.
+ 'test_suite_pem': [
+ re.compile(r'PEM read .*(AES|DES|\bencrypt).*'),
+ ],
+ 'test_suite_platform': [
+ # Incompatible with sanitizers (e.g. ASan). If the driver
+ # component uses a sanitizer but the reference component
+ # doesn't, we have a PASS vs SKIP mismatch.
+ 'Check mbedtls_calloc overallocation',
+ ],
+ # Following tests depend on AES_C/DES_C but are not about
+ # them really, just need to know some error code is there.
+ 'test_suite_error': [
+ 'Low and high error',
+ 'Single low error'
+ ],
+ # Similar to test_suite_error above.
+ 'test_suite_version': [
+ 'Check for MBEDTLS_AES_C when already present',
+ ],
+ # The en/decryption part of PKCS#12 is not supported so far.
+ # The rest of PKCS#12 (key derivation) works though.
+ 'test_suite_pkcs12': [
+ re.compile(r'PBE Encrypt, .*'),
+ re.compile(r'PBE Decrypt, .*'),
+ ],
+ # The en/decryption part of PKCS#5 is not supported so far.
+ # The rest of PKCS#5 (PBKDF2) works though.
+ 'test_suite_pkcs5': [
+ re.compile(r'PBES2 Encrypt, .*'),
+ re.compile(r'PBES2 Decrypt .*'),
+ ],
+ # Encrypted keys are not supported so far.
+ # pylint: disable=line-too-long
+ 'test_suite_pkparse': [
+ 'Key ASN1 (Encrypted key PKCS12, trailing garbage data)',
+ 'Key ASN1 (Encrypted key PKCS5, trailing garbage data)',
+ re.compile(r'Parse (RSA|EC) Key .*\(.* ([Ee]ncrypted|password).*\)'),
+ ],
+ # Encrypted keys are not supported so far.
+ 'ssl-opt': [
+ 'TLS: password protected server key',
+ 'TLS: password protected client key',
+ 'TLS: password protected server key, two certificates',
+ ],
+ }
+
+class DriverVSReference_ecp_light_only(DriverVSReference):
+ REFERENCE = 'test_psa_crypto_config_reference_ecc_ecp_light_only'
+ DRIVER = 'test_psa_crypto_config_accel_ecc_ecp_light_only'
+ IGNORED_SUITES = [
+ # Modules replaced by drivers
+ 'ecdsa', 'ecdh', 'ecjpake',
+ ]
+ IGNORED_TESTS = {
+ 'test_suite_config': [
+ re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
+ ],
+ 'test_suite_platform': [
+ # Incompatible with sanitizers (e.g. ASan). If the driver
+ # component uses a sanitizer but the reference component
+ # doesn't, we have a PASS vs SKIP mismatch.
+ 'Check mbedtls_calloc overallocation',
+ ],
+ # This test wants a legacy function that takes f_rng, p_rng
+ # arguments, and uses legacy ECDSA for that. The test is
+ # really about the wrapper around the PSA RNG, not ECDSA.
+ 'test_suite_random': [
+ 'PSA classic wrapper: ECDSA signature (SECP256R1)',
+ ],
+ # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
+ # so we must ignore disparities in the tests for which ECP_C
+ # is required.
+ 'test_suite_ecp': [
+ re.compile(r'ECP check public-private .*'),
+ re.compile(r'ECP calculate public: .*'),
+ re.compile(r'ECP gen keypair .*'),
+ re.compile(r'ECP point muladd .*'),
+ re.compile(r'ECP point multiplication .*'),
+ re.compile(r'ECP test vectors .*'),
+ ],
+ 'test_suite_ssl': [
+ # This deprecated function is only present when ECP_C is On.
+ 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
+ ],
+ }
+
+class DriverVSReference_no_ecp_at_all(DriverVSReference):
+ REFERENCE = 'test_psa_crypto_config_reference_ecc_no_ecp_at_all'
+ DRIVER = 'test_psa_crypto_config_accel_ecc_no_ecp_at_all'
+ IGNORED_SUITES = [
+ # Modules replaced by drivers
+ 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
+ ]
+ IGNORED_TESTS = {
+ 'test_suite_config': [
+ re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
+ re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
+ ],
+ 'test_suite_platform': [
+ # Incompatible with sanitizers (e.g. ASan). If the driver
+ # component uses a sanitizer but the reference component
+ # doesn't, we have a PASS vs SKIP mismatch.
+ 'Check mbedtls_calloc overallocation',
+ ],
+ # See ecp_light_only
+ 'test_suite_random': [
+ 'PSA classic wrapper: ECDSA signature (SECP256R1)',
+ ],
+ 'test_suite_pkparse': [
+ # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
+ # is automatically enabled in build_info.h (backward compatibility)
+ # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
+ # consequence compressed points are supported in the reference
+ # component but not in the accelerated one, so they should be skipped
+ # while checking driver's coverage.
+ re.compile(r'Parse EC Key .*compressed\)'),
+ re.compile(r'Parse Public EC Key .*compressed\)'),
+ ],
+ # See ecp_light_only
+ 'test_suite_ssl': [
+ 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
+ ],
+ }
+
+class DriverVSReference_ecc_no_bignum(DriverVSReference):
+ REFERENCE = 'test_psa_crypto_config_reference_ecc_no_bignum'
+ DRIVER = 'test_psa_crypto_config_accel_ecc_no_bignum'
+ IGNORED_SUITES = [
+ # Modules replaced by drivers
+ 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
+ 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
+ 'bignum.generated', 'bignum.misc',
+ ]
+ IGNORED_TESTS = {
+ 'test_suite_config': [
+ re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
+ re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
+ re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
+ ],
+ 'test_suite_platform': [
+ # Incompatible with sanitizers (e.g. ASan). If the driver
+ # component uses a sanitizer but the reference component
+ # doesn't, we have a PASS vs SKIP mismatch.
+ 'Check mbedtls_calloc overallocation',
+ ],
+ # See ecp_light_only
+ 'test_suite_random': [
+ 'PSA classic wrapper: ECDSA signature (SECP256R1)',
+ ],
+ # See no_ecp_at_all
+ 'test_suite_pkparse': [
+ re.compile(r'Parse EC Key .*compressed\)'),
+ re.compile(r'Parse Public EC Key .*compressed\)'),
+ ],
+ 'test_suite_asn1parse': [
+ 'INTEGER too large for mpi',
+ ],
+ 'test_suite_asn1write': [
+ re.compile(r'ASN.1 Write mpi.*'),
+ ],
+ 'test_suite_debug': [
+ re.compile(r'Debug print mbedtls_mpi.*'),
+ ],
+ # See ecp_light_only
+ 'test_suite_ssl': [
+ 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
+ ],
+ }
+
+class DriverVSReference_ecc_ffdh_no_bignum(DriverVSReference):
+ REFERENCE = 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum'
+ DRIVER = 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum'
+ IGNORED_SUITES = [
+ # Modules replaced by drivers
+ 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm',
+ 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
+ 'bignum.generated', 'bignum.misc',
+ ]
+ IGNORED_TESTS = {
+ 'ssl-opt': [
+ # DHE support in TLS 1.2 requires built-in MBEDTLS_DHM_C
+ # (because it needs custom groups, which PSA does not
+ # provide), even with MBEDTLS_USE_PSA_CRYPTO.
+ re.compile(r'PSK callback:.*\bdhe-psk\b.*'),
+ ],
+ 'test_suite_config': [
+ re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
+ re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
+ re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
+ re.compile(r'.*\bMBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED\b.*'),
+ re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
+ ],
+ 'test_suite_platform': [
+ # Incompatible with sanitizers (e.g. ASan). If the driver
+ # component uses a sanitizer but the reference component
+ # doesn't, we have a PASS vs SKIP mismatch.
+ 'Check mbedtls_calloc overallocation',
+ ],
+ # See ecp_light_only
+ 'test_suite_random': [
+ 'PSA classic wrapper: ECDSA signature (SECP256R1)',
+ ],
+ # See no_ecp_at_all
+ 'test_suite_pkparse': [
+ re.compile(r'Parse EC Key .*compressed\)'),
+ re.compile(r'Parse Public EC Key .*compressed\)'),
+ ],
+ 'test_suite_asn1parse': [
+ 'INTEGER too large for mpi',
+ ],
+ 'test_suite_asn1write': [
+ re.compile(r'ASN.1 Write mpi.*'),
+ ],
+ 'test_suite_debug': [
+ re.compile(r'Debug print mbedtls_mpi.*'),
+ ],
+ # See ecp_light_only
+ 'test_suite_ssl': [
+ 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
+ ],
+ }
+
+class DriverVSReference_ffdh_alg(DriverVSReference):
+ REFERENCE = 'test_psa_crypto_config_reference_ffdh'
+ DRIVER = 'test_psa_crypto_config_accel_ffdh'
+ IGNORED_SUITES = ['dhm']
+ IGNORED_TESTS = {
+ 'test_suite_config': [
+ re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
+ ],
+ 'test_suite_platform': [
+ # Incompatible with sanitizers (e.g. ASan). If the driver
+ # component uses a sanitizer but the reference component
+ # doesn't, we have a PASS vs SKIP mismatch.
+ 'Check mbedtls_calloc overallocation',
+ ],
+ }
+
+class DriverVSReference_tfm_config(DriverVSReference):
+ REFERENCE = 'test_tfm_config_no_p256m'
+ DRIVER = 'test_tfm_config_p256m_driver_accel_ec'
+ IGNORED_SUITES = [
+ # Modules replaced by drivers
+ 'asn1parse', 'asn1write',
+ 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
+ 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
+ 'bignum.generated', 'bignum.misc',
+ ]
+ IGNORED_TESTS = {
+ 'test_suite_config': [
+ re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
+ re.compile(r'.*\bMBEDTLS_(ASN1\w+)_C\b.*'),
+ re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECP)_.*'),
+ re.compile(r'.*\bMBEDTLS_PSA_P256M_DRIVER_ENABLED\b.*')
+ ],
+ 'test_suite_config.crypto_combinations': [
+ 'Config: ECC: Weierstrass curves only',
+ ],
+ 'test_suite_platform': [
+ # Incompatible with sanitizers (e.g. ASan). If the driver
+ # component uses a sanitizer but the reference component
+ # doesn't, we have a PASS vs SKIP mismatch.
+ 'Check mbedtls_calloc overallocation',
+ ],
+ # See ecp_light_only
+ 'test_suite_random': [
+ 'PSA classic wrapper: ECDSA signature (SECP256R1)',
+ ],
+ }
+
+class DriverVSReference_rsa(DriverVSReference):
+ REFERENCE = 'test_psa_crypto_config_reference_rsa_crypto'
+ DRIVER = 'test_psa_crypto_config_accel_rsa_crypto'
+ IGNORED_SUITES = [
+ # Modules replaced by drivers.
+ 'rsa', 'pkcs1_v15', 'pkcs1_v21',
+ # We temporarily don't care about PK stuff.
+ 'pk', 'pkwrite', 'pkparse'
+ ]
+ IGNORED_TESTS = {
+ 'test_suite_config': [
+ re.compile(r'.*\bMBEDTLS_(PKCS1|RSA)_.*'),
+ re.compile(r'.*\bMBEDTLS_GENPRIME\b.*')
+ ],
+ 'test_suite_platform': [
+ # Incompatible with sanitizers (e.g. ASan). If the driver
+ # component uses a sanitizer but the reference component
+ # doesn't, we have a PASS vs SKIP mismatch.
+ 'Check mbedtls_calloc overallocation',
+ ],
+ # Following tests depend on RSA_C but are not about
+ # them really, just need to know some error code is there.
+ 'test_suite_error': [
+ 'Low and high error',
+ 'Single high error'
+ ],
+ # Constant time operations only used for PKCS1_V15
+ 'test_suite_constant_time': [
+ re.compile(r'mbedtls_ct_zeroize_if .*'),
+ re.compile(r'mbedtls_ct_memmove_left .*')
+ ],
+ 'test_suite_psa_crypto': [
+ # We don't support generate_key_custom entry points
+ # in drivers yet.
+ re.compile(r'PSA generate key custom: RSA, e=.*'),
+ re.compile(r'PSA generate key ext: RSA, e=.*'),
+ ],
+ }
+
+class DriverVSReference_block_cipher_dispatch(DriverVSReference):
+ REFERENCE = 'test_full_block_cipher_legacy_dispatch'
+ DRIVER = 'test_full_block_cipher_psa_dispatch'
+ IGNORED_SUITES = [
+ # Skipped in the accelerated component
+ 'aes', 'aria', 'camellia',
+ # These require AES_C, ARIA_C or CAMELLIA_C to be enabled in
+ # order for the cipher module (actually cipher_wrapper) to work
+ # properly. However these symbols are disabled in the accelerated
+ # component so we ignore them.
+ 'cipher.ccm', 'cipher.gcm', 'cipher.aes', 'cipher.aria',
+ 'cipher.camellia',
+ ]
+ IGNORED_TESTS = {
+ 'test_suite_config': [
+ re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA)_.*'),
+ re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
+ ],
+ 'test_suite_cmac': [
+ # Following tests require AES_C/ARIA_C/CAMELLIA_C to be enabled,
+ # but these are not available in the accelerated component.
+ 'CMAC null arguments',
+ re.compile('CMAC.* (AES|ARIA|Camellia).*'),
+ ],
+ 'test_suite_cipher.padding': [
+ # Following tests require AES_C/CAMELLIA_C to be enabled,
+ # but these are not available in the accelerated component.
+ re.compile('Set( non-existent)? padding with (AES|CAMELLIA).*'),
+ ],
+ 'test_suite_pkcs5': [
+ # The AES part of PKCS#5 PBES2 is not yet supported.
+ # The rest of PKCS#5 (PBKDF2) works, though.
+ re.compile(r'PBES2 .* AES-.*')
+ ],
+ 'test_suite_pkparse': [
+ # PEM (called by pkparse) requires AES_C in order to decrypt
+ # the key, but this is not available in the accelerated
+ # component.
+ re.compile('Parse RSA Key.*(password|AES-).*'),
+ ],
+ 'test_suite_pem': [
+ # Following tests require AES_C, but this is diabled in the
+ # accelerated component.
+ re.compile('PEM read .*AES.*'),
+ 'PEM read (unknown encryption algorithm)',
+ ],
+ 'test_suite_error': [
+ # Following tests depend on AES_C but are not about them
+ # really, just need to know some error code is there.
+ 'Single low error',
+ 'Low and high error',
+ ],
+ 'test_suite_version': [
+ # Similar to test_suite_error above.
+ 'Check for MBEDTLS_AES_C when already present',
+ ],
+ 'test_suite_platform': [
+ # Incompatible with sanitizers (e.g. ASan). If the driver
+ # component uses a sanitizer but the reference component
+ # doesn't, we have a PASS vs SKIP mismatch.
+ 'Check mbedtls_calloc overallocation',
+ ],
+ }
+
+#pylint: enable=invalid-name,missing-class-docstring
+
+
# List of tasks with a function that can handle this task and additional arguments if required
KNOWN_TASKS = {
- 'analyze_coverage': {
- 'test_function': do_analyze_coverage,
- 'args': {
- 'allow_list': [
- # Algorithm not supported yet
- 'test_suite_psa_crypto_metadata;Asymmetric signature: pure EdDSA',
- # Algorithm not supported yet
- 'test_suite_psa_crypto_metadata;Cipher: XTS',
- ],
- 'full_coverage': False,
- }
- },
- # There are 2 options to use analyze_driver_vs_reference_xxx locally:
- # 1. Run tests and then analysis:
- # - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver>
- # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
- # 2. Let this script run both automatically:
- # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
- 'analyze_driver_vs_reference_hash': {
- 'test_function': do_analyze_driver_vs_reference,
- 'args': {
- 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa',
- 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa',
- 'ignored_suites': [
- 'shax', 'mdx', # the software implementations that are being excluded
- 'md.psa', # purposefully depends on whether drivers are present
- 'psa_crypto_low_hash.generated', # testing the builtins
- ],
- 'ignored_tests': {
- 'test_suite_config': [
- re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
- ],
- 'test_suite_platform': [
- # Incompatible with sanitizers (e.g. ASan). If the driver
- # component uses a sanitizer but the reference component
- # doesn't, we have a PASS vs SKIP mismatch.
- 'Check mbedtls_calloc overallocation',
- ],
- }
- }
- },
- 'analyze_driver_vs_reference_hmac': {
- 'test_function': do_analyze_driver_vs_reference,
- 'args': {
- 'component_ref': 'test_psa_crypto_config_reference_hmac',
- 'component_driver': 'test_psa_crypto_config_accel_hmac',
- 'ignored_suites': [
- # These suites require legacy hash support, which is disabled
- # in the accelerated component.
- 'shax', 'mdx',
- # This suite tests builtins directly, but these are missing
- # in the accelerated case.
- 'psa_crypto_low_hash.generated',
- ],
- 'ignored_tests': {
- 'test_suite_config': [
- re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
- re.compile(r'.*\bMBEDTLS_MD_C\b')
- ],
- 'test_suite_md': [
- # Builtin HMAC is not supported in the accelerate component.
- re.compile('.*HMAC.*'),
- # Following tests make use of functions which are not available
- # when MD_C is disabled, as it happens in the accelerated
- # test component.
- re.compile('generic .* Hash file .*'),
- 'MD list',
- ],
- 'test_suite_md.psa': [
- # "legacy only" tests require hash algorithms to be NOT
- # accelerated, but this of course false for the accelerated
- # test component.
- re.compile('PSA dispatch .* legacy only'),
- ],
- 'test_suite_platform': [
- # Incompatible with sanitizers (e.g. ASan). If the driver
- # component uses a sanitizer but the reference component
- # doesn't, we have a PASS vs SKIP mismatch.
- 'Check mbedtls_calloc overallocation',
- ],
- }
- }
- },
- 'analyze_driver_vs_reference_cipher_aead_cmac': {
- 'test_function': do_analyze_driver_vs_reference,
- 'args': {
- 'component_ref': 'test_psa_crypto_config_reference_cipher_aead_cmac',
- 'component_driver': 'test_psa_crypto_config_accel_cipher_aead_cmac',
- # Modules replaced by drivers.
- 'ignored_suites': [
- # low-level (block/stream) cipher modules
- 'aes', 'aria', 'camellia', 'des', 'chacha20',
- # AEAD modes and CMAC
- 'ccm', 'chachapoly', 'cmac', 'gcm',
- # The Cipher abstraction layer
- 'cipher',
- ],
- 'ignored_tests': {
- 'test_suite_config': [
- re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA|CHACHA20|DES)_.*'),
- re.compile(r'.*\bMBEDTLS_(CCM|CHACHAPOLY|CMAC|GCM)_.*'),
- re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
- re.compile(r'.*\bMBEDTLS_CIPHER_.*'),
- ],
- # PEM decryption is not supported so far.
- # The rest of PEM (write, unencrypted read) works though.
- 'test_suite_pem': [
- re.compile(r'PEM read .*(AES|DES|\bencrypt).*'),
- ],
- 'test_suite_platform': [
- # Incompatible with sanitizers (e.g. ASan). If the driver
- # component uses a sanitizer but the reference component
- # doesn't, we have a PASS vs SKIP mismatch.
- 'Check mbedtls_calloc overallocation',
- ],
- # Following tests depend on AES_C/DES_C but are not about
- # them really, just need to know some error code is there.
- 'test_suite_error': [
- 'Low and high error',
- 'Single low error'
- ],
- # Similar to test_suite_error above.
- 'test_suite_version': [
- 'Check for MBEDTLS_AES_C when already present',
- ],
- # The en/decryption part of PKCS#12 is not supported so far.
- # The rest of PKCS#12 (key derivation) works though.
- 'test_suite_pkcs12': [
- re.compile(r'PBE Encrypt, .*'),
- re.compile(r'PBE Decrypt, .*'),
- ],
- # The en/decryption part of PKCS#5 is not supported so far.
- # The rest of PKCS#5 (PBKDF2) works though.
- 'test_suite_pkcs5': [
- re.compile(r'PBES2 Encrypt, .*'),
- re.compile(r'PBES2 Decrypt .*'),
- ],
- # Encrypted keys are not supported so far.
- # pylint: disable=line-too-long
- 'test_suite_pkparse': [
- 'Key ASN1 (Encrypted key PKCS12, trailing garbage data)',
- 'Key ASN1 (Encrypted key PKCS5, trailing garbage data)',
- re.compile(r'Parse (RSA|EC) Key .*\(.* ([Ee]ncrypted|password).*\)'),
- ],
- # Encrypted keys are not supported so far.
- 'ssl-opt': [
- 'TLS: password protected server key',
- 'TLS: password protected client key',
- 'TLS: password protected server key, two certificates',
- ],
- }
- }
- },
- 'analyze_driver_vs_reference_ecp_light_only': {
- 'test_function': do_analyze_driver_vs_reference,
- 'args': {
- 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only',
- 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only',
- 'ignored_suites': [
- # Modules replaced by drivers
- 'ecdsa', 'ecdh', 'ecjpake',
- ],
- 'ignored_tests': {
- 'test_suite_config': [
- re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
- ],
- 'test_suite_platform': [
- # Incompatible with sanitizers (e.g. ASan). If the driver
- # component uses a sanitizer but the reference component
- # doesn't, we have a PASS vs SKIP mismatch.
- 'Check mbedtls_calloc overallocation',
- ],
- # This test wants a legacy function that takes f_rng, p_rng
- # arguments, and uses legacy ECDSA for that. The test is
- # really about the wrapper around the PSA RNG, not ECDSA.
- 'test_suite_random': [
- 'PSA classic wrapper: ECDSA signature (SECP256R1)',
- ],
- # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
- # so we must ignore disparities in the tests for which ECP_C
- # is required.
- 'test_suite_ecp': [
- re.compile(r'ECP check public-private .*'),
- re.compile(r'ECP calculate public: .*'),
- re.compile(r'ECP gen keypair .*'),
- re.compile(r'ECP point muladd .*'),
- re.compile(r'ECP point multiplication .*'),
- re.compile(r'ECP test vectors .*'),
- ],
- 'test_suite_ssl': [
- # This deprecated function is only present when ECP_C is On.
- 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
- ],
- }
- }
- },
- 'analyze_driver_vs_reference_no_ecp_at_all': {
- 'test_function': do_analyze_driver_vs_reference,
- 'args': {
- 'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all',
- 'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all',
- 'ignored_suites': [
- # Modules replaced by drivers
- 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
- ],
- 'ignored_tests': {
- 'test_suite_config': [
- re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
- re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
- ],
- 'test_suite_platform': [
- # Incompatible with sanitizers (e.g. ASan). If the driver
- # component uses a sanitizer but the reference component
- # doesn't, we have a PASS vs SKIP mismatch.
- 'Check mbedtls_calloc overallocation',
- ],
- # See ecp_light_only
- 'test_suite_random': [
- 'PSA classic wrapper: ECDSA signature (SECP256R1)',
- ],
- 'test_suite_pkparse': [
- # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
- # is automatically enabled in build_info.h (backward compatibility)
- # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
- # consequence compressed points are supported in the reference
- # component but not in the accelerated one, so they should be skipped
- # while checking driver's coverage.
- re.compile(r'Parse EC Key .*compressed\)'),
- re.compile(r'Parse Public EC Key .*compressed\)'),
- ],
- # See ecp_light_only
- 'test_suite_ssl': [
- 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
- ],
- }
- }
- },
- 'analyze_driver_vs_reference_ecc_no_bignum': {
- 'test_function': do_analyze_driver_vs_reference,
- 'args': {
- 'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum',
- 'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum',
- 'ignored_suites': [
- # Modules replaced by drivers
- 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
- 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
- 'bignum.generated', 'bignum.misc',
- ],
- 'ignored_tests': {
- 'test_suite_config': [
- re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
- re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
- re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
- ],
- 'test_suite_platform': [
- # Incompatible with sanitizers (e.g. ASan). If the driver
- # component uses a sanitizer but the reference component
- # doesn't, we have a PASS vs SKIP mismatch.
- 'Check mbedtls_calloc overallocation',
- ],
- # See ecp_light_only
- 'test_suite_random': [
- 'PSA classic wrapper: ECDSA signature (SECP256R1)',
- ],
- # See no_ecp_at_all
- 'test_suite_pkparse': [
- re.compile(r'Parse EC Key .*compressed\)'),
- re.compile(r'Parse Public EC Key .*compressed\)'),
- ],
- 'test_suite_asn1parse': [
- 'INTEGER too large for mpi',
- ],
- 'test_suite_asn1write': [
- re.compile(r'ASN.1 Write mpi.*'),
- ],
- 'test_suite_debug': [
- re.compile(r'Debug print mbedtls_mpi.*'),
- ],
- # See ecp_light_only
- 'test_suite_ssl': [
- 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
- ],
- }
- }
- },
- 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': {
- 'test_function': do_analyze_driver_vs_reference,
- 'args': {
- 'component_ref': 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum',
- 'component_driver': 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum',
- 'ignored_suites': [
- # Modules replaced by drivers
- 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm',
- 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
- 'bignum.generated', 'bignum.misc',
- ],
- 'ignored_tests': {
- 'ssl-opt': [
- # DHE support in TLS 1.2 requires built-in MBEDTLS_DHM_C
- # (because it needs custom groups, which PSA does not
- # provide), even with MBEDTLS_USE_PSA_CRYPTO.
- re.compile(r'PSK callback:.*\bdhe-psk\b.*'),
- ],
- 'test_suite_config': [
- re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
- re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
- re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
- re.compile(r'.*\bMBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED\b.*'),
- re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
- ],
- 'test_suite_platform': [
- # Incompatible with sanitizers (e.g. ASan). If the driver
- # component uses a sanitizer but the reference component
- # doesn't, we have a PASS vs SKIP mismatch.
- 'Check mbedtls_calloc overallocation',
- ],
- # See ecp_light_only
- 'test_suite_random': [
- 'PSA classic wrapper: ECDSA signature (SECP256R1)',
- ],
- # See no_ecp_at_all
- 'test_suite_pkparse': [
- re.compile(r'Parse EC Key .*compressed\)'),
- re.compile(r'Parse Public EC Key .*compressed\)'),
- ],
- 'test_suite_asn1parse': [
- 'INTEGER too large for mpi',
- ],
- 'test_suite_asn1write': [
- re.compile(r'ASN.1 Write mpi.*'),
- ],
- 'test_suite_debug': [
- re.compile(r'Debug print mbedtls_mpi.*'),
- ],
- # See ecp_light_only
- 'test_suite_ssl': [
- 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
- ],
- }
- }
- },
- 'analyze_driver_vs_reference_ffdh_alg': {
- 'test_function': do_analyze_driver_vs_reference,
- 'args': {
- 'component_ref': 'test_psa_crypto_config_reference_ffdh',
- 'component_driver': 'test_psa_crypto_config_accel_ffdh',
- 'ignored_suites': ['dhm'],
- 'ignored_tests': {
- 'test_suite_config': [
- re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
- ],
- 'test_suite_platform': [
- # Incompatible with sanitizers (e.g. ASan). If the driver
- # component uses a sanitizer but the reference component
- # doesn't, we have a PASS vs SKIP mismatch.
- 'Check mbedtls_calloc overallocation',
- ],
- }
- }
- },
- 'analyze_driver_vs_reference_tfm_config': {
- 'test_function': do_analyze_driver_vs_reference,
- 'args': {
- 'component_ref': 'test_tfm_config_no_p256m',
- 'component_driver': 'test_tfm_config_p256m_driver_accel_ec',
- 'ignored_suites': [
- # Modules replaced by drivers
- 'asn1parse', 'asn1write',
- 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
- 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
- 'bignum.generated', 'bignum.misc',
- ],
- 'ignored_tests': {
- 'test_suite_config': [
- re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
- re.compile(r'.*\bMBEDTLS_(ASN1\w+)_C\b.*'),
- re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECP)_.*'),
- re.compile(r'.*\bMBEDTLS_PSA_P256M_DRIVER_ENABLED\b.*')
- ],
- 'test_suite_config.crypto_combinations': [
- 'Config: ECC: Weierstrass curves only',
- ],
- 'test_suite_platform': [
- # Incompatible with sanitizers (e.g. ASan). If the driver
- # component uses a sanitizer but the reference component
- # doesn't, we have a PASS vs SKIP mismatch.
- 'Check mbedtls_calloc overallocation',
- ],
- # See ecp_light_only
- 'test_suite_random': [
- 'PSA classic wrapper: ECDSA signature (SECP256R1)',
- ],
- }
- }
- },
- 'analyze_driver_vs_reference_rsa': {
- 'test_function': do_analyze_driver_vs_reference,
- 'args': {
- 'component_ref': 'test_psa_crypto_config_reference_rsa_crypto',
- 'component_driver': 'test_psa_crypto_config_accel_rsa_crypto',
- 'ignored_suites': [
- # Modules replaced by drivers.
- 'rsa', 'pkcs1_v15', 'pkcs1_v21',
- # We temporarily don't care about PK stuff.
- 'pk', 'pkwrite', 'pkparse'
- ],
- 'ignored_tests': {
- 'test_suite_config': [
- re.compile(r'.*\bMBEDTLS_(PKCS1|RSA)_.*'),
- re.compile(r'.*\bMBEDTLS_GENPRIME\b.*')
- ],
- 'test_suite_platform': [
- # Incompatible with sanitizers (e.g. ASan). If the driver
- # component uses a sanitizer but the reference component
- # doesn't, we have a PASS vs SKIP mismatch.
- 'Check mbedtls_calloc overallocation',
- ],
- # Following tests depend on RSA_C but are not about
- # them really, just need to know some error code is there.
- 'test_suite_error': [
- 'Low and high error',
- 'Single high error'
- ],
- # Constant time operations only used for PKCS1_V15
- 'test_suite_constant_time': [
- re.compile(r'mbedtls_ct_zeroize_if .*'),
- re.compile(r'mbedtls_ct_memmove_left .*')
- ],
- 'test_suite_psa_crypto': [
- # We don't support generate_key_custom entry points
- # in drivers yet.
- re.compile(r'PSA generate key custom: RSA, e=.*'),
- re.compile(r'PSA generate key ext: RSA, e=.*'),
- ],
- }
- }
- },
- 'analyze_block_cipher_dispatch': {
- 'test_function': do_analyze_driver_vs_reference,
- 'args': {
- 'component_ref': 'test_full_block_cipher_legacy_dispatch',
- 'component_driver': 'test_full_block_cipher_psa_dispatch',
- 'ignored_suites': [
- # Skipped in the accelerated component
- 'aes', 'aria', 'camellia',
- # These require AES_C, ARIA_C or CAMELLIA_C to be enabled in
- # order for the cipher module (actually cipher_wrapper) to work
- # properly. However these symbols are disabled in the accelerated
- # component so we ignore them.
- 'cipher.ccm', 'cipher.gcm', 'cipher.aes', 'cipher.aria',
- 'cipher.camellia',
- ],
- 'ignored_tests': {
- 'test_suite_config': [
- re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA)_.*'),
- re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
- ],
- 'test_suite_cmac': [
- # Following tests require AES_C/ARIA_C/CAMELLIA_C to be enabled,
- # but these are not available in the accelerated component.
- 'CMAC null arguments',
- re.compile('CMAC.* (AES|ARIA|Camellia).*'),
- ],
- 'test_suite_cipher.padding': [
- # Following tests require AES_C/CAMELLIA_C to be enabled,
- # but these are not available in the accelerated component.
- re.compile('Set( non-existent)? padding with (AES|CAMELLIA).*'),
- ],
- 'test_suite_pkcs5': [
- # The AES part of PKCS#5 PBES2 is not yet supported.
- # The rest of PKCS#5 (PBKDF2) works, though.
- re.compile(r'PBES2 .* AES-.*')
- ],
- 'test_suite_pkparse': [
- # PEM (called by pkparse) requires AES_C in order to decrypt
- # the key, but this is not available in the accelerated
- # component.
- re.compile('Parse RSA Key.*(password|AES-).*'),
- ],
- 'test_suite_pem': [
- # Following tests require AES_C, but this is diabled in the
- # accelerated component.
- re.compile('PEM read .*AES.*'),
- 'PEM read (unknown encryption algorithm)',
- ],
- 'test_suite_error': [
- # Following tests depend on AES_C but are not about them
- # really, just need to know some error code is there.
- 'Single low error',
- 'Low and high error',
- ],
- 'test_suite_version': [
- # Similar to test_suite_error above.
- 'Check for MBEDTLS_AES_C when already present',
- ],
- 'test_suite_platform': [
- # Incompatible with sanitizers (e.g. ASan). If the driver
- # component uses a sanitizer but the reference component
- # doesn't, we have a PASS vs SKIP mismatch.
- 'Check mbedtls_calloc overallocation',
- ],
- }
- }
- }
+ 'analyze_coverage': CoverageTask,
+ 'analyze_driver_vs_reference_hash': DriverVSReference_hash,
+ 'analyze_driver_vs_reference_hmac': DriverVSReference_hmac,
+ 'analyze_driver_vs_reference_cipher_aead_cmac': DriverVSReference_cipher_aead_cmac,
+ 'analyze_driver_vs_reference_ecp_light_only': DriverVSReference_ecp_light_only,
+ 'analyze_driver_vs_reference_no_ecp_at_all': DriverVSReference_no_ecp_at_all,
+ 'analyze_driver_vs_reference_ecc_no_bignum': DriverVSReference_ecc_no_bignum,
+ 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': DriverVSReference_ecc_ffdh_no_bignum,
+ 'analyze_driver_vs_reference_ffdh_alg': DriverVSReference_ffdh_alg,
+ 'analyze_driver_vs_reference_tfm_config': DriverVSReference_tfm_config,
+ 'analyze_driver_vs_reference_rsa': DriverVSReference_rsa,
+ 'analyze_block_cipher_dispatch': DriverVSReference_block_cipher_dispatch,
}
+
def main():
main_results = Results()
@@ -754,8 +804,6 @@
sys.stderr.write('invalid task: {}\n'.format(task))
sys.exit(2)
- KNOWN_TASKS['analyze_coverage']['args']['full_coverage'] = options.full_coverage
-
# If the outcome file exists, parse it once and share the result
# among tasks to improve performance.
# Otherwise, it will be generated by execute_reference_driver_tests.
@@ -766,21 +814,21 @@
task_name = tasks_list[0]
task = KNOWN_TASKS[task_name]
- if task['test_function'] != do_analyze_driver_vs_reference: # pylint: disable=comparison-with-callable
+ if not issubclass(task, DriverVSReference):
sys.stderr.write("please provide valid outcomes file for {}.\n".format(task_name))
sys.exit(2)
-
execute_reference_driver_tests(main_results,
- task['args']['component_ref'],
- task['args']['component_driver'],
+ task.REFERENCE,
+ task.DRIVER,
options.outcomes)
outcomes = read_outcome_file(options.outcomes)
- for task in tasks_list:
- test_function = KNOWN_TASKS[task]['test_function']
- test_args = KNOWN_TASKS[task]['args']
- test_function(main_results, outcomes, test_args)
+ for task_name in tasks_list:
+ task_constructor = KNOWN_TASKS[task_name]
+ task = task_constructor(options)
+ main_results.new_section(task.section_name())
+ task.run(main_results, outcomes)
main_results.info("Overall results: {} warnings and {} errors",
main_results.warning_count, main_results.error_count)