Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog.d/iar-1.1.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Bugfix
* Fix some IAR warnings.
24 changes: 24 additions & 0 deletions core/tf_psa_crypto_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@
* headers what we expect of them. */
#include "tf_psa_crypto_platform_requirements.h"

#if defined(__IAR_SYSTEMS_ICC__)
/* In IAR (at least IAR 9.40 for Arm), enabling the C11 annex K functions
* (memset_s(), memcpy_s(), ...) with `#define __STDC_WANT_LIB_EXT1__ 1`
* causes the non-s functions to be declared as deprecatd. We want some
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'deprecatd' to 'deprecated'.

Suggested change
* causes the non-s functions to be declared as deprecatd. We want some
* causes the non-s functions to be declared as deprecated. We want some

Copilot uses AI. Check for mistakes.
* s functions (specifically memset_s() and gmtime_s()), but we also want
* to be able to use the non-s functions. Try to hack around this:
*
* - tf_psa_crypto_platform_requirements.h enables annex K functions.
* - tf_psa_crypto_platform_requirements.h does not include any system
* header, so that a parent project such as Mbed TLS can declare
* more platform requirements after including only
* tf_psa_crypto_platform_requirements.h.
* - Then, here, we include a system header that causes the effects of
* `__STDC_WANT_LIB_EXT1__` to be analyzed.
* - These effects include the definition of the macro `__DEPREC`, but
* not yet the declaration of functions that use it (because stddef.h
* doesn't declare any affected function). We redeclare this macro
* to make the subsequent function declarations not be deprecated.
*/
#include <stddef.h>
#undef __DEPREC
#define __DEPREC
#endif
Comment on lines +48 to +51
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redefining a toolchain/system macro like __DEPREC in a widely-included header can leak into downstream includes and alter how unrelated headers declare deprecations (effectively disabling deprecation annotations beyond this library). A more contained approach would be to localize this workaround to implementation files, or to bracket only the specific system header inclusions that trigger the unwanted deprecations (and then restore the original macro), or to prefer a compiler pragma/warning-control mechanism where possible.

Copilot uses AI. Check for mistakes.

/* From this point onwards, ensure we have the library configuration and
* the configuration-derived macros. */
#include "tf-psa-crypto/build_info.h"
Expand Down
2 changes: 2 additions & 0 deletions core/tf_psa_crypto_platform_requirements.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef __STDC_WANT_LIB_EXT1__
/* Ask for the C11 gmtime_s() and memset_s() if available */
#define __STDC_WANT_LIB_EXT1__ 1
/* This causes IAR to deprecate non-s functions that have an Annex K
* equivalent. We hack around this in tf_psa_crypto_common.h. */
#endif

#if !defined(_POSIX_C_SOURCE)
Expand Down
5 changes: 3 additions & 2 deletions drivers/builtin/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,11 @@ mbedtls_aes_implementation mbedtls_aes_get_implementation(void)
}
#endif

#if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
#if defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
return MBEDTLS_AES_IMP_UNKNOWN;
#else
return MBEDTLS_AES_IMP_SOFTWARE;
#endif
return MBEDTLS_AES_IMP_UNKNOWN;
}

#if defined(MBEDTLS_CIPHER_MODE_XTS)
Expand Down
9 changes: 8 additions & 1 deletion drivers/builtin/src/bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@

#include "mbedtls/platform.h"


#if defined(__IAR_SYSTEMS_ICC__)
/* Suppress a very overeager warning from IAR: it dislikes a forward goto
* that bypasses the initialization of a variable, even if that variable
* is not used after the jump. (This is perfectly valid C; it would only
* be invalid C if jumping into a block from outside that block.)
*/
#pragma diag_suppress=Pe546 // transfer of control bypasses initialization
#endif

/*
* Conditionally select an MPI sign in constant time.
Expand Down
9 changes: 9 additions & 0 deletions drivers/builtin/src/psa_crypto_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@

#include <string.h>

#if defined(__IAR_SYSTEMS_ICC__)
/* Suppress a very overeager warning from IAR: it dislikes a forward goto
* that bypasses the initialization of a variable, even if that variable
* is not used after the jump. (This is perfectly valid C; it would only
* be invalid C if jumping into a block from outside that block.)
*/
#pragma diag_suppress=Pe546 // transfer of control bypasses initialization
#endif

