Skip to content

Commit 350a223

Browse files
de-nordickartben
authored andcommitted
modules: mbedtls: Expose MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
The commit adds Kconfig options that allows users to select - MBEDTLS_PLATFORM_NO_STD_FUNCTIONS - MBEDTLS_PLATFORM_SNPRINTF_ALT allowing Mbed TLS to use alternative definitions of STD functions. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
1 parent d7e363e commit 350a223

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

modules/mbedtls/Kconfig.mbedtls

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,28 @@ config MBEDTLS_GENPRIME_ENABLED
378378
config MBEDTLS_ASN1_PARSE_C
379379
bool "Support for ASN1 parser functions"
380380

381+
config MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
382+
bool "Remove usage of standard libc functions"
383+
help
384+
This prevents Mbed TLS from linking against the following standard functions
385+
from libc: `snprintf`, `vsnprintf`, `printf`, `fprintf`, `calloc`, `free`, `setbuf`, `exit`
386+
and `time`. By default Mbed TLS will use stub functions for all these functions.
387+
These stubs are just meant to return successfully, but they don't implement
388+
the required functionality.
389+
Users can individually override each of these stubs by calling
390+
`mbedtls_platform_set_xxx()` to set the their implementation of `xxx()` function
391+
at runtime.
392+
393+
if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
394+
395+
config MBEDTLS_PLATFORM_SNPRINTF_ALT
396+
bool "Allow setting custom snprintf at run-time"
397+
help
398+
Allow setting a custom `snprintf()` function with `mbedtls_platform_set_snprintf()`.
399+
Include `mbedtls/platform.h` for the prototype of this function.
400+
401+
endif # MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
402+
381403
config MBEDTLS_PEM_CERTIFICATE_FORMAT
382404
bool "Support for PEM certificate format"
383405
help

modules/mbedtls/configs/config-mbedtls.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
#define MBEDTLS_PLATFORM_ZEROIZE_ALT
2424
#endif
2525

26+
#if defined(CONFIG_MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
27+
#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
28+
#endif /* defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) */
29+
30+
#if defined(CONFIG_MBEDTLS_PLATFORM_SNPRINTF_ALT)
31+
#define MBEDTLS_PLATFORM_SNPRINTF_ALT
32+
#endif /* defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) */
33+
2634
#if defined(CONFIG_MBEDTLS_ENTROPY_POLL_ZEPHYR)
2735
#define MBEDTLS_ENTROPY_HARDWARE_ALT
2836
#else

0 commit comments

Comments
 (0)