Skip to content

Commit d3d0e51

Browse files
author
Charley Chu
committed
Use PSA TRNG if PSA is enabled and no TRNG device defined
Signed-off-by: Charley Chu <[email protected]>
1 parent 6cb4df5 commit d3d0e51

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

features/mbedtls/platform/inc/platform_mbed.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
#define MBEDTLS_PSA_CRYPTO_STORAGE_C
5555
#define MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C
5656
#undef MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C
57+
58+
#define MBEDTLS_ENTROPY_HARDWARE_ALT
5759
#endif
5860

5961
/*

features/mbedtls/platform/src/mbed_trng.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#if DEVICE_TRNG
17+
#if defined(DEVICE_TRNG) || defined(FEATURE_PSA)
1818

1919
#include "hal/trng_api.h"
2020
#include "platform/SingletonPtr.h"
@@ -24,13 +24,20 @@ SingletonPtr<PlatformMutex> mbedtls_mutex;
2424

2525
extern "C"
2626
int mbedtls_hardware_poll( void *data, unsigned char *output, size_t len, size_t *olen ) {
27+
#if defined(DEVICE_TRNG)
2728
trng_t trng_obj;
2829
mbedtls_mutex->lock();
2930
trng_init(&trng_obj);
3031
int ret = trng_get_bytes(&trng_obj, output, len, olen);
3132
trng_free(&trng_obj);
3233
mbedtls_mutex->unlock();
3334
return ret;
35+
#else /* defined(FEATURE_PSA) */
36+
mbedtls_mutex->lock();
37+
int ret = trng_get_bytes(NULL, output, len, olen);
38+
mbedtls_mutex->unlock();
39+
return ret;
40+
#endif
3441
}
3542

3643
#endif

hal/trng_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <stddef.h>
2424
#include "device.h"
2525

26-
#if DEVICE_TRNG
26+
#if defined(DEVICE_TRNG) || defined(FEATURE_PSA)
2727

2828
/** TRNG HAL structure. trng_s is declared in the target's HAL
2929
*/

0 commit comments

Comments
 (0)