#if defined(MBEDTLS_PSA_BUILTIN_CIPHER) || \
defined(MBEDTLS_PSA_BUILTIN_AEAD) || \
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_AES) || \
Expand Down
2 changes: 1 addition & 1 deletion framework
2 changes: 1 addition & 1 deletion platform/platform_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void mbedtls_platform_zeroize(void *buf, size_t len)
*/
__msan_unpoison(buf, len);
#endif
#elif defined(__STDC_LIB_EXT1__) && !defined(__IAR_SYSTEMS_ICC__)
#elif defined(__STDC_LIB_EXT1__)
memset_s(buf, len, 0, len);
#elif defined(_WIN32)
SecureZeroMemory(buf, len);
Expand Down
2 changes: 1 addition & 1 deletion tests/suites/host_test.function
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static int verify_int(char *str, intmax_t *p_value)
/* Limit the range to long: for large integers, the test framework will
* use expressions anyway. */
long value = strtol(str, &end, 0);
if (errno == EINVAL || *end != '\0') {
if (*end != '\0' || end == str) {
mbedtls_fprintf(stderr,
"Expected integer for parameter and got: %s\n", str);
return KEY_VALUE_MAPPING_NOT_FOUND;
Comment on lines 41 to 45
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strtol() errors aren’t fully handled here: overflow/underflow sets errno = ERANGE and returns a clamped value, which would currently be accepted and can yield incorrect test parameter values. Consider setting errno = 0 before calling strtol() and rejecting inputs when errno == ERANGE (in addition to the existing end == str / trailing characters checks).

Copilot uses AI. Check for mistakes.
Expand Down
25 changes: 24 additions & 1 deletion tests/suites/main_test.function
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
#define __USE_MINGW_ANSI_STDIO 1
#endif

#if defined(__IAR_SYSTEMS_ICC__)
/* With IAR, enable support for ::FILE functions in stdio.h.
*/
#define _DLIB_FILE_DESCRIPTOR 1
#endif

#include "mbedtls/build_info.h"

/* Test code may use deprecated identifiers only if the preprocessor symbol
Expand All @@ -55,6 +61,24 @@ __MBEDTLS_TEST_TEMPLATE__TEST_COMMON_HELPERS
/* Test Suite Code */


#if defined(__IAR_SYSTEMS_ICC__)
/* Suppress a very overeager warning from IAR: it dislikes a forward goto
* that bypasses the initialization of a variable, even if that variable
* is not used after the jump. (This is perfectly valid C; it would only
* be invalid C if jumping into a block from outside that block.)
*/
#pragma diag_suppress=Pe546 // transfer of control bypasses initialization

/* Temporarily suppress a perfectly reasonable warning from IAR that
* comes up very often in our unit tests: silent conversion of int to
* an enum type.
*
* Remove this when https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/707
* is fixed.
*/
#pragma diag_suppress=Pe188 // enumerated type mixed with another type
#endif
Comment on lines +64 to +80
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These diagnostic suppressions apply to the remainder of the translation unit and are not restored, which can mask unrelated warnings and make future debugging harder. Consider scoping them (e.g., using IAR’s diagnostic push/pop if available, or restoring with #pragma diag_default=Pe546 / #pragma diag_default=Pe188 after the affected section) so only the intended code patterns are covered.

Copilot uses AI. Check for mistakes.

#define TEST_SUITE_ACTIVE

__MBEDTLS_TEST_TEMPLATE__FUNCTIONS_CODE
Expand Down Expand Up @@ -219,7 +243,6 @@ static int check_test(size_t func_idx)
return ret;
}


__MBEDTLS_TEST_TEMPLATE__PLATFORM_CODE

#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
Expand Down
6 changes: 0 additions & 6 deletions tests/suites/test_suite_alignment.function
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ void mbedtls_byteswap(char *input_str, int size, char *expected_str)
/* BEGIN_CASE */
void get_byte()
{
uint8_t data[16];

for (size_t i = 0; i < sizeof(data); i++) {
data[i] = (uint8_t) i;
}

uint64_t u64 = 0x0706050403020100;
for (size_t b = 0; b < 8; b++) {
uint8_t expected = b;
Expand Down
24 changes: 12 additions & 12 deletions tests/suites/test_suite_psa_crypto.function
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,

/* Error didn't trigger, make test fail */
if (inject_error == 1) {
TEST_ASSERT(
!"One of the last psa_pake_input() calls should have returned the expected error.");
TEST_FAIL(
"One of the last psa_pake_input() calls should have returned the expected error.");
}
}

Expand Down Expand Up @@ -933,8 +933,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,

/* Error didn't trigger, make test fail */
if (inject_error == 1) {
TEST_ASSERT(
!"One of the last psa_pake_input() calls should have returned the expected error.");
TEST_FAIL(
"One of the last psa_pake_input() calls should have returned the expected error.");
}
}

Expand Down Expand Up @@ -1001,8 +1001,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,

/* Error didn't trigger, make test fail */
if (inject_error == 2) {
TEST_ASSERT(
!"One of the last psa_pake_input() calls should have returned the expected error.");
TEST_FAIL(
"One of the last psa_pake_input() calls should have returned the expected error.");
}

break;
Expand Down Expand Up @@ -1068,8 +1068,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,

/* Error didn't trigger, make test fail */
if (inject_error == 3) {
TEST_ASSERT(
!"One of the last psa_pake_input() calls should have returned the expected error.");
TEST_FAIL(
"One of the last psa_pake_input() calls should have returned the expected error.");
}
}

Expand Down Expand Up @@ -1128,8 +1128,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,

/* Error didn't trigger, make test fail */
if (inject_error == 3) {
TEST_ASSERT(
!"One of the last psa_pake_input() calls should have returned the expected error.");
TEST_FAIL(
"One of the last psa_pake_input() calls should have returned the expected error.");
}
}

