From f3c04f3f47c242924a9927c6c411bb5464aa1107 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Tue, 5 Dec 2023 12:06:11 +0000 Subject: [PATCH 1/3] Better definition of MBEDTLS_IS_BIG_ENDIAN for IAR Signed-off-by: Dave Rodgman --- library/alignment.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/library/alignment.h b/library/alignment.h index 4aab8e027..634d61046 100644 --- a/library/alignment.h +++ b/library/alignment.h @@ -224,10 +224,25 @@ static inline uint64_t mbedtls_bswap64(uint64_t x) #endif /* !defined(MBEDTLS_BSWAP64) */ #if !defined(__BYTE_ORDER__) + +#if defined(__LITTLE_ENDIAN__) +/* IAR defines __xxx_ENDIAN__, but not __BYTE_ORDER__ */ +#define MBEDTLS_IS_BIG_ENDIAN 0 +#elif defined(__BIG_ENDIAN__) +#define MBEDTLS_IS_BIG_ENDIAN 1 +#else static const uint16_t mbedtls_byte_order_detector = { 0x100 }; #define MBEDTLS_IS_BIG_ENDIAN (*((unsigned char *) (&mbedtls_byte_order_detector)) == 0x01) +#endif + #else -#define MBEDTLS_IS_BIG_ENDIAN ((__BYTE_ORDER__) == (__ORDER_BIG_ENDIAN__)) + +#if (__BYTE_ORDER__) == (__ORDER_BIG_ENDIAN__) +#define MBEDTLS_IS_BIG_ENDIAN 1 +#else +#define MBEDTLS_IS_BIG_ENDIAN 0 +#endif + #endif /* !defined(__BYTE_ORDER__) */ /** From 650674bb41f2147be7eeb1d25913e45aa0dc4b39 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Tue, 5 Dec 2023 12:16:48 +0000 Subject: [PATCH 2/3] Add MBEDTLS_BSWAPxx intrinsics for IAR Signed-off-by: Dave Rodgman --- library/alignment.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/alignment.h b/library/alignment.h index 634d61046..9e1e044ec 100644 --- a/library/alignment.h +++ b/library/alignment.h @@ -180,6 +180,16 @@ inline void mbedtls_put_unaligned_uint64(void *p, uint64_t x) #define MBEDTLS_BSWAP32 __rev #endif +/* Detect IAR built-in byteswap routine */ +#if defined(__IAR_SYSTEMS_ICC__) +#if defined(__ARM_ACLE) +#include +#define MBEDTLS_BSWAP16(x) ((uint16_t) __rev16((uint32_t) (x))) +#define MBEDTLS_BSWAP32 __rev +#define MBEDTLS_BSWAP64 __revll +#endif +#endif + /* * Where compiler built-ins are not present, fall back to C code that the * compiler may be able to detect and transform into the relevant bswap or From 69928dbe86cefd1640b2fa08f6f8d896bde255d3 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Thu, 14 Dec 2023 12:09:18 +0000 Subject: [PATCH 3/3] Fix compile warning from IAR Signed-off-by: Dave Rodgman --- library/ccm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/ccm.c b/library/ccm.c index 6700dc743..6b137d7bf 100644 --- a/library/ccm.c +++ b/library/ccm.c @@ -91,7 +91,7 @@ int mbedtls_ccm_setkey(mbedtls_ccm_context *ctx, } #endif - return 0; + return ret; } /*