From 22106f54538bd649d546c790bdc5edf0a424c5e9 Mon Sep 17 00:00:00 2001 From: David Vincze Date: Fri, 21 Mar 2025 11:14:56 +0000 Subject: [PATCH 1/5] Crypto: Update to Mbed TLS 3.6.3 - Bump Mbed TLS version to 3.6.3, - Re-align mbedtls/psa interface headers, - Rebase patch files and fix 0005. Change-Id: I7a21c95f64d9d7e82b1167dd5fdc7b196b049808 Signed-off-by: David Vincze (cherry picked from commit 79ae04de655304b2c12b059121880aed3436e2e5) --- config/config_base.cmake | 3 +- interface/include/mbedtls/check_config.h | 8 ++ .../mbedtls/config_adjust_legacy_crypto.h | 75 +++++++++++++-- .../mbedtls/config_adjust_legacy_from_psa.h | 19 ---- .../config_adjust_psa_superset_legacy.h | 7 -- interface/include/mbedtls/debug.h | 6 +- interface/include/mbedtls/entropy.h | 5 +- interface/include/mbedtls/gcm.h | 23 +++-- interface/include/mbedtls/net_sockets.h | 2 +- interface/include/mbedtls/pk.h | 2 +- interface/include/mbedtls/psa_util.h | 19 ++++ interface/include/mbedtls/ssl.h | 33 ++++++- interface/include/mbedtls/threading.h | 2 +- interface/include/psa/crypto_extra.h | 39 ++++++++ interface/include/psa/crypto_sizes.h | 25 +++++ ...iltin-Key-Loader-driver-entry-points.patch | 52 +++++----- ...de-sharing-between-independent-binar.patch | 4 +- ...-use-key-vendor-id-within-PSA-crypto.patch | 8 +- ...r-wrappers-as-first-step-in-psa_cryp.patch | 8 +- .../0005-Hardcode-CC3XX-entry-points.patch | 95 ++++++++++--------- .../0006-Enable-psa_can_do_hash.patch | 6 +- ...M-Add-option-to-force-not-use-of-asm.patch | 30 ++++++ 22 files changed, 333 insertions(+), 138 deletions(-) create mode 100644 lib/ext/mbedcrypto/0007-P256M-Add-option-to-force-not-use-of-asm.patch diff --git a/config/config_base.cmake b/config/config_base.cmake index b70c627c6b..14d6ae97a3 100644 --- a/config/config_base.cmake +++ b/config/config_base.cmake @@ -37,7 +37,8 @@ set(PROJECT_CONFIG_HEADER_FILE "" CACHE FILEPATH "User define # External libraries source and version set(MBEDCRYPTO_PATH "DOWNLOAD" CACHE PATH "Path to Mbed Crypto (or DOWNLOAD to fetch automatically") set(MBEDCRYPTO_FORCE_PATCH OFF CACHE BOOL "Always apply MBed Crypto patches") -set(MBEDCRYPTO_VERSION "mbedtls-3.6.2" CACHE STRING "The version of Mbed Crypto to use") +# TODO update to "mbedtls-3.6.3" after release, +set(MBEDCRYPTO_VERSION "f985bee" CACHE STRING "The version of Mbed Crypto to use") set(MBEDCRYPTO_GIT_REMOTE "https://github.com/Mbed-TLS/mbedtls.git" CACHE STRING "The URL (or path) to retrieve MbedTLS from.") set(MCUBOOT_PATH "DOWNLOAD" CACHE PATH "Path to MCUboot (or DOWNLOAD to fetch automatically") diff --git a/interface/include/mbedtls/check_config.h b/interface/include/mbedtls/check_config.h index 67a05f83b8..aec5050b70 100644 --- a/interface/include/mbedtls/check_config.h +++ b/interface/include/mbedtls/check_config.h @@ -247,6 +247,9 @@ #if defined(MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN) && !defined(MBEDTLS_HAS_MEMSAN) #error "MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN requires building with MemorySanitizer" #endif +#if defined(MBEDTLS_HAS_MEMSAN) && defined(MBEDTLS_HAVE_ASM) +#error "MemorySanitizer does not support assembly implementation" +#endif #undef MBEDTLS_HAS_MEMSAN // temporary macro defined above #if defined(MBEDTLS_CCM_C) && \ @@ -738,6 +741,11 @@ #error "MBEDTLS_PSA_INJECT_ENTROPY is not compatible with MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG" #endif +#if defined(MBEDTLS_PSA_KEY_STORE_DYNAMIC) && \ + defined(MBEDTLS_PSA_STATIC_KEY_SLOTS) +#error "MBEDTLS_PSA_KEY_STORE_DYNAMIC and MBEDTLS_PSA_STATIC_KEY_SLOTS cannot be defined simultaneously" +#endif + #if defined(MBEDTLS_PSA_ITS_FILE_C) && \ !defined(MBEDTLS_FS_IO) #error "MBEDTLS_PSA_ITS_FILE_C defined, but not all prerequisites" diff --git a/interface/include/mbedtls/config_adjust_legacy_crypto.h b/interface/include/mbedtls/config_adjust_legacy_crypto.h index 3ba987ebb2..331ac9b2da 100644 --- a/interface/include/mbedtls/config_adjust_legacy_crypto.h +++ b/interface/include/mbedtls/config_adjust_legacy_crypto.h @@ -48,6 +48,13 @@ #endif #endif /* _MINGW32__ || (_MSC_VER && (_MSC_VER <= 1900)) */ +/* If MBEDTLS_PSA_CRYPTO_C is defined, make sure MBEDTLS_PSA_CRYPTO_CLIENT + * is defined as well to include all PSA code. + */ +#if defined(MBEDTLS_PSA_CRYPTO_C) +#define MBEDTLS_PSA_CRYPTO_CLIENT +#endif /* MBEDTLS_PSA_CRYPTO_C */ + /* Auto-enable CIPHER_C when any of the unauthenticated ciphers is builtin * in PSA. */ #if defined(MBEDTLS_PSA_CRYPTO_C) && \ @@ -158,7 +165,66 @@ #define MBEDTLS_MD_SHA3_512_VIA_PSA #define MBEDTLS_MD_SOME_PSA #endif -#endif /* MBEDTLS_PSA_CRYPTO_C */ + +#elif defined(MBEDTLS_PSA_CRYPTO_CLIENT) + +#if defined(PSA_WANT_ALG_MD5) +#define MBEDTLS_MD_CAN_MD5 +#define MBEDTLS_MD_MD5_VIA_PSA +#define MBEDTLS_MD_SOME_PSA +#endif +#if defined(PSA_WANT_ALG_SHA_1) +#define MBEDTLS_MD_CAN_SHA1 +#define MBEDTLS_MD_SHA1_VIA_PSA +#define MBEDTLS_MD_SOME_PSA +#endif +#if defined(PSA_WANT_ALG_SHA_224) +#define MBEDTLS_MD_CAN_SHA224 +#define MBEDTLS_MD_SHA224_VIA_PSA +#define MBEDTLS_MD_SOME_PSA +#endif +#if defined(PSA_WANT_ALG_SHA_256) +#define MBEDTLS_MD_CAN_SHA256 +#define MBEDTLS_MD_SHA256_VIA_PSA +#define MBEDTLS_MD_SOME_PSA +#endif +#if defined(PSA_WANT_ALG_SHA_384) +#define MBEDTLS_MD_CAN_SHA384 +#define MBEDTLS_MD_SHA384_VIA_PSA +#define MBEDTLS_MD_SOME_PSA +#endif +#if defined(PSA_WANT_ALG_SHA_512) +#define MBEDTLS_MD_CAN_SHA512 +#define MBEDTLS_MD_SHA512_VIA_PSA +#define MBEDTLS_MD_SOME_PSA +#endif +#if defined(PSA_WANT_ALG_RIPEMD160) +#define MBEDTLS_MD_CAN_RIPEMD160 +#define MBEDTLS_MD_RIPEMD160_VIA_PSA +#define MBEDTLS_MD_SOME_PSA +#endif +#if defined(PSA_WANT_ALG_SHA3_224) +#define MBEDTLS_MD_CAN_SHA3_224 +#define MBEDTLS_MD_SHA3_224_VIA_PSA +#define MBEDTLS_MD_SOME_PSA +#endif +#if defined(PSA_WANT_ALG_SHA3_256) +#define MBEDTLS_MD_CAN_SHA3_256 +#define MBEDTLS_MD_SHA3_256_VIA_PSA +#define MBEDTLS_MD_SOME_PSA +#endif +#if defined(PSA_WANT_ALG_SHA3_384) +#define MBEDTLS_MD_CAN_SHA3_384 +#define MBEDTLS_MD_SHA3_384_VIA_PSA +#define MBEDTLS_MD_SOME_PSA +#endif +#if defined(PSA_WANT_ALG_SHA3_512) +#define MBEDTLS_MD_CAN_SHA3_512 +#define MBEDTLS_MD_SHA3_512_VIA_PSA +#define MBEDTLS_MD_SOME_PSA +#endif + +#endif /* !MBEDTLS_PSA_CRYPTO_CLIENT && !MBEDTLS_PSA_CRYPTO_C */ /* Built-in implementations */ #if defined(MBEDTLS_MD5_C) @@ -352,13 +418,6 @@ #define MBEDTLS_PK_CAN_ECDSA_SOME #endif -/* If MBEDTLS_PSA_CRYPTO_C is defined, make sure MBEDTLS_PSA_CRYPTO_CLIENT - * is defined as well to include all PSA code. - */ -#if defined(MBEDTLS_PSA_CRYPTO_C) -#define MBEDTLS_PSA_CRYPTO_CLIENT -#endif /* MBEDTLS_PSA_CRYPTO_C */ - /* Helpers to state that each key is supported either on the builtin or PSA side. */ #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_521) #define MBEDTLS_ECP_HAVE_SECP521R1 diff --git a/interface/include/mbedtls/config_adjust_legacy_from_psa.h b/interface/include/mbedtls/config_adjust_legacy_from_psa.h index 04bdae61bb..48f1bab1ed 100644 --- a/interface/include/mbedtls/config_adjust_legacy_from_psa.h +++ b/interface/include/mbedtls/config_adjust_legacy_from_psa.h @@ -69,7 +69,6 @@ (defined(PSA_WANT_ECC_SECP_R1_384) && !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_384)) || \ (defined(PSA_WANT_ECC_SECP_R1_521) && !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_521)) || \ (defined(PSA_WANT_ECC_SECP_K1_192) && !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_192)) || \ - (defined(PSA_WANT_ECC_SECP_K1_224) && !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_224)) || \ (defined(PSA_WANT_ECC_SECP_K1_256) && !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_256)) #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES #define MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_WEIERSTRASS_CURVES @@ -225,17 +224,6 @@ #endif /* missing accel */ #endif /* PSA_WANT_ECC_SECP_K1_192 */ -#if defined(PSA_WANT_ECC_SECP_K1_224) -#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_224) || \ - defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \ - defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_ALGS) -#define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_224 1 -#define MBEDTLS_ECP_DP_SECP224K1_ENABLED -/* https://github.com/Mbed-TLS/mbedtls/issues/3541 */ -#error "SECP224K1 is buggy via the PSA API in Mbed TLS." -#endif /* missing accel */ -#endif /* PSA_WANT_ECC_SECP_K1_224 */ - #if defined(PSA_WANT_ECC_SECP_K1_256) #if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_256) || \ defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_KEY_TYPES) || \ @@ -782,13 +770,6 @@ #define PSA_HAVE_SOFT_BLOCK_CIPHER 1 #endif -#if defined(PSA_WANT_ALG_CBC_MAC) -#if !defined(MBEDTLS_PSA_ACCEL_ALG_CBC_MAC) -#error "CBC-MAC is not yet supported via the PSA API in Mbed TLS." -#define MBEDTLS_PSA_BUILTIN_ALG_CBC_MAC 1 -#endif /* !MBEDTLS_PSA_ACCEL_ALG_CBC_MAC */ -#endif /* PSA_WANT_ALG_CBC_MAC */ - #if defined(PSA_WANT_ALG_CMAC) #if !defined(MBEDTLS_PSA_ACCEL_ALG_CMAC) || \ defined(PSA_HAVE_SOFT_BLOCK_CIPHER) diff --git a/interface/include/mbedtls/config_adjust_psa_superset_legacy.h b/interface/include/mbedtls/config_adjust_psa_superset_legacy.h index ef65cce0d9..1a232cbb81 100644 --- a/interface/include/mbedtls/config_adjust_psa_superset_legacy.h +++ b/interface/include/mbedtls/config_adjust_psa_superset_legacy.h @@ -136,13 +136,6 @@ #endif /* PSA_WANT_ECC_SECP_K1_192 */ #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */ -/* SECP224K1 is buggy via the PSA API (https://github.com/Mbed-TLS/mbedtls/issues/3541) */ -#if 0 && defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) -#if !defined(PSA_WANT_ECC_SECP_K1_224) -#define PSA_WANT_ECC_SECP_K1_224 1 -#endif /* PSA_WANT_ECC_SECP_K1_224 */ -#endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */ - #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) #if !defined(PSA_WANT_ECC_SECP_K1_256) #define PSA_WANT_ECC_SECP_K1_256 1 diff --git a/interface/include/mbedtls/debug.h b/interface/include/mbedtls/debug.h index 424ed4b3fd..e6f5dadb14 100644 --- a/interface/include/mbedtls/debug.h +++ b/interface/include/mbedtls/debug.h @@ -108,16 +108,16 @@ * * This module provides debugging functions. */ -#if (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) +#if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER < 1900) #include #define MBEDTLS_PRINTF_SIZET PRIuPTR #define MBEDTLS_PRINTF_LONGLONG "I64d" #else \ - /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */ + /* defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER < 1900) */ #define MBEDTLS_PRINTF_SIZET "zu" #define MBEDTLS_PRINTF_LONGLONG "lld" #endif \ - /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */ + /* defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER < 1900) */ #if !defined(MBEDTLS_PRINTF_MS_TIME) #include diff --git a/interface/include/mbedtls/entropy.h b/interface/include/mbedtls/entropy.h index 20fd6872b8..6c64e3e4e1 100644 --- a/interface/include/mbedtls/entropy.h +++ b/interface/include/mbedtls/entropy.h @@ -17,12 +17,13 @@ #include "md.h" -#if defined(MBEDTLS_MD_CAN_SHA512) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) +#if (defined(MBEDTLS_MD_CAN_SHA512) || defined(PSA_WANT_ALG_SHA_512)) && \ + !defined(MBEDTLS_ENTROPY_FORCE_SHA256) #define MBEDTLS_ENTROPY_SHA512_ACCUMULATOR #define MBEDTLS_ENTROPY_MD MBEDTLS_MD_SHA512 #define MBEDTLS_ENTROPY_BLOCK_SIZE 64 /**< Block size of entropy accumulator (SHA-512) */ #else -#if defined(MBEDTLS_MD_CAN_SHA256) +#if (defined(MBEDTLS_MD_CAN_SHA256) || defined(PSA_WANT_ALG_SHA_256)) #define MBEDTLS_ENTROPY_SHA256_ACCUMULATOR #define MBEDTLS_ENTROPY_MD MBEDTLS_MD_SHA256 #define MBEDTLS_ENTROPY_BLOCK_SIZE 32 /**< Block size of entropy accumulator (SHA-256) */ diff --git a/interface/include/mbedtls/gcm.h b/interface/include/mbedtls/gcm.h index 98faa43612..390ed4c6d0 100644 --- a/interface/include/mbedtls/gcm.h +++ b/interface/include/mbedtls/gcm.h @@ -115,10 +115,9 @@ int mbedtls_gcm_setkey(mbedtls_gcm_context *ctx, /** * \brief This function performs GCM encryption or decryption of a buffer. * - * \note For encryption, the output buffer can be the same as the - * input buffer. For decryption, the output buffer cannot be - * the same as input buffer. If the buffers overlap, the output - * buffer must trail at least 8 Bytes behind the input buffer. + * \note The output buffer \p output can be the same as the input + * buffer \p input. If \p output is greater than \p input, they + * cannot overlap. * * \warning When this function performs a decryption, it outputs the * authentication tag and does not verify that the data is @@ -179,9 +178,11 @@ int mbedtls_gcm_crypt_and_tag(mbedtls_gcm_context *ctx, * \brief This function performs a GCM authenticated decryption of a * buffer. * - * \note For decryption, the output buffer cannot be the same as - * input buffer. If the buffers overlap, the output buffer - * must trail at least 8 Bytes behind the input buffer. + * \note The output buffer \p output can be the same as the input + * buffer \p input. If \p output is greater than \p input, they + * cannot overlap. Implementations which require + * MBEDTLS_GCM_ALT to be enabled may not provide support for + * overlapping buffers. * * \param ctx The GCM context. This must be initialized. * \param length The length of the ciphertext to decrypt, which is also @@ -287,9 +288,11 @@ int mbedtls_gcm_update_ad(mbedtls_gcm_context *ctx, * to this function during an operation, then it is * correct to use \p output_size = \p input_length. * - * \note For decryption, the output buffer cannot be the same as - * input buffer. If the buffers overlap, the output buffer - * must trail at least 8 Bytes behind the input buffer. + * \note The output buffer \p output can be the same as the input + * buffer \p input. If \p output is greater than \p input, they + * cannot overlap. Implementations which require + * MBEDTLS_GCM_ALT to be enabled may not provide support for + * overlapping buffers. * * \param ctx The GCM context. This must be initialized. * \param input The buffer holding the input data. If \p input_length diff --git a/interface/include/mbedtls/net_sockets.h b/interface/include/mbedtls/net_sockets.h index 85c11971d8..8e69bc0fb3 100644 --- a/interface/include/mbedtls/net_sockets.h +++ b/interface/include/mbedtls/net_sockets.h @@ -229,7 +229,7 @@ int mbedtls_net_recv(void *ctx, unsigned char *buf, size_t len); /** * \brief Write at most 'len' characters. If no error occurs, - * the actual amount read is returned. + * the actual amount written is returned. * * \param ctx Socket * \param buf The buffer to read from diff --git a/interface/include/mbedtls/pk.h b/interface/include/mbedtls/pk.h index 1b7e4f1066..52f4cc6c9e 100644 --- a/interface/include/mbedtls/pk.h +++ b/interface/include/mbedtls/pk.h @@ -362,7 +362,7 @@ int mbedtls_pk_setup(mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info); * \brief Initialize a PK context to wrap a PSA key. * * This function creates a PK context which wraps a PSA key. The PSA wrapped - * key must be an EC or RSA key pair (DH is not supported in the PK module). + * key must be an EC or RSA key pair (DH is not suported in the PK module). * * Under the hood PSA functions will be used to perform the required * operations and, based on the key type, used algorithms will be: diff --git a/interface/include/mbedtls/psa_util.h b/interface/include/mbedtls/psa_util.h index c78cc23333..b898f1f8d3 100644 --- a/interface/include/mbedtls/psa_util.h +++ b/interface/include/mbedtls/psa_util.h @@ -161,6 +161,16 @@ static inline mbedtls_md_type_t mbedtls_md_type_from_psa_alg(psa_algorithm_t psa * \param[out] der_len On success it contains the amount of valid data * (in bytes) written to \p der. It's undefined * in case of failure. + * + * \note The behavior is undefined if \p der is null, + * even if \p der_size is 0. + * + * \return 0 if successful. + * \return #MBEDTLS_ERR_ASN1_BUF_TOO_SMALL if \p der_size + * is too small or if \p bits is larger than the + * largest supported curve. + * \return #MBEDTLS_ERR_ASN1_INVALID_DATA if one of the + * numbers in the signature is 0. */ int mbedtls_ecdsa_raw_to_der(size_t bits, const unsigned char *raw, size_t raw_len, unsigned char *der, size_t der_size, size_t *der_len); @@ -177,6 +187,15 @@ int mbedtls_ecdsa_raw_to_der(size_t bits, const unsigned char *raw, size_t raw_l * \param[out] raw_len On success it is updated with the amount of valid * data (in bytes) written to \p raw. It's undefined * in case of failure. + * + * \return 0 if successful. + * \return #MBEDTLS_ERR_ASN1_BUF_TOO_SMALL if \p raw_size + * is too small or if \p bits is larger than the + * largest supported curve. + * \return #MBEDTLS_ERR_ASN1_INVALID_DATA if the data in + * \p der is inconsistent with \p bits. + * \return An \c MBEDTLS_ERR_ASN1_xxx error code if + * \p der is malformed. */ int mbedtls_ecdsa_der_to_raw(size_t bits, const unsigned char *der, size_t der_len, unsigned char *raw, size_t raw_size, size_t *raw_len); diff --git a/interface/include/mbedtls/ssl.h b/interface/include/mbedtls/ssl.h index 42fffbf860..97b0dcb380 100644 --- a/interface/include/mbedtls/ssl.h +++ b/interface/include/mbedtls/ssl.h @@ -1724,7 +1724,16 @@ struct mbedtls_ssl_context { int MBEDTLS_PRIVATE(early_data_state); #endif - unsigned MBEDTLS_PRIVATE(badmac_seen); /*!< records with a bad MAC received */ + /** Multipurpose field. + * + * - DTLS: records with a bad MAC received. + * - TLS: accumulated length of handshake fragments (up to \c in_hslen). + * + * This field is multipurpose in order to preserve the ABI in the + * Mbed TLS 3.6 LTS branch. Until 3.6.2, it was only used in DTLS + * and called `badmac_seen`. + */ + unsigned MBEDTLS_PRIVATE(badmac_seen_or_in_hsfraglen); #if defined(MBEDTLS_X509_CRT_PARSE_C) /** Callback to customize X.509 certificate chain verification */ @@ -4440,6 +4449,10 @@ void mbedtls_ssl_conf_cert_req_ca_list(mbedtls_ssl_config *conf, * with \c mbedtls_ssl_read()), not handshake messages. * With DTLS, this affects both ApplicationData and handshake. * + * \note Defragmentation of TLS handshake messages is supported + * with some limitations. See the documentation of + * mbedtls_ssl_handshake() for details. + * * \note This sets the maximum length for a record's payload, * excluding record overhead that will be added to it, see * \c mbedtls_ssl_get_record_expansion(). @@ -4970,6 +4983,24 @@ int mbedtls_ssl_get_session(const mbedtls_ssl_context *ssl, * if a negotiation involving TLS 1.3 takes place (this may * be the case even if TLS 1.3 is offered but eventually * not selected). + * + * \note In TLS, reception of fragmented handshake messages is + * supported with some limitations (those limitations do + * not apply to DTLS, where defragmentation is fully + * supported): + * - On an Mbed TLS server that only accepts TLS 1.2, + * the initial ClientHello message must not be fragmented. + * A TLS 1.2 ClientHello may be fragmented if the server + * also accepts TLS 1.3 connections (meaning + * that #MBEDTLS_SSL_PROTO_TLS1_3 enabled, and the + * accepted versions have not been restricted with + * mbedtls_ssl_conf_max_tls_version() or the like). + * - The first fragment of a handshake message must be + * at least 4 bytes long. + * - Non-handshake records must not be interleaved between + * the fragments of a handshake message. (This is permitted + * in TLS 1.2 but not in TLS 1.3, but Mbed TLS rejects it + * even in TLS 1.2.) */ int mbedtls_ssl_handshake(mbedtls_ssl_context *ssl); diff --git a/interface/include/mbedtls/threading.h b/interface/include/mbedtls/threading.h index d50d04ead1..b4df0e38be 100644 --- a/interface/include/mbedtls/threading.h +++ b/interface/include/mbedtls/threading.h @@ -30,7 +30,7 @@ typedef struct mbedtls_threading_mutex_t { pthread_mutex_t MBEDTLS_PRIVATE(mutex); /* WARNING - state should only be accessed when holding the mutex lock in - * tests/src/threading_helpers.c, otherwise corruption can occur. + * framework/tests/src/threading_helpers.c, otherwise corruption can occur. * state will be 0 after a failed init or a free, and nonzero after a * successful init. This field is for testing only and thus not considered * part of the public API of Mbed TLS and may change without notice.*/ diff --git a/interface/include/psa/crypto_extra.h b/interface/include/psa/crypto_extra.h index 0cf42c6055..a046ba5777 100644 --- a/interface/include/psa/crypto_extra.h +++ b/interface/include/psa/crypto_extra.h @@ -32,6 +32,16 @@ extern "C" { #define MBEDTLS_PSA_KEY_SLOT_COUNT 32 #endif +/* If the size of static key slots is not explicitly defined by the user, then + * set it to the maximum between PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE and + * PSA_CIPHER_MAX_KEY_LENGTH. + * See mbedtls_config.h for the definition. */ +#if !defined(MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE) +#define MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE \ + ((PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE > PSA_CIPHER_MAX_KEY_LENGTH) ? \ + PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE : PSA_CIPHER_MAX_KEY_LENGTH) +#endif /* !MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE*/ + /** \addtogroup attributes * @{ */ @@ -573,6 +583,35 @@ psa_status_t mbedtls_psa_platform_get_builtin_key( /** @} */ +/** \defgroup psa_crypto_client Functions defined by a client provider + * + * The functions in this group are meant to be implemented by providers of + * the PSA Crypto client interface. They are provided by the library when + * #MBEDTLS_PSA_CRYPTO_C is enabled. + * + * \note All functions in this group are experimental, as using + * alternative client interface providers is experimental. + * + * @{ + */ + +/** Check if PSA is capable of handling the specified hash algorithm. + * + * This means that PSA core was built with the corresponding PSA_WANT_ALG_xxx + * set and that psa_crypto_init has already been called. + * + * \note When using Mbed TLS version of PSA core (i.e. MBEDTLS_PSA_CRYPTO_C is + * set) for now this function only checks the state of the driver + * subsystem, not the algorithm. This might be improved in the future. + * + * \param hash_alg The hash algorithm. + * + * \return 1 if the PSA can handle \p hash_alg, 0 otherwise. + */ +int psa_can_do_hash(psa_algorithm_t hash_alg); + +/**@}*/ + /** \addtogroup crypto_types * @{ */ diff --git a/interface/include/psa/crypto_sizes.h b/interface/include/psa/crypto_sizes.h index 635ee98f80..87b8c39fa6 100644 --- a/interface/include/psa/crypto_sizes.h +++ b/interface/include/psa/crypto_sizes.h @@ -1038,6 +1038,10 @@ PSA_KEY_EXPORT_FFDH_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_FFDH_MAX_KEY_BITS) #endif +#define PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE \ + ((PSA_EXPORT_KEY_PAIR_MAX_SIZE > PSA_EXPORT_PUBLIC_KEY_MAX_SIZE) ? \ + PSA_EXPORT_KEY_PAIR_MAX_SIZE : PSA_EXPORT_PUBLIC_KEY_MAX_SIZE) + /** Sufficient output buffer size for psa_raw_key_agreement(). * * This macro returns a compile-time constant if its arguments are @@ -1085,6 +1089,27 @@ #define PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE PSA_BITS_TO_BYTES(PSA_VENDOR_FFDH_MAX_KEY_BITS) #endif +/** Maximum key length for ciphers. + * + * Since there is no additional PSA_WANT_xxx symbol to specifiy the size of + * the key once a cipher is enabled (as it happens for asymmetric keys for + * example), the maximum key length is taken into account for each cipher. + * The resulting value will be the maximum cipher's key length given depending + * on which ciphers are enabled. + * + * Note: max value for AES used below would be doubled if XTS were enabled, but + * this mode is currently not supported in Mbed TLS implementation of PSA + * APIs. + */ +#if (defined(PSA_WANT_KEY_TYPE_AES) || defined(PSA_WANT_KEY_TYPE_ARIA) || \ + defined(PSA_WANT_KEY_TYPE_CAMELLIA) || defined(PSA_WANT_KEY_TYPE_CHACHA20)) +#define PSA_CIPHER_MAX_KEY_LENGTH 32u +#elif defined(PSA_WANT_KEY_TYPE_DES) +#define PSA_CIPHER_MAX_KEY_LENGTH 24u +#else +#define PSA_CIPHER_MAX_KEY_LENGTH 0u +#endif + /** The default IV size for a cipher algorithm, in bytes. * * The IV that is generated as part of a call to #psa_cipher_encrypt() is always diff --git a/lib/ext/mbedcrypto/0001-Add-TF-M-Builtin-Key-Loader-driver-entry-points.patch b/lib/ext/mbedcrypto/0001-Add-TF-M-Builtin-Key-Loader-driver-entry-points.patch index 48de7bab11..7b9cd4802d 100644 --- a/lib/ext/mbedcrypto/0001-Add-TF-M-Builtin-Key-Loader-driver-entry-points.patch +++ b/lib/ext/mbedcrypto/0001-Add-TF-M-Builtin-Key-Loader-driver-entry-points.patch @@ -1,7 +1,7 @@ -From 4b2df7aeedd3fec1f46766afb39a36f5e2b6be59 Mon Sep 17 00:00:00 2001 +From 91ebcce1e2a1cc5f84fc378e22f625e519951f76 Mon Sep 17 00:00:00 2001 From: Antonio de Angelis Date: Thu, 21 Mar 2024 11:44:56 +0000 -Subject: [PATCH 1/6] Add TF-M Builtin Key Loader driver entry points +Subject: [PATCH 1/7] Add TF-M Builtin Key Loader driver entry points TF-M requires a mechanism to leverage the drivers and builtin keys at the same time to allow for @@ -18,7 +18,7 @@ Co-authored-by: Antonio de Angelis 3 files changed, 143 insertions(+), 9 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c -index c4f41db10..5180435de 100644 +index 348c79cf4..78fa0205a 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -73,6 +73,10 @@ @@ -32,7 +32,7 @@ index c4f41db10..5180435de 100644 #if defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF) || \ defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF_EXTRACT) || \ defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF_EXPAND) -@@ -1166,7 +1170,11 @@ static psa_status_t psa_get_and_lock_transparent_key_slot_with_policy( +@@ -1172,7 +1176,11 @@ static psa_status_t psa_get_and_lock_transparent_key_slot_with_policy( return status; } @@ -46,7 +46,7 @@ index c4f41db10..5180435de 100644 *p_slot = NULL; return PSA_ERROR_NOT_SUPPORTED; diff --git a/library/psa_crypto_driver_wrappers.h b/library/psa_crypto_driver_wrappers.h -index b90155720..2e828115f 100644 +index 0ed221b50..17b129a02 100644 --- a/library/psa_crypto_driver_wrappers.h +++ b/library/psa_crypto_driver_wrappers.h @@ -42,16 +42,32 @@ @@ -129,7 +129,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -@@ -391,6 +422,9 @@ static inline psa_status_t psa_driver_wrapper_verify_hash( +@@ -390,6 +421,9 @@ static inline psa_status_t psa_driver_wrapper_verify_hash( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -139,7 +139,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -@@ -521,6 +555,9 @@ static inline psa_status_t psa_driver_wrapper_sign_hash_start( +@@ -519,6 +553,9 @@ static inline psa_status_t psa_driver_wrapper_sign_hash_start( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -149,7 +149,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ -@@ -613,6 +650,9 @@ static inline psa_status_t psa_driver_wrapper_verify_hash_start( +@@ -611,6 +648,9 @@ static inline psa_status_t psa_driver_wrapper_verify_hash_start( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -159,7 +159,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ -@@ -776,6 +816,9 @@ static inline psa_status_t psa_driver_wrapper_generate_key( +@@ -774,6 +814,9 @@ static inline psa_status_t psa_driver_wrapper_generate_key( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -169,7 +169,7 @@ index b90155720..2e828115f 100644 #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) /* Transparent drivers are limited to generating asymmetric keys. */ /* We don't support passing custom production parameters -@@ -880,6 +923,9 @@ static inline psa_status_t psa_driver_wrapper_import_key( +@@ -878,6 +921,9 @@ static inline psa_status_t psa_driver_wrapper_import_key( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -179,7 +179,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -@@ -981,6 +1027,9 @@ static inline psa_status_t psa_driver_wrapper_export_key( +@@ -979,6 +1025,9 @@ static inline psa_status_t psa_driver_wrapper_export_key( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -189,7 +189,7 @@ index b90155720..2e828115f 100644 return( psa_export_key_internal( attributes, key_buffer, key_buffer_size, -@@ -1087,6 +1136,9 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt( +@@ -1085,6 +1134,9 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -199,7 +199,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -@@ -1177,6 +1229,9 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt( +@@ -1175,6 +1227,9 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -209,7 +209,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -@@ -1254,6 +1309,9 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt_setup( +@@ -1252,6 +1307,9 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt_setup( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -219,7 +219,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -@@ -1327,6 +1385,9 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt_setup( +@@ -1325,6 +1383,9 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt_setup( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -229,7 +229,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -@@ -1727,6 +1788,9 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt( +@@ -1725,6 +1786,9 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -239,7 +239,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ -@@ -1779,6 +1843,9 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt( +@@ -1777,6 +1841,9 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -249,7 +249,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ -@@ -1828,6 +1895,9 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt_setup( +@@ -1826,6 +1893,9 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt_setup( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -259,7 +259,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ -@@ -1876,6 +1946,9 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt_setup( +@@ -1874,6 +1944,9 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt_setup( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -269,7 +269,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ -@@ -2212,6 +2285,9 @@ static inline psa_status_t psa_driver_wrapper_mac_compute( +@@ -2210,6 +2283,9 @@ static inline psa_status_t psa_driver_wrapper_mac_compute( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -279,7 +279,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -@@ -2276,6 +2352,9 @@ static inline psa_status_t psa_driver_wrapper_mac_sign_setup( +@@ -2274,6 +2350,9 @@ static inline psa_status_t psa_driver_wrapper_mac_sign_setup( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -289,7 +289,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -@@ -2348,6 +2427,9 @@ static inline psa_status_t psa_driver_wrapper_mac_verify_setup( +@@ -2346,6 +2425,9 @@ static inline psa_status_t psa_driver_wrapper_mac_verify_setup( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -299,7 +299,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -@@ -2548,6 +2630,9 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_encrypt( +@@ -2546,6 +2628,9 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_encrypt( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -309,7 +309,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -@@ -2606,6 +2691,9 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_decrypt( +@@ -2604,6 +2689,9 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_decrypt( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -319,7 +319,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -@@ -2670,6 +2758,9 @@ static inline psa_status_t psa_driver_wrapper_key_agreement( +@@ -2668,6 +2756,9 @@ static inline psa_status_t psa_driver_wrapper_key_agreement( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: @@ -329,7 +329,7 @@ index b90155720..2e828115f 100644 /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) -@@ -2750,6 +2841,9 @@ static inline psa_status_t psa_driver_wrapper_pake_setup( +@@ -2748,6 +2839,9 @@ static inline psa_status_t psa_driver_wrapper_pake_setup( switch( location ) { case PSA_KEY_LOCATION_LOCAL_STORAGE: diff --git a/lib/ext/mbedcrypto/0002-Enable-crypto-code-sharing-between-independent-binar.patch b/lib/ext/mbedcrypto/0002-Enable-crypto-code-sharing-between-independent-binar.patch index 8383b2674f..2283d0b42a 100644 --- a/lib/ext/mbedcrypto/0002-Enable-crypto-code-sharing-between-independent-binar.patch +++ b/lib/ext/mbedcrypto/0002-Enable-crypto-code-sharing-between-independent-binar.patch @@ -1,7 +1,7 @@ -From 3d59b2503307a50882e54553ea2b879f30fc1f00 Mon Sep 17 00:00:00 2001 +From 8df3803e2ab01bb5955e3a52fbd5e7ec3a601fc3 Mon Sep 17 00:00:00 2001 From: Tamas Ban Date: Tue, 27 Oct 2020 08:55:37 +0000 -Subject: [PATCH 2/6] Enable crypto code sharing between independent binaries +Subject: [PATCH 2/7] Enable crypto code sharing between independent binaries Signed-off-by: Tamas Ban --- diff --git a/lib/ext/mbedcrypto/0003-Allow-SE-key-to-use-key-vendor-id-within-PSA-crypto.patch b/lib/ext/mbedcrypto/0003-Allow-SE-key-to-use-key-vendor-id-within-PSA-crypto.patch index b91f5c47bf..04dd5ea1b5 100644 --- a/lib/ext/mbedcrypto/0003-Allow-SE-key-to-use-key-vendor-id-within-PSA-crypto.patch +++ b/lib/ext/mbedcrypto/0003-Allow-SE-key-to-use-key-vendor-id-within-PSA-crypto.patch @@ -1,7 +1,7 @@ -From 5035d84a049e59fd5973c61a913db38b0dc20949 Mon Sep 17 00:00:00 2001 +From 4c730658542be6eb6a3e571f95aa1398e1f990de Mon Sep 17 00:00:00 2001 From: Benjamin Baratte Date: Thu, 9 Feb 2023 10:35:01 +0100 -Subject: [PATCH 3/6] Allow SE key to use key vendor id within PSA crypto +Subject: [PATCH 3/7] Allow SE key to use key vendor id within PSA crypto Signed-off-by: Benjamin Baratte --- @@ -9,10 +9,10 @@ Signed-off-by: Benjamin Baratte 1 file changed, 4 insertions(+) diff --git a/library/psa_crypto.c b/library/psa_crypto.c -index 5180435de..589a00e6e 100644 +index 78fa0205a..95f37fe2c 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c -@@ -1719,7 +1719,11 @@ static psa_status_t psa_validate_key_attributes( +@@ -1732,7 +1732,11 @@ static psa_status_t psa_validate_key_attributes( return PSA_ERROR_INVALID_ARGUMENT; } } else { diff --git a/lib/ext/mbedcrypto/0004-Initialise-driver-wrappers-as-first-step-in-psa_cryp.patch b/lib/ext/mbedcrypto/0004-Initialise-driver-wrappers-as-first-step-in-psa_cryp.patch index 6fea7612e9..11c778dffa 100644 --- a/lib/ext/mbedcrypto/0004-Initialise-driver-wrappers-as-first-step-in-psa_cryp.patch +++ b/lib/ext/mbedcrypto/0004-Initialise-driver-wrappers-as-first-step-in-psa_cryp.patch @@ -1,7 +1,7 @@ -From f7ee76eb24a88e7168749e273f76282658da6ca9 Mon Sep 17 00:00:00 2001 +From 0803fb5aea0768c37cb027af0af9223c2f0f47a9 Mon Sep 17 00:00:00 2001 From: Antonio de Angelis Date: Thu, 21 Mar 2024 11:58:19 +0000 -Subject: [PATCH 4/6] Initialise driver wrappers as first step in +Subject: [PATCH 4/7] Initialise driver wrappers as first step in psa_crypto_init() This patch amends the order of initialisations performed in @@ -16,10 +16,10 @@ Signed-off-by: Antonio de Angelis 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c -index 589a00e6e..d3f729320 100644 +index 95f37fe2c..451e95492 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c -@@ -8341,12 +8341,12 @@ psa_status_t psa_crypto_init(void) +@@ -8483,12 +8483,12 @@ psa_status_t psa_crypto_init(void) return PSA_SUCCESS; } diff --git a/lib/ext/mbedcrypto/0005-Hardcode-CC3XX-entry-points.patch b/lib/ext/mbedcrypto/0005-Hardcode-CC3XX-entry-points.patch index 7661c44357..d423bdaa35 100644 --- a/lib/ext/mbedcrypto/0005-Hardcode-CC3XX-entry-points.patch +++ b/lib/ext/mbedcrypto/0005-Hardcode-CC3XX-entry-points.patch @@ -1,7 +1,7 @@ -From 49e1f6ec6bc1a5a52a82b0cbb423db7c361f2896 Mon Sep 17 00:00:00 2001 +From cf0fc2373fce8d7110a5afb5f6c7bf4d48235ad9 Mon Sep 17 00:00:00 2001 From: Antonio de Angelis Date: Thu, 21 Mar 2024 12:58:37 +0000 -Subject: [PATCH 5/6] Hardcode CC3XX entry points +Subject: [PATCH 5/7] Hardcode CC3XX entry points Manually hardcode PSA driver entry points for the CC3XX driver into psa crypto driver wrappers file (and provide missing entry point @@ -12,9 +12,9 @@ Signed-off-by: Antonio de Angelis --- .../psa/crypto_driver_contexts_composites.h | 10 + .../psa/crypto_driver_contexts_primitives.h | 10 + - library/psa_crypto_driver_wrappers.h | 426 ++++++++++++++++-- + library/psa_crypto_driver_wrappers.h | 431 ++++++++++++++++-- .../psa_crypto_driver_wrappers_no_static.c | 24 + - 4 files changed, 441 insertions(+), 29 deletions(-) + 4 files changed, 446 insertions(+), 29 deletions(-) diff --git a/include/psa/crypto_driver_contexts_composites.h b/include/psa/crypto_driver_contexts_composites.h index d717c5190..f6a54aefd 100644 @@ -87,7 +87,7 @@ index c90a5fbe7..3f00006f8 100644 #endif /* PSA_CRYPTO_DRIVER_CONTEXTS_PRIMITIVES_H */ diff --git a/library/psa_crypto_driver_wrappers.h b/library/psa_crypto_driver_wrappers.h -index 2e828115f..3a8f3a0f9 100644 +index 17b129a02..5c581ff72 100644 --- a/library/psa_crypto_driver_wrappers.h +++ b/library/psa_crypto_driver_wrappers.h @@ -53,6 +53,16 @@ @@ -258,8 +258,8 @@ index 2e828115f..3a8f3a0f9 100644 +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ #if defined (MBEDTLS_PSA_P256M_DRIVER_ENABLED) if( PSA_KEY_TYPE_IS_ECC( psa_get_key_type(attributes) ) && - PSA_ALG_IS_ECDSA(alg) && -@@ -442,6 +499,17 @@ static inline psa_status_t psa_driver_wrapper_verify_hash( + PSA_ALG_IS_RANDOMIZED_ECDSA(alg) && +@@ -441,6 +498,17 @@ static inline psa_status_t psa_driver_wrapper_verify_hash( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -277,7 +277,7 @@ index 2e828115f..3a8f3a0f9 100644 #if defined (MBEDTLS_PSA_P256M_DRIVER_ENABLED) if( PSA_KEY_TYPE_IS_ECC( psa_get_key_type(attributes) ) && PSA_ALG_IS_ECDSA(alg) && -@@ -835,6 +903,12 @@ static inline psa_status_t psa_driver_wrapper_generate_key( +@@ -833,6 +901,12 @@ static inline psa_status_t psa_driver_wrapper_generate_key( if( status != PSA_ERROR_NOT_SUPPORTED ) break; #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -290,7 +290,7 @@ index 2e828115f..3a8f3a0f9 100644 #if defined(MBEDTLS_PSA_P256M_DRIVER_ENABLED) if( PSA_KEY_TYPE_IS_ECC( psa_get_key_type(attributes) ) && psa_get_key_type(attributes) == PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1) && -@@ -1158,6 +1232,20 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt( +@@ -1156,6 +1230,20 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -311,7 +311,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) -@@ -1249,6 +1337,18 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt( +@@ -1247,6 +1335,18 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -330,7 +330,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) -@@ -1329,6 +1429,16 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt_setup( +@@ -1327,6 +1427,16 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt_setup( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -347,7 +347,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) /* Fell through, meaning no accelerator supports this operation */ -@@ -1405,6 +1515,16 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt_setup( +@@ -1403,6 +1513,16 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt_setup( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -364,7 +364,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) /* Fell through, meaning no accelerator supports this operation */ -@@ -1474,6 +1594,12 @@ static inline psa_status_t psa_driver_wrapper_cipher_set_iv( +@@ -1472,6 +1592,12 @@ static inline psa_status_t psa_driver_wrapper_cipher_set_iv( &operation->ctx.opaque_test_driver_ctx, iv, iv_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -377,7 +377,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ } -@@ -1517,6 +1643,13 @@ static inline psa_status_t psa_driver_wrapper_cipher_update( +@@ -1515,6 +1641,13 @@ static inline psa_status_t psa_driver_wrapper_cipher_update( input, input_length, output, output_size, output_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -391,7 +391,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ } -@@ -1557,6 +1690,12 @@ static inline psa_status_t psa_driver_wrapper_cipher_finish( +@@ -1555,6 +1688,12 @@ static inline psa_status_t psa_driver_wrapper_cipher_finish( &operation->ctx.opaque_test_driver_ctx, output, output_size, output_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -404,7 +404,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ } -@@ -1597,6 +1736,15 @@ static inline psa_status_t psa_driver_wrapper_cipher_abort( +@@ -1595,6 +1734,15 @@ static inline psa_status_t psa_driver_wrapper_cipher_abort( sizeof( operation->ctx.opaque_test_driver_ctx ) ); return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -420,7 +420,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ } -@@ -1618,12 +1766,19 @@ static inline psa_status_t psa_driver_wrapper_hash_compute( +@@ -1616,12 +1764,24 @@ static inline psa_status_t psa_driver_wrapper_hash_compute( psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; /* Try accelerators first */ @@ -435,13 +435,18 @@ index 2e828115f..3a8f3a0f9 100644 +#if defined(PSA_CRYPTO_DRIVER_CC3XX) + status = cc3xx_hash_compute(alg, input, input_length, hash, hash_size, + hash_length); -+ return status; ++#if defined(PSA_WANT_ALG_SHA_384) || defined(PSA_WANT_ALG_SHA_512) ++ if( status != PSA_ERROR_NOT_SUPPORTED ) ++ return( status ); ++#else ++ return( status ); ++#endif /* defined(PSA_WANT_ALG_SHA_384) || defined(PSA_WANT_ALG_SHA_512) */ +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ /* If software fallback is compiled in, try fallback */ #if defined(MBEDTLS_PSA_BUILTIN_HASH) -@@ -1650,6 +1805,7 @@ static inline psa_status_t psa_driver_wrapper_hash_setup( +@@ -1648,6 +1808,7 @@ static inline psa_status_t psa_driver_wrapper_hash_setup( psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; /* Try setup on accelerators first */ @@ -449,7 +454,7 @@ index 2e828115f..3a8f3a0f9 100644 #if defined(PSA_CRYPTO_DRIVER_TEST) status = mbedtls_test_transparent_hash_setup( &operation->ctx.test_driver_ctx, alg ); -@@ -1658,7 +1814,18 @@ static inline psa_status_t psa_driver_wrapper_hash_setup( +@@ -1656,7 +1817,18 @@ static inline psa_status_t psa_driver_wrapper_hash_setup( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); @@ -469,7 +474,7 @@ index 2e828115f..3a8f3a0f9 100644 /* If software fallback is compiled in, try fallback */ #if defined(MBEDTLS_PSA_BUILTIN_HASH) -@@ -1688,13 +1855,23 @@ static inline psa_status_t psa_driver_wrapper_hash_clone( +@@ -1686,13 +1858,23 @@ static inline psa_status_t psa_driver_wrapper_hash_clone( return( mbedtls_psa_hash_clone( &source_operation->ctx.mbedtls_ctx, &target_operation->ctx.mbedtls_ctx ) ); #endif @@ -494,7 +499,7 @@ index 2e828115f..3a8f3a0f9 100644 default: (void) target_operation; return( PSA_ERROR_BAD_STATE ); -@@ -1713,12 +1890,20 @@ static inline psa_status_t psa_driver_wrapper_hash_update( +@@ -1711,12 +1893,20 @@ static inline psa_status_t psa_driver_wrapper_hash_update( return( mbedtls_psa_hash_update( &operation->ctx.mbedtls_ctx, input, input_length ) ); #endif @@ -516,7 +521,7 @@ index 2e828115f..3a8f3a0f9 100644 default: (void) input; (void) input_length; -@@ -1739,12 +1924,20 @@ static inline psa_status_t psa_driver_wrapper_hash_finish( +@@ -1737,12 +1927,20 @@ static inline psa_status_t psa_driver_wrapper_hash_finish( return( mbedtls_psa_hash_finish( &operation->ctx.mbedtls_ctx, hash, hash_size, hash_length ) ); #endif @@ -538,7 +543,7 @@ index 2e828115f..3a8f3a0f9 100644 default: (void) hash; (void) hash_size; -@@ -1762,11 +1955,18 @@ static inline psa_status_t psa_driver_wrapper_hash_abort( +@@ -1760,11 +1958,18 @@ static inline psa_status_t psa_driver_wrapper_hash_abort( case PSA_CRYPTO_MBED_TLS_DRIVER_ID: return( mbedtls_psa_hash_abort( &operation->ctx.mbedtls_ctx ) ); #endif @@ -558,7 +563,7 @@ index 2e828115f..3a8f3a0f9 100644 default: return( PSA_ERROR_BAD_STATE ); } -@@ -1807,6 +2007,17 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt( +@@ -1805,6 +2010,17 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -576,7 +581,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ /* Fell through, meaning no accelerator supports this operation */ -@@ -1862,6 +2073,17 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt( +@@ -1860,6 +2076,17 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -594,7 +599,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ /* Fell through, meaning no accelerator supports this operation */ -@@ -1913,6 +2135,15 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt_setup( +@@ -1911,6 +2138,15 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt_setup( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -610,7 +615,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ /* Fell through, meaning no accelerator supports this operation */ -@@ -1965,6 +2196,16 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt_setup( +@@ -1963,6 +2199,16 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt_setup( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -627,7 +632,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ /* Fell through, meaning no accelerator supports this operation */ -@@ -2011,6 +2252,12 @@ static inline psa_status_t psa_driver_wrapper_aead_set_nonce( +@@ -2009,6 +2255,12 @@ static inline psa_status_t psa_driver_wrapper_aead_set_nonce( /* Add cases for opaque driver here */ #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -640,7 +645,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ } -@@ -2045,6 +2292,12 @@ static inline psa_status_t psa_driver_wrapper_aead_set_lengths( +@@ -2043,6 +2295,12 @@ static inline psa_status_t psa_driver_wrapper_aead_set_lengths( /* Add cases for opaque driver here */ #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -653,7 +658,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ } -@@ -2079,6 +2332,12 @@ static inline psa_status_t psa_driver_wrapper_aead_update_ad( +@@ -2077,6 +2335,12 @@ static inline psa_status_t psa_driver_wrapper_aead_update_ad( /* Add cases for opaque driver here */ #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -666,7 +671,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ } -@@ -2118,6 +2377,13 @@ static inline psa_status_t psa_driver_wrapper_aead_update( +@@ -2116,6 +2380,13 @@ static inline psa_status_t psa_driver_wrapper_aead_update( /* Add cases for opaque driver here */ #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -680,7 +685,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ } -@@ -2162,6 +2428,13 @@ static inline psa_status_t psa_driver_wrapper_aead_finish( +@@ -2160,6 +2431,13 @@ static inline psa_status_t psa_driver_wrapper_aead_finish( /* Add cases for opaque driver here */ #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -694,7 +699,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ } -@@ -2226,6 +2499,13 @@ static inline psa_status_t psa_driver_wrapper_aead_verify( +@@ -2224,6 +2502,13 @@ static inline psa_status_t psa_driver_wrapper_aead_verify( /* Add cases for opaque driver here */ #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -708,7 +713,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ } -@@ -2258,6 +2538,11 @@ static inline psa_status_t psa_driver_wrapper_aead_abort( +@@ -2256,6 +2541,11 @@ static inline psa_status_t psa_driver_wrapper_aead_abort( /* Add cases for opaque driver here */ #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -720,7 +725,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ } -@@ -2300,6 +2585,12 @@ static inline psa_status_t psa_driver_wrapper_mac_compute( +@@ -2298,6 +2588,12 @@ static inline psa_status_t psa_driver_wrapper_mac_compute( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -733,7 +738,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #if defined(MBEDTLS_PSA_BUILTIN_MAC) /* Fell through, meaning no accelerator supports this operation */ -@@ -2371,6 +2662,15 @@ static inline psa_status_t psa_driver_wrapper_mac_sign_setup( +@@ -2369,6 +2665,15 @@ static inline psa_status_t psa_driver_wrapper_mac_sign_setup( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -749,7 +754,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #if defined(MBEDTLS_PSA_BUILTIN_MAC) /* Fell through, meaning no accelerator supports this operation */ -@@ -2446,6 +2746,15 @@ static inline psa_status_t psa_driver_wrapper_mac_verify_setup( +@@ -2444,6 +2749,15 @@ static inline psa_status_t psa_driver_wrapper_mac_verify_setup( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -765,7 +770,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #if defined(MBEDTLS_PSA_BUILTIN_MAC) /* Fell through, meaning no accelerator supports this operation */ -@@ -2513,6 +2822,10 @@ static inline psa_status_t psa_driver_wrapper_mac_update( +@@ -2511,6 +2825,10 @@ static inline psa_status_t psa_driver_wrapper_mac_update( &operation->ctx.opaque_test_driver_ctx, input, input_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -776,7 +781,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: (void) input; -@@ -2547,6 +2860,11 @@ static inline psa_status_t psa_driver_wrapper_mac_sign_finish( +@@ -2545,6 +2863,11 @@ static inline psa_status_t psa_driver_wrapper_mac_sign_finish( &operation->ctx.opaque_test_driver_ctx, mac, mac_size, mac_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -788,7 +793,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: (void) mac; -@@ -2581,6 +2899,12 @@ static inline psa_status_t psa_driver_wrapper_mac_verify_finish( +@@ -2579,6 +2902,12 @@ static inline psa_status_t psa_driver_wrapper_mac_verify_finish( &operation->ctx.opaque_test_driver_ctx, mac, mac_length ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -801,7 +806,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: (void) mac; -@@ -2608,6 +2932,10 @@ static inline psa_status_t psa_driver_wrapper_mac_abort( +@@ -2606,6 +2935,10 @@ static inline psa_status_t psa_driver_wrapper_mac_abort( return( mbedtls_test_opaque_mac_abort( &operation->ctx.opaque_test_driver_ctx ) ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -812,7 +817,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ default: return( PSA_ERROR_INVALID_ARGUMENT ); -@@ -2645,6 +2973,20 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_encrypt( +@@ -2643,6 +2976,20 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_encrypt( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -833,7 +838,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ return( mbedtls_psa_asymmetric_encrypt( attributes, key_buffer, key_buffer_size, alg, input, input_length, -@@ -2706,6 +3048,20 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_decrypt( +@@ -2704,6 +3051,20 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_decrypt( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ @@ -854,7 +859,7 @@ index 2e828115f..3a8f3a0f9 100644 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ return( mbedtls_psa_asymmetric_decrypt( attributes, key_buffer, key_buffer_size, alg,input, input_length, -@@ -2773,6 +3129,18 @@ static inline psa_status_t psa_driver_wrapper_key_agreement( +@@ -2771,6 +3132,18 @@ static inline psa_status_t psa_driver_wrapper_key_agreement( if( status != PSA_ERROR_NOT_SUPPORTED ) return( status ); #endif /* PSA_CRYPTO_DRIVER_TEST */ diff --git a/lib/ext/mbedcrypto/0006-Enable-psa_can_do_hash.patch b/lib/ext/mbedcrypto/0006-Enable-psa_can_do_hash.patch index 755a0eba9a..501c857223 100644 --- a/lib/ext/mbedcrypto/0006-Enable-psa_can_do_hash.patch +++ b/lib/ext/mbedcrypto/0006-Enable-psa_can_do_hash.patch @@ -1,7 +1,7 @@ -From b9e1f06ba19b1c05557fd082ea8fa2f8f1b0c0a2 Mon Sep 17 00:00:00 2001 +From 29fa390e489ace016b9d1dcb2843c81d1e4067f3 Mon Sep 17 00:00:00 2001 From: Antonio de Angelis Date: Thu, 21 Mar 2024 13:02:44 +0000 -Subject: [PATCH 6/6] Enable psa_can_do_hash +Subject: [PATCH 6/7] Enable psa_can_do_hash CC312 driver want to use hash in md for entropy operations. Enable psa_can_do_hash by directly returning 1. @@ -14,7 +14,7 @@ Signed-off-by: Summer Qin 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c -index d3f729320..68895738e 100644 +index 451e95492..af630d590 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -288,7 +288,8 @@ static uint8_t psa_get_drivers_initialized(void) diff --git a/lib/ext/mbedcrypto/0007-P256M-Add-option-to-force-not-use-of-asm.patch b/lib/ext/mbedcrypto/0007-P256M-Add-option-to-force-not-use-of-asm.patch new file mode 100644 index 0000000000..9561b26855 --- /dev/null +++ b/lib/ext/mbedcrypto/0007-P256M-Add-option-to-force-not-use-of-asm.patch @@ -0,0 +1,30 @@ +From c47b819cefb69a9c7e9f5cdd2dbd3d9a91b16f66 Mon Sep 17 00:00:00 2001 +From: Antonio de Angelis +Date: Wed, 9 Oct 2024 13:36:42 +0100 +Subject: [PATCH 7/7] P256M: Add option to force not use of asm + +Add an option to let the compiler generate the assembly +code for u32_muladd64(), especially for MinSizeRel and +Release builds. + +Signed-off-by: Antonio de Angelis +--- + 3rdparty/p256-m/p256-m/p256-m.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/3rdparty/p256-m/p256-m/p256-m.c b/3rdparty/p256-m/p256-m/p256-m.c +index 42c35b5bf..558a8bc95 100644 +--- a/3rdparty/p256-m/p256-m/p256-m.c ++++ b/3rdparty/p256-m/p256-m/p256-m.c +@@ -197,7 +197,7 @@ static uint64_t u32_muladd64(uint32_t x, uint32_t y, uint32_t z, uint32_t t); + * v7-M architectures. __ARM_ARCH_PROFILE is not defined for v6 and earlier. + * Thumb and 32-bit assembly is supported; aarch64 is not supported. + */ +-#if defined(__GNUC__) &&\ ++#if !defined(MULADD64_IGNORE_ASM) && defined(__GNUC__) &&\ + defined(__ARM_ARCH) && __ARM_ARCH >= 6 && defined(__ARM_ARCH_PROFILE) && \ + ( __ARM_ARCH_PROFILE == 77 || __ARM_ARCH_PROFILE == 65 ) /* 'M' or 'A' */ && \ + !defined(__aarch64__) +-- +2.34.1 + From 3a531a698be4aef9e101c3037b9b2dfe769101af Mon Sep 17 00:00:00 2001 From: Antonio de Angelis Date: Fri, 11 Apr 2025 13:44:41 +0100 Subject: [PATCH 2/5] Crypto: Update mbed TLS includes that were missed in the first upgrade When upgrading from Mbed TLS 3.6.2 to 3.6.3, a cherry-pick was created from the patch on main, but for some reason a few headers for the interface/include/mbedtls directory were not upgraded correctly. This would lead to issue in integration such as SDKs or the Zephyr one, if both projects are present will lead to header mismatches with code. Signed-off-by: Antonio de Angelis Change-Id: I3ab88ddd57b82d3bf5b093955274ad9cdd4e90fc (cherry picked from commit 19cf6fabe8d218d3471518158c493f316a2b23c3) --- interface/include/mbedtls/build_info.h | 8 +- interface/include/mbedtls/error.h | 2 +- interface/include/mbedtls/ssl.h | 104 ++++++++++++++++++++++--- 3 files changed, 99 insertions(+), 15 deletions(-) diff --git a/interface/include/mbedtls/build_info.h b/interface/include/mbedtls/build_info.h index d91d2964b6..e70c4d7cc5 100644 --- a/interface/include/mbedtls/build_info.h +++ b/interface/include/mbedtls/build_info.h @@ -26,16 +26,16 @@ */ #define MBEDTLS_VERSION_MAJOR 3 #define MBEDTLS_VERSION_MINOR 6 -#define MBEDTLS_VERSION_PATCH 2 +#define MBEDTLS_VERSION_PATCH 3 /** * The single version number has the following structure: * MMNNPP00 * Major version | Minor version | Patch version */ -#define MBEDTLS_VERSION_NUMBER 0x03060200 -#define MBEDTLS_VERSION_STRING "3.6.2" -#define MBEDTLS_VERSION_STRING_FULL "Mbed TLS 3.6.2" +#define MBEDTLS_VERSION_NUMBER 0x03060300 +#define MBEDTLS_VERSION_STRING "3.6.3" +#define MBEDTLS_VERSION_STRING_FULL "Mbed TLS 3.6.3" /* Macros for build-time platform detection */ diff --git a/interface/include/mbedtls/error.h b/interface/include/mbedtls/error.h index 186589ac5b..635f7cd842 100644 --- a/interface/include/mbedtls/error.h +++ b/interface/include/mbedtls/error.h @@ -81,7 +81,7 @@ * MD 5 5 * HKDF 5 1 (Started from top) * PKCS7 5 12 (Started from 0x5300) - * SSL 5 2 (Started from 0x5F00) + * SSL 5 3 (Started from 0x5F00) * CIPHER 6 8 (Started from 0x6080) * SSL 6 22 (Started from top, plus 0x6000) * SSL 7 20 (Started from 0x7000, gaps at diff --git a/interface/include/mbedtls/ssl.h b/interface/include/mbedtls/ssl.h index 97b0dcb380..f9b103e382 100644 --- a/interface/include/mbedtls/ssl.h +++ b/interface/include/mbedtls/ssl.h @@ -166,6 +166,42 @@ #define MBEDTLS_ERR_SSL_VERSION_MISMATCH -0x5F00 /** Invalid value in SSL config */ #define MBEDTLS_ERR_SSL_BAD_CONFIG -0x5E80 +/* Error space gap */ +/** Attempt to verify a certificate without an expected hostname. + * This is usually insecure. + * + * In TLS clients, when a client authenticates a server through its + * certificate, the client normally checks three things: + * - the certificate chain must be valid; + * - the chain must start from a trusted CA; + * - the certificate must cover the server name that is expected by the client. + * + * Omitting any of these checks is generally insecure, and can allow a + * malicious server to impersonate a legitimate server. + * + * The third check may be safely skipped in some unusual scenarios, + * such as networks where eavesdropping is a risk but not active attacks, + * or a private PKI where the client equally trusts all servers that are + * accredited by the root CA. + * + * You should call mbedtls_ssl_set_hostname() with the expected server name + * before starting a TLS handshake on a client (unless the client is + * set up to only use PSK-based authentication, which does not rely on the + * host name). If you have determined that server name verification is not + * required for security in your scenario, call mbedtls_ssl_set_hostname() + * with \p NULL as the server name. + * + * This error is raised if all of the following conditions are met: + * + * - A TLS client is configured with the authentication mode + * #MBEDTLS_SSL_VERIFY_REQUIRED (default). + * - Certificate authentication is enabled. + * - The client does not call mbedtls_ssl_set_hostname(). + * - The configuration option + * #MBEDTLS_SSL_CLI_ALLOW_WEAK_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME + * is not enabled. + */ +#define MBEDTLS_ERR_SSL_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME -0x5D80 /* * Constants from RFC 8446 for TLS 1.3 PSK modes @@ -1893,8 +1929,35 @@ struct mbedtls_ssl_context { * User settings */ #if defined(MBEDTLS_X509_CRT_PARSE_C) - char *MBEDTLS_PRIVATE(hostname); /*!< expected peer CN for verification - (and SNI if available) */ + /** Expected peer CN for verification. + * + * Also used on clients for SNI, + * and for TLS 1.3 session resumption using tickets. + * + * The value of this field can be: + * - \p NULL in a newly initialized or reset context. + * - A heap-allocated copy of the last value passed to + * mbedtls_ssl_set_hostname(), if the last call had a non-null + * \p hostname argument. + * - A special value to indicate that mbedtls_ssl_set_hostname() + * was called with \p NULL (as opposed to never having been called). + * See `mbedtls_ssl_get_hostname_pointer()` in `ssl_tls.c`. + * + * If this field contains the value \p NULL and the configuration option + * #MBEDTLS_SSL_CLI_ALLOW_WEAK_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME + * is unset, on a TLS client, attempting to verify a server certificate + * results in the error + * #MBEDTLS_ERR_SSL_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME. + * + * If this field contains the special value described above, or if + * the value is \p NULL and the configuration option + * #MBEDTLS_SSL_CLI_ALLOW_WEAK_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME + * is set, then the peer name verification is skipped, which may be + * insecure, especially on a client. Furthermore, on a client, the + * server_name extension is not sent, and the server name is ignored + * in TLS 1.3 session resumption using tickets. + */ + char *MBEDTLS_PRIVATE(hostname); #endif /* MBEDTLS_X509_CRT_PARSE_C */ #if defined(MBEDTLS_SSL_ALPN) @@ -2002,6 +2065,14 @@ void mbedtls_ssl_init(mbedtls_ssl_context *ssl); * Calling mbedtls_ssl_setup again is not supported, even * if no session is active. * + * \warning After setting up a client context, if certificate-based + * authentication is enabled, you should call + * mbedtls_ssl_set_hostname() to specifiy the expected + * name of the server. Without this, in most scenarios, + * the TLS connection is insecure. See + * #MBEDTLS_ERR_SSL_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME + * for more information. + * * \note If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto * subsystem must have been initialized by calling * psa_crypto_init() before calling this function. @@ -3976,16 +4047,29 @@ void mbedtls_ssl_conf_sig_algs(mbedtls_ssl_config *conf, #if defined(MBEDTLS_X509_CRT_PARSE_C) /** * \brief Set or reset the hostname to check against the received - * server certificate. It sets the ServerName TLS extension, - * too, if that extension is enabled. (client-side only) + * peer certificate. On a client, this also sets the + * ServerName TLS extension, if that extension is enabled. + * On a TLS 1.3 client, this also sets the server name in + * the session resumption ticket, if that feature is enabled. * * \param ssl SSL context - * \param hostname the server hostname, may be NULL to clear hostname - - * \note Maximum hostname length MBEDTLS_SSL_MAX_HOST_NAME_LEN. - * - * \return 0 if successful, MBEDTLS_ERR_SSL_ALLOC_FAILED on - * allocation failure, MBEDTLS_ERR_SSL_BAD_INPUT_DATA on + * \param hostname The server hostname. This may be \c NULL to clear + * the hostname. + * + * \note Maximum hostname length #MBEDTLS_SSL_MAX_HOST_NAME_LEN. + * + * \note If the hostname is \c NULL on a client, then the server + * is not authenticated: it only needs to have a valid + * certificate, not a certificate matching its name. + * Therefore you should always call this function on a client, + * unless the connection is set up to only allow + * pre-shared keys, or in scenarios where server + * impersonation is not a concern. See the documentation of + * #MBEDTLS_ERR_SSL_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME + * for more details. + * + * \return 0 if successful, #MBEDTLS_ERR_SSL_ALLOC_FAILED on + * allocation failure, #MBEDTLS_ERR_SSL_BAD_INPUT_DATA on * too long input hostname. * * Hostname set to the one provided on success (cleared From 63c65ae61a64e7bbfcb42927ce05261a8bd4621a Mon Sep 17 00:00:00 2001 From: Antonio de Angelis Date: Fri, 11 Apr 2025 16:00:53 +0100 Subject: [PATCH 3/5] Interface: Align comments on psa/client.h and psa/service.h Align comments on psa/client.h and psa/service.h. Signed-off-by: Antonio de Angelis Change-Id: I6b5497bc46494ff9466e8291bc7e48684f90daa8 (cherry picked from commit 92cb06afe941e9c9fb4fad2516862fa558bff836) --- interface/include/psa/client.h | 19 +++--- interface/include/psa/service.h | 115 ++++++++++++-------------------- 2 files changed, 55 insertions(+), 79 deletions(-) diff --git a/interface/include/psa/client.h b/interface/include/psa/client.h index b4e8b09708..61722e3ad8 100644 --- a/interface/include/psa/client.h +++ b/interface/include/psa/client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Arm Limited. All rights reserved. + * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors * * SPDX-License-Identifier: BSD-3-Clause * @@ -21,6 +21,13 @@ extern "C" { #define IOVEC_LEN(arr) ((uint32_t)(sizeof(arr)/sizeof(arr[0]))) #endif +/** + * Type definitions equivalent to size_t as defined in the RoT Service + * environment. + */ +typedef uint32_t rot_size_t; +#define ROT_SIZE_MAX UINT32_MAX + /*********************** PSA Client Macros and Types *************************/ /** @@ -180,13 +187,9 @@ psa_status_t psa_call(psa_handle_t handle, int32_t type, * \param[in] handle A handle to an established connection, or the * null handle. * - * \retval void Success. - * \retval "PROGRAMMER ERROR" The call is a PROGRAMMER ERROR if one or more - * of the following are true: - * \arg An invalid handle was provided that is not - * the null handle. - * \arg The connection is currently handling a - * request. + * \note The call is a PROGRAMMER ERROR if one or more of the following occurs: + * - An invalid handle was provided that is not the null handle. + * - The connection is currently handling a request. */ void psa_close(psa_handle_t handle); diff --git a/interface/include/psa/service.h b/interface/include/psa/service.h index 39fde10ab3..5c0c078370 100644 --- a/interface/include/psa/service.h +++ b/interface/include/psa/service.h @@ -140,10 +140,9 @@ psa_status_t psa_get(psa_signal_t signal, psa_msg_t *msg); * \param[in] msg_handle Handle for the client's message. * \param[in] rhandle Reverse handle allocated by the RoT Service. * - * \retval void Success, rhandle will be provided with all - * subsequent messages delivered on this - * connection. - * \retval "PROGRAMMER ERROR" msg_handle is invalid. + * \note When successful,rhandle will be provided with all subsequent messages + * delivered on this connection. + * \note The call is a "PROGRAMMER ERROR" if msg_handle is invalid. */ void psa_set_rhandle(psa_handle_t msg_handle, void *rhandle); @@ -207,17 +206,13 @@ size_t psa_skip(psa_handle_t msg_handle, uint32_t invec_idx, size_t num_bytes); * \param[in] num_bytes Number of bytes to write to the client output * vector. * - * \retval void Success - * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the - * following are true: - * \arg msg_handle is invalid. - * \arg msg_handle does not refer to a request - * message. - * \arg outvec_idx is equal to or greater than - * \ref PSA_MAX_IOVEC. - * \arg The memory reference for buffer is invalid. - * \arg The call attempts to write data past the end - * of the client output vector. + * \note The call is a "PROGRAMMER ERROR" if one or more of the following occur: + * - msg_handle is invalid. + * - msg_handle does not refer to a request message. + * - outvec_idx is equal to or greater than \ref PSA_MAX_IOVEC. + * - the memory reference for buffer is invalid. + * - the call attempts to write data past the end of the client output + * vector. */ void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx, const void *buffer, size_t num_bytes); @@ -229,12 +224,9 @@ void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx, * \param[in] status Message result value to be reported to the * client. * - * \retval void Success. - * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the - * following are true: - * \arg msg_handle is invalid. - * \arg An invalid status code is specified for the - * type of message. + * \note The call is a "PROGRAMMER ERROR" if one or more of the following occur: + * - msg_handle is invalid. + * - An invalid status code is specified for the type of message. */ void psa_reply(psa_handle_t msg_handle, psa_status_t status); @@ -243,18 +235,16 @@ void psa_reply(psa_handle_t msg_handle, psa_status_t status); * * \param[in] partition_id Secure Partition ID of the target partition. * - * \retval void Success. - * \retval "PROGRAMMER ERROR" partition_id does not correspond to a Secure - * Partition. + * \note The call is a "PROGRAMMER ERROR" if partition_id does not correspond to + * a Secure Partition. */ void psa_notify(int32_t partition_id); /** * \brief Clear the PSA_DOORBELL signal. * - * \retval void Success. - * \retval "PROGRAMMER ERROR" The Secure Partition's doorbell signal is not - * currently asserted. + * \note The call is a "PROGRAMMER ERROR" if the Secure Partition's doorbell + * signal is not currently asserted. */ void psa_clear(void); @@ -263,21 +253,17 @@ void psa_clear(void); * * \param[in] irq_signal The interrupt signal that has been processed. * - * \retval void Success. - * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the - * following are true: - * \arg irq_signal is not an interrupt signal. - * \arg irq_signal indicates more than one signal. - * \arg irq_signal is not currently asserted. - * \arg The interrupt is not using SLIH. + * \note The call is a "PROGRAMMER ERROR" if one or more of the following occur: + * - irq_signal is not an interrupt signal. + * - irq_signal indicates more than one signal. + * - irq_signal is not currently asserted. + * - The interrupt is not using SLIH. */ void psa_eoi(psa_signal_t irq_signal); /** * \brief Terminate execution within the calling Secure Partition and will not * return. - * - * \retval "Does not return" */ void psa_panic(void); @@ -289,10 +275,9 @@ void psa_panic(void); * signal value for an interrupt in the calling Secure * Partition. * - * \retval void - * \retval "PROGRAMMER ERROR" If one or more of the following are true: - * \arg \a irq_signal is not an interrupt signal. - * \arg \a irq_signal indicates more than one signal. + * \note The call is a "PROGRAMMER ERROR" if one or more of the following occur: + * - \a irq_signal is not an interrupt signal. + * - \a irq_signal indicates more than one signal. */ void psa_irq_enable(psa_signal_t irq_signal); @@ -323,13 +308,11 @@ psa_irq_status_t psa_irq_disable(psa_signal_t irq_signal); * currently asserted signal for an interrupt that is * defined to use FLIH handling. * - * \retval void - * \retval "Programmer Error" if one or more of the following are true: - * \arg \a irq_signal is not a signal for an interrupt - * that is specified with FLIH handling in the Secure - * Partition manifest. - * \arg \a irq_signal indicates more than one signal. - * \arg \a irq_signal is not currently asserted. + * \note The call is a "PROGRAMMER ERROR" if one or more of the following occur: + * - \a irq_signal is not a signal for an interrupt that is specified + * with FLIH handling in the Secure Partition manifest. + * - \a irq_signal indicates more than one signal. + * - \a irq_signal is not currently asserted. */ void psa_reset_signal(psa_signal_t irq_signal); @@ -369,18 +352,13 @@ const void *psa_map_invec(psa_handle_t msg_handle, uint32_t invec_idx); * \param[in] invec_idx Index of input vector to map. Must be * less than \ref PSA_MAX_IOVEC. * - * \retval void - * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the - * following are true: - * \arg msg_handle is invalid. - * \arg msg_handle does not refer to a request - * message. - * \arg invec_idx is equal to or greater than - * \ref PSA_MAX_IOVEC. - * \arg The input vector has not been mapped by a call - * to psa_map_invec(). - * \arg The input vector has already been unmapped by - * a call to psa_unmap_invec(). + * \note The call is a "PROGRAMMER ERROR" if one or more of the following occur: + * - msg_handle is invalid. + * - msg_handle does not refer to a request message. + * - invec_idx is equal to or greater than \ref PSA_MAX_IOVEC. + * - The input vector has not been mapped by a call to psa_map_invec(). + * - The input vector has already been unmapped by a call to + * psa_unmap_invec(). */ void psa_unmap_invec(psa_handle_t msg_handle, uint32_t invec_idx); @@ -421,18 +399,13 @@ void *psa_map_outvec(psa_handle_t msg_handle, uint32_t outvec_idx); * vector. This must be less than or equal to the * size of the output vector. * - * \retval void - * \retval "PROGRAMMER ERROR" The call is invalid, one or more of the - * following are true: - * \arg msg_handle is invalid. - * \arg msg_handle does not refer to a request - * message. - * \arg outvec_idx is equal to or greater than - * \ref PSA_MAX_IOVEC. - * \arg The output vector has not been mapped by a - * call to psa_map_outvec(). - * \arg The output vector has already been unmapped by - * a call to psa_unmap_outvec(). + * \note The call is a "PROGRAMMER ERROR" if one or more of the following occur: + * - msg_handle is invalid. + * - msg_handle does not refer to a request message. + * - outvec_idx is equal to or greater than \ref PSA_MAX_IOVEC. + * - The output vector has not been mapped by a call to psa_map_outvec(). + * - The output vector has already been unmapped by a call to + * psa_unmap_outvec(). */ void psa_unmap_outvec(psa_handle_t msg_handle, uint32_t outvec_idx, size_t len); From 8300dd8664d32cc8e39d30353e039d09554a46fd Mon Sep 17 00:00:00 2001 From: Antonio de Angelis Date: Fri, 11 Apr 2025 15:57:03 +0100 Subject: [PATCH 4/5] Crypto: The client side interface provides psa_can_do_hash() Once TF-M Crypto has booted up, there isn't any hashing algorithm that would require additional preparation steps hence everything would be ready to be run, provided that the core or drivers are built to support it, which could be investigated inspecting build time options. Signed-off-by: Antonio de Angelis Change-Id: I0386e1c74589e8d48d35f2ad533f0ecfb966c7f4 (cherry picked from commit bdffde9c634c9277c128e19510653be3c136d1a2) --- interface/src/tfm_crypto_api.c | 13 ++++++++++++- secure_fw/partitions/crypto/crypto_spe.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/interface/src/tfm_crypto_api.c b/interface/src/tfm_crypto_api.c index 65eae46824..f4edef9256 100644 --- a/interface/src/tfm_crypto_api.c +++ b/interface/src/tfm_crypto_api.c @@ -1,10 +1,11 @@ /* - * Copyright (c) 2018-2023, Arm Limited. All rights reserved. + * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors * * SPDX-License-Identifier: BSD-3-Clause * */ +#include #include #include @@ -63,6 +64,16 @@ TFM_CRYPTO_API(psa_status_t, psa_crypto_init)(void) return PSA_SUCCESS; } +TFM_CRYPTO_API(int, psa_can_do_hash)(psa_algorithm_t hash_alg) +{ + (void)hash_alg; + /* There isn't any hashing algorithm that would not be ready + * to be used after TF-M has booted up, hence this function + * just returns success all the time + */ + return (int)true; +} + TFM_CRYPTO_API(psa_status_t, psa_open_key)(psa_key_id_t id, psa_key_id_t *key) { diff --git a/secure_fw/partitions/crypto/crypto_spe.h b/secure_fw/partitions/crypto/crypto_spe.h index 61e85488b6..532f4929f9 100644 --- a/secure_fw/partitions/crypto/crypto_spe.h +++ b/secure_fw/partitions/crypto/crypto_spe.h @@ -24,6 +24,8 @@ #define psa_crypto_init \ PSA_FUNCTION_NAME(psa_crypto_init) +#define psa_can_do_hash \ + PSA_FUNCTION_NAME(psa_can_do_hash) #define psa_key_derivation_get_capacity \ PSA_FUNCTION_NAME(psa_key_derivation_get_capacity) #define psa_key_derivation_set_capacity \ From bcae4445fe14e90898e64afc9f076bc2d9805c84 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Tue, 18 Feb 2025 21:36:29 +1000 Subject: [PATCH 5/5] cmake: set `CMAKE_INSTALL_MESSAGE` in single location Respect the default value of `CMAKE_INSTALL_MESSAGE` set in `tfm_build_log_config.cmake` by removing the unconditional overrides in other files. This suppresses the dozens of `Installing: ...` messages output when `CONFIG_TFM_BUILD_LOG_QUIET=y`. Change-Id: Ic0be233a93062cced942908ff1c8f680dd5da893 Signed-off-by: Jordan Yates (cherry picked from commit 7141436201cc6b1efcff48dd9423cb2ea199632d) --- cmake/install.cmake | 3 --- config/tfm_build_log_config.cmake | 1 + platform/CMakeLists.txt | 3 --- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/cmake/install.cmake b/cmake/install.cmake index 8e4003f5f7..5ddd06e8fd 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -7,9 +7,6 @@ # #------------------------------------------------------------------------------- -# Skip "up-to-date" prints to avoid flooding the build output. Just print "installing" -set(CMAKE_INSTALL_MESSAGE LAZY) - install(DIRECTORY ${CMAKE_BINARY_DIR}/bin/ DESTINATION bin ) diff --git a/config/tfm_build_log_config.cmake b/config/tfm_build_log_config.cmake index a8e344ea9a..70e572fa09 100644 --- a/config/tfm_build_log_config.cmake +++ b/config/tfm_build_log_config.cmake @@ -13,6 +13,7 @@ if(CONFIG_TFM_BUILD_LOG_QUIET) set(CONFIG_TFM_MEMORY_USAGE_QUIET ON CACHE BOOL "Disable the memory usage report") set(CONFIG_TFM_PARSE_MANIFEST_QUIET ON CACHE BOOL "Parse manifest quietly") else() + set(CMAKE_INSTALL_MESSAGE LAZY CACHE BOOL "Output installation message generated by the install() command[ALWAYS,LAZY,NEVER]") set(CONFIG_TFM_PARTITION_QUIET OFF CACHE BOOL "Disable printing of partition configuration during build") set(CONFIG_TFM_MEMORY_USAGE_QUIET OFF CACHE BOOL "Disable the memory usage report") set(CONFIG_TFM_PARSE_MANIFEST_QUIET OFF CACHE BOOL "Parse manifest quietly") diff --git a/platform/CMakeLists.txt b/platform/CMakeLists.txt index 271ac4daf6..acb921af18 100644 --- a/platform/CMakeLists.txt +++ b/platform/CMakeLists.txt @@ -28,9 +28,6 @@ endif() set(PLATFORM_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Path to platform directory") -# Skip "up-to-date" prints to avoid flooding the build output. Just print "installing" -set(CMAKE_INSTALL_MESSAGE LAZY) - add_subdirectory(ext/target/${TFM_PLATFORM} target) #====================== CMSIS stack override interface ========================#