diff --git a/features/mbedtls/platform/inc/platform_mbed.h b/features/mbedtls/platform/inc/platform_mbed.h index c424a05..66d5292 100644 --- a/features/mbedtls/platform/inc/platform_mbed.h +++ b/features/mbedtls/platform/inc/platform_mbed.h @@ -54,6 +54,8 @@ #define MBEDTLS_PSA_CRYPTO_STORAGE_C #define MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C #undef MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C + +#define MBEDTLS_ENTROPY_HARDWARE_ALT #endif /* diff --git a/features/mbedtls/platform/src/mbed_trng.cpp b/features/mbedtls/platform/src/mbed_trng.cpp index 79fed2a..eb7a516 100644 --- a/features/mbedtls/platform/src/mbed_trng.cpp +++ b/features/mbedtls/platform/src/mbed_trng.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#if DEVICE_TRNG +#if defined(DEVICE_TRNG) || defined(FEATURE_PSA) #include "hal/trng_api.h" #include "platform/SingletonPtr.h" @@ -24,6 +24,7 @@ extern "C" int mbedtls_hardware_poll( void *data, unsigned char *output, size_t len, size_t *olen ) { +#if defined(DEVICE_TRNG) trng_t trng_obj; mbedtls_mutex->lock(); trng_init(&trng_obj); @@ -31,6 +32,12 @@ trng_free(&trng_obj); mbedtls_mutex->unlock(); return ret; +#else /* defined(FEATURE_PSA) */ + mbedtls_mutex->lock(); + int ret = trng_get_bytes(NULL, output, len, olen); + mbedtls_mutex->unlock(); + return ret; +#endif } #endif diff --git a/hal/trng_api.h b/hal/trng_api.h index 7677094..34780d6 100644 --- a/hal/trng_api.h +++ b/hal/trng_api.h @@ -23,7 +23,7 @@ #include #include "device.h" -#if DEVICE_TRNG +#if defined(DEVICE_TRNG) || defined(FEATURE_PSA) /** TRNG HAL structure. trng_s is declared in the target's HAL */