Michel Jaouen | cfeafe0 | 2023-04-04 15:47:25 +0200 | [diff] [blame] | 1 | From 8be39b4353bdeee2f80e42c23a73a276cbd9a8ad Mon Sep 17 00:00:00 2001 |
| 2 | From: TTornblom <thomas.tornblom@iar.com> |
| 3 | Date: Thu, 16 Apr 2020 13:53:38 +0200 |
| 4 | Subject: [PATCH 1/8] BUILD: Update For IAR support |
| 5 | |
| 6 | Applied the same change as in mbed-crypto for using this as a sub |
| 7 | project with the IAR toolchain. Use __asm generic ,and avoid empty |
Michel Jaouen | 3968eb0 | 2023-04-17 16:00:02 +0200 | [diff] [blame] | 8 | enum. Avoid declaration of array with null size. |
Michel Jaouen | cfeafe0 | 2023-04-04 15:47:25 +0200 | [diff] [blame] | 9 | |
| 10 | Signed-off-by: TTornblom <thomas.tornblom@iar.com> |
| 11 | Signed-off-by: Michel Jaouen <michel.jaouen@st.com> |
| 12 | --- |
| 13 | CMakeLists.txt | 4 +++- |
| 14 | include/mbedtls/ssl.h | 1 + |
| 15 | library/constant_time.c | 2 +- |
Michel Jaouen | 3968eb0 | 2023-04-17 16:00:02 +0200 | [diff] [blame] | 16 | library/psa_crypto.c | 7 ++++++- |
| 17 | 4 files changed, 11 insertions(+), 3 deletions(-) |
Michel Jaouen | cfeafe0 | 2023-04-04 15:47:25 +0200 | [diff] [blame] | 18 | |
| 19 | diff --git a/CMakeLists.txt b/CMakeLists.txt |
| 20 | index 8d3f08a98..096bb6e14 100644 |
| 21 | --- a/CMakeLists.txt |
| 22 | +++ b/CMakeLists.txt |
| 23 | @@ -222,7 +222,9 @@ if(CMAKE_COMPILER_IS_CLANG) |
| 24 | endif(CMAKE_COMPILER_IS_CLANG) |
| 25 | |
| 26 | if(CMAKE_COMPILER_IS_IAR) |
| 27 | - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --warn_about_c_style_casts -Ohz") |
| 28 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --warn_about_c_style_casts") |
| 29 | + set(CMAKE_C_FLAGS_RELEASE "-Ohz") |
| 30 | + set(CMAKE_C_FLAGS_DEBUG "--debug -On") |
| 31 | endif(CMAKE_COMPILER_IS_IAR) |
| 32 | |
| 33 | if(CMAKE_COMPILER_IS_MSVC) |
| 34 | diff --git a/include/mbedtls/ssl.h b/include/mbedtls/ssl.h |
| 35 | index 68e8d040f..fbd150638 100644 |
| 36 | --- a/include/mbedtls/ssl.h |
| 37 | +++ b/include/mbedtls/ssl.h |
| 38 | @@ -620,6 +620,7 @@ |
| 39 | |
| 40 | /* Dummy type used only for its size */ |
| 41 | union mbedtls_ssl_premaster_secret { |
| 42 | + unsigned MBEDTLS_PRIVATE(dummy); /* Make the union non-empty even with no supported algorithms. */ |
| 43 | #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) |
| 44 | unsigned char _pms_rsa[48]; /* RFC 5246 8.1.1 */ |
| 45 | #endif |
| 46 | diff --git a/library/constant_time.c b/library/constant_time.c |
| 47 | index 552a918f4..471d91618 100644 |
| 48 | --- a/library/constant_time.c |
| 49 | +++ b/library/constant_time.c |
| 50 | @@ -77,7 +77,7 @@ static inline uint32_t mbedtls_get_unaligned_volatile_uint32(volatile const unsi |
| 51 | */ |
| 52 | uint32_t r; |
| 53 | #if defined(__arm__) || defined(__thumb__) || defined(__thumb2__) |
| 54 | - asm volatile ("ldr %0, [%1]" : "=r" (r) : "r" (p) :); |
| 55 | + __asm volatile ("ldr %0, [%1]" : "=r" (r) : "r" (p) :); |
| 56 | #elif defined(__aarch64__) |
| 57 | asm volatile ("ldr %w0, [%1]" : "=r" (r) : "r" (p) :); |
| 58 | #endif |
Michel Jaouen | 3968eb0 | 2023-04-17 16:00:02 +0200 | [diff] [blame] | 59 | diff --git a/library/psa_crypto.c b/library/psa_crypto.c |
| 60 | index bc19ed07c..8b9f28f4d 100644 |
| 61 | --- a/library/psa_crypto.c |
| 62 | +++ b/library/psa_crypto.c |
| 63 | @@ -6611,8 +6611,13 @@ static psa_status_t psa_key_agreement_internal(psa_key_derivation_operation_t *o |
| 64 | size_t peer_key_length) |
| 65 | { |
| 66 | psa_status_t status; |
| 67 | +#if PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE != 0 |
| 68 | uint8_t shared_secret[PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE]; |
| 69 | + size_t shared_secret_length = sizeof(shared_secret); |
| 70 | +#else |
| 71 | + uint8_t *shared_secret = NULL; |
| 72 | size_t shared_secret_length = 0; |
| 73 | +#endif |
| 74 | psa_algorithm_t ka_alg = PSA_ALG_KEY_AGREEMENT_GET_BASE(operation->alg); |
| 75 | |
| 76 | /* Step 1: run the secret agreement algorithm to generate the shared |
| 77 | @@ -6621,7 +6626,7 @@ static psa_status_t psa_key_agreement_internal(psa_key_derivation_operation_t *o |
| 78 | private_key, |
| 79 | peer_key, peer_key_length, |
| 80 | shared_secret, |
| 81 | - sizeof(shared_secret), |
| 82 | + shared_secret_length, |
| 83 | &shared_secret_length); |
| 84 | if (status != PSA_SUCCESS) { |
| 85 | goto exit; |
Michel Jaouen | cfeafe0 | 2023-04-04 15:47:25 +0200 | [diff] [blame] | 86 | -- |
| 87 | 2.32.0 |
| 88 | |