From db29ab528a858a31f2fcdc4c51cb18a38dba7886 Mon Sep 17 00:00:00 2001 From: Jaeden Amero Date: Tue, 12 Feb 2019 16:40:27 +0000 Subject: [PATCH] psa: Fix builds without MBEDTLS_PLATFORM_C When `MBEDTLS_PLATFORM_C` is not enabled, our PSA Crypto implementation depends on the standard C library for functions like snprintf() and exit(). However, our implementation was not including the proper header files nor redefining all `mbedtls_*` symbols properly to ensure successful builds without MBEDTLS_PLATFORM_C. Add the necessary header files and macro definitions to our PSA Crypto implementation. --- library/psa_crypto_storage.c | 1 + library/psa_crypto_storage_file.c | 1 + programs/psa/crypto_examples.c | 3 +++ programs/psa/key_ladder_demo.c | 1 + 4 files changed, 6 insertions(+) diff --git a/library/psa_crypto_storage.c b/library/psa_crypto_storage.c index 687269b07..b4e4076e1 100644 --- a/library/psa_crypto_storage.c +++ b/library/psa_crypto_storage.c @@ -38,6 +38,7 @@ #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" #else +#include #define mbedtls_calloc calloc #define mbedtls_free free #endif diff --git a/library/psa_crypto_storage_file.c b/library/psa_crypto_storage_file.c index 87420be98..d7c33624e 100644 --- a/library/psa_crypto_storage_file.c +++ b/library/psa_crypto_storage_file.c @@ -36,6 +36,7 @@ #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" #else +#include #define mbedtls_snprintf snprintf #endif diff --git a/programs/psa/crypto_examples.c b/programs/psa/crypto_examples.c index d7a667b7f..9947a70bc 100644 --- a/programs/psa/crypto_examples.c +++ b/programs/psa/crypto_examples.c @@ -5,7 +5,10 @@ #include "mbedtls/platform.h" #else #include +#include +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #define mbedtls_printf printf +#define mbedtls_exit exit #endif #define ASSERT( predicate ) \ diff --git a/programs/psa/key_ladder_demo.c b/programs/psa/key_ladder_demo.c index 0943bf53c..c9d76763e 100644 --- a/programs/psa/key_ladder_demo.c +++ b/programs/psa/key_ladder_demo.c @@ -66,6 +66,7 @@ #define mbedtls_calloc calloc #define mbedtls_free free #define mbedtls_printf printf +#define mbedtls_exit exit #endif #include #include