From ac41c191b90c94c0fd2a5b1f1eca7675ee467773 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 4 Dec 2018 10:57:13 +0100 Subject: [PATCH 1/3] Add psa_crypto_invasive.h --- visualc/VS2010/mbedTLS.vcxproj | 1 + 1 file changed, 1 insertion(+) diff --git a/visualc/VS2010/mbedTLS.vcxproj b/visualc/VS2010/mbedTLS.vcxproj index 6535d483a..d305c4515 100644 --- a/visualc/VS2010/mbedTLS.vcxproj +++ b/visualc/VS2010/mbedTLS.vcxproj @@ -231,6 +231,7 @@ + From 79e213cfc8547b64cb645be0096e9ca07930525c Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 4 Dec 2018 12:25:40 +0100 Subject: [PATCH 2/3] Don't include mbedtls/platform.h unconditionally Programs must not include mbedtls/platform.h if MBEDTLS_PLATFORM_C is not defined. Test suites don't need to include mbedtls/platform.h because helpers.function takes care of it. This commit also removes a stray `;` which is technically not standard C. --- tests/suites/test_suite_psa_crypto_init.function | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto_init.function b/tests/suites/test_suite_psa_crypto_init.function index 359650429..132fe82f8 100644 --- a/tests/suites/test_suite_psa_crypto_init.function +++ b/tests/suites/test_suite_psa_crypto_init.function @@ -11,7 +11,6 @@ #include "mbedtls/entropy.h" #include "mbedtls/entropy_poll.h" -#include "mbedtls/platform.h" #define MIN( x, y ) ( ( x ) < ( y ) ? ( x ) : ( y ) ) #define MAX( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) ) @@ -41,7 +40,7 @@ static int fake_entropy_source( void *state_arg, output[i] = i; ++state->step; return( 0 ); -}; +} #define ENTROPY_SOURCE_PLATFORM 0x00000001 #define ENTROPY_SOURCE_TIMING 0x00000002 From 5a3c50e89049b4a5efbeceea49318182fac28456 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 4 Dec 2018 12:27:09 +0100 Subject: [PATCH 3/3] Don't use an enum in a bit-field This isn't standard C. GCC and Clang accept it but not every compiler (e.g. Armcc 5). --- library/psa_crypto.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 233a19ede..7415a9a4f 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -147,12 +147,10 @@ static int key_type_is_raw_bytes( psa_key_type_t type ) return( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) ); } -enum rng_state -{ - RNG_NOT_INITIALIZED = 0, - RNG_INITIALIZED, - RNG_SEEDED, -}; +/* Values for psa_global_data_t::rng_state */ +#define RNG_NOT_INITIALIZED 0 +#define RNG_INITIALIZED 1 +#define RNG_SEEDED 2 typedef struct { @@ -162,7 +160,7 @@ typedef struct mbedtls_ctr_drbg_context ctr_drbg; key_slot_t key_slots[PSA_KEY_SLOT_COUNT]; unsigned initialized : 1; - enum rng_state rng_state : 2; + unsigned rng_state : 2; unsigned key_slots_initialized : 1; } psa_global_data_t;