Expand Down Expand Up @@ -1168,8 +1168,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,

/* Error didn't trigger, make test fail */
if (inject_error == 4) {
TEST_ASSERT(
!"One of the last psa_pake_input() calls should have returned the expected error.");
TEST_FAIL(
"One of the last psa_pake_input() calls should have returned the expected error.");
}

break;
Expand Down
24 changes: 12 additions & 12 deletions tests/suites/test_suite_psa_crypto_pake.function
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,
/* Error didn't trigger, make test fail */
if ((err_stage >= ERR_INJECT_ROUND1_SERVER_KEY_SHARE_PART1) &&
(err_stage <= ERR_INJECT_ROUND1_SERVER_ZK_PROOF_PART2)) {
TEST_ASSERT(
!"One of the last psa_pake_input() calls should have returned the expected error.");
TEST_FAIL(
"One of the last psa_pake_input() calls should have returned the expected error.");
}
}

Expand Down Expand Up @@ -348,8 +348,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,
/* Error didn't trigger, make test fail */
if ((err_stage >= ERR_INJECT_ROUND1_SERVER_KEY_SHARE_PART1) &&
(err_stage <= ERR_INJECT_ROUND1_SERVER_ZK_PROOF_PART2)) {
TEST_ASSERT(
!"One of the last psa_pake_input() calls should have returned the expected error.");
TEST_FAIL(
"One of the last psa_pake_input() calls should have returned the expected error.");
}
}

Expand Down Expand Up @@ -381,8 +381,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,
/* Error didn't trigger, make test fail */
if ((err_stage >= ERR_INJECT_ROUND1_CLIENT_KEY_SHARE_PART1) &&
(err_stage <= ERR_INJECT_ROUND1_CLIENT_ZK_PROOF_PART2)) {
TEST_ASSERT(
!"One of the last psa_pake_input() calls should have returned the expected error.");
TEST_FAIL(
"One of the last psa_pake_input() calls should have returned the expected error.");
}

break;
Expand Down Expand Up @@ -437,8 +437,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,
/* Error didn't trigger, make test fail */
if ((err_stage >= ERR_INJECT_ROUND2_SERVER_KEY_SHARE) &&
(err_stage <= ERR_INJECT_ROUND2_SERVER_ZK_PROOF)) {
TEST_ASSERT(
!"One of the last psa_pake_input() calls should have returned the expected error.");
TEST_FAIL(
"One of the last psa_pake_input() calls should have returned the expected error.");
}
}

Expand Down Expand Up @@ -501,8 +501,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,
/* Error didn't trigger, make test fail */
if ((err_stage >= ERR_INJECT_ROUND2_SERVER_KEY_SHARE) &&
(err_stage <= ERR_INJECT_ROUND2_SERVER_ZK_PROOF)) {
TEST_ASSERT(
!"One of the last psa_pake_input() calls should have returned the expected error.");
TEST_FAIL(
"One of the last psa_pake_input() calls should have returned the expected error.");
}
}

Expand All @@ -528,8 +528,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,
/* Error didn't trigger, make test fail */
if ((err_stage >= ERR_INJECT_ROUND2_CLIENT_KEY_SHARE) &&
(err_stage <= ERR_INJECT_ROUND2_CLIENT_ZK_PROOF)) {
TEST_ASSERT(
!"One of the last psa_pake_input() calls should have returned the expected error.");
TEST_FAIL(
"One of the last psa_pake_input() calls should have returned the expected error.");
}

break;
Expand Down
2 changes: 1 addition & 1 deletion tests/suites/test_suite_rsa.function
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ void mbedtls_rsa_validate_params(char *input_N,
have_D ? &D : NULL,
have_E ? &E : NULL,
prng ? mbedtls_test_rnd_std_rand : NULL,
prng ? NULL : NULL) == result);
NULL) == result);

exit:
mbedtls_mpi_free(&N);
Expand Down