Skip to content

Commit 69e6f14

Browse files
committed
[crypto] mbedtls: refactor mbedtls-config.h for better readability
Group mbedTLS configuration macros into logical sections and improve formatting. This commit helps prepare for PSA API backend introduction. Signed-off-by: Łukasz Duda <lukasz.duda@nordicsemi.no>
1 parent c966588 commit 69e6f14

File tree

1 file changed

+92
-12
lines changed

1 file changed

+92
-12
lines changed

third_party/mbedtls/mbedtls-config.h

Lines changed: 92 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
#include <openthread/platform/logging.h>
4141
#include <openthread/platform/memory.h>
4242

43-
#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf
43+
// ==============================================================================
44+
// Cryptographic configuration
45+
// ==============================================================================
4446

4547
#define MBEDTLS_AES_C
4648
#if (MBEDTLS_VERSION_NUMBER >= 0x03050000)
@@ -66,19 +68,34 @@
6668
#define MBEDTLS_ENTROPY_C
6769
#define MBEDTLS_HAVE_ASM
6870
#define MBEDTLS_HMAC_DRBG_C
69-
#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
7071
#define MBEDTLS_MD_C
71-
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
72-
#define MBEDTLS_NO_PLATFORM_ENTROPY
73-
#define MBEDTLS_OID_C
74-
#define MBEDTLS_PK_C
75-
#define MBEDTLS_PK_PARSE_C
76-
#define MBEDTLS_PLATFORM_C
77-
#define MBEDTLS_PLATFORM_MEMORY
78-
#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
7972
#define MBEDTLS_SHA224_C
8073
#define MBEDTLS_SHA256_C
8174
#define MBEDTLS_SHA256_SMALLER
75+
76+
#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE || OPENTHREAD_CONFIG_TLS_ENABLE
77+
#define MBEDTLS_BASE64_C
78+
#define MBEDTLS_ECDH_C
79+
#define MBEDTLS_ECDSA_C
80+
#endif
81+
82+
#if OPENTHREAD_CONFIG_BLE_TCAT_ENABLE
83+
#define MBEDTLS_GCM_C
84+
#endif
85+
86+
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
87+
#define MBEDTLS_BASE64_C
88+
#define MBEDTLS_ECDH_C
89+
#define MBEDTLS_ECDSA_C
90+
#if OPENTHREAD_CONFIG_DETERMINISTIC_ECDSA_ENABLE
91+
#define MBEDTLS_ECDSA_DETERMINISTIC
92+
#endif
93+
#endif
94+
95+
// ==============================================================================
96+
// SSL configuration
97+
// ==============================================================================
98+
8299
#define MBEDTLS_SSL_CLI_C
83100
#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
84101
#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
@@ -93,6 +110,12 @@
93110
#define MBEDTLS_SSL_SRV_C
94111
#endif
95112

113+
#if OPENTHREAD_CONFIG_BLE_TCAT_ENABLE
114+
#define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
115+
#endif
116+
117+
#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
118+
96119
#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
97120
#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
98121
#endif
@@ -134,8 +157,8 @@
134157
#define MBEDTLS_ENTROPY_MAX_SOURCES 1 /**< Maximum number of sources supported */
135158

136159
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
137-
#define MBEDTLS_PLATFORM_STD_CALLOC otPlatCAlloc /**< Default allocator to use, can be undefined */
138-
#define MBEDTLS_PLATFORM_STD_FREE otPlatFree /**< Default free to use, can be undefined */
160+
#define MBEDTLS_PLATFORM_STD_CALLOC otPlatCryptoCAlloc /**< Default allocator to use, can be undefined */
161+
#define MBEDTLS_PLATFORM_STD_FREE otPlatCryptoFree /**< Default free to use, can be undefined */
139162
#else
140163
#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
141164
#endif
@@ -152,6 +175,63 @@
152175
#define MBEDTLS_SSL_OUT_CONTENT_LEN MBEDTLS_SSL_MAX_CONTENT_LEN
153176
#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
154177

178+
// ==============================================================================
179+
// x509 & PK configuration
180+
// ==============================================================================
181+
182+
#define MBEDTLS_OID_C
183+
#define MBEDTLS_PK_C
184+
#define MBEDTLS_PK_PARSE_C
185+
186+
#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE || OPENTHREAD_CONFIG_TLS_ENABLE
187+
#define MBEDTLS_BASE64_C
188+
#define MBEDTLS_PEM_PARSE_C
189+
#define MBEDTLS_X509_USE_C
190+
#define MBEDTLS_X509_CRT_PARSE_C
191+
#endif
192+
193+
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
194+
#define MBEDTLS_PEM_PARSE_C
195+
#define MBEDTLS_PK_WRITE_C
196+
#endif
197+
198+
// ==============================================================================
199+
// MPI configuration
200+
// ==============================================================================
201+
202+
#define MBEDTLS_MPI_WINDOW_SIZE 1 /**< Maximum windows size used. */
203+
#define MBEDTLS_MPI_MAX_SIZE 32 /**< Maximum number of bytes for usable MPIs. */
204+
205+
// ==============================================================================
206+
// ECP configuration
207+
// ==============================================================================
208+
209+
#if (MBEDTLS_VERSION_NUMBER < 0x03000000)
210+
#define MBEDTLS_ECP_MAX_BITS 256 /**< Maximum bit size of groups */
211+
#endif
212+
#define MBEDTLS_ECP_WINDOW_SIZE 2 /**< Maximum window size used */
213+
#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 /**< Enable fixed-point speed-up */
214+
215+
// ==============================================================================
216+
// Platform configuration
217+
// ==============================================================================
218+
219+
#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf
220+
221+
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
222+
#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use, can be undefined */
223+
#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */
224+
#else
225+
#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
226+
#endif
227+
228+
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
229+
#define MBEDTLS_NO_PLATFORM_ENTROPY
230+
#define MBEDTLS_PLATFORM_C
231+
#define MBEDTLS_PLATFORM_MEMORY
232+
#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
233+
#define MBEDTLS_ENTROPY_MAX_SOURCES 1
234+
155235
// Spans multiple lines to avoid being processed by unifdef
156236
#if defined(\
157237
MBEDTLS_USER_CONFIG_FILE)

0 commit comments

Comments
 (0)