Skip to content

Commit 1bb351f

Browse files
committed
DeviceKey: Fix random key doesn't generate on MBEDTLS_ENTROPY_HARDWARE_ALT
Originally, when DEVICE_TRNG is defined, MBEDTLS_ENTROPY_HARDWARE_ALT will also be defined accordingly to provide entropy source. This is fine for targets supporting TRNG. However, for targets without TRNG, it is also possible to provide non-TRNG entropy source solution via the define MBEDTLS_ENTROPY_HARDWARE_ALT. Related discussion can be found at: #11680
1 parent 9db54bc commit 1bb351f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

features/device_key/TESTS/device_key/functionality/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include "DeviceKey.h"
18+
#include "mbedtls/config.h"
1819
#include "utest/utest.h"
1920
#include "mbed_error.h"
2021
#include "unity/unity.h"
@@ -51,7 +52,7 @@ void generate_derived_key_consistency_32_byte_key_long_consistency_test(char *ke
5152
*/
5253
int inject_dummy_rot_key()
5354
{
54-
#if !DEVICE_TRNG
55+
#if !DEVICE_TRNG && !defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
5556
uint32_t key[DEVICE_KEY_16BYTE / sizeof(uint32_t)];
5657

5758
memcpy(key, "1234567812345678", DEVICE_KEY_16BYTE);

features/device_key/source/DeviceKey.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ int DeviceKey::generate_key_by_random(uint32_t *output, size_t size)
271271
return DEVICEKEY_INVALID_PARAM;
272272
}
273273

274-
#if defined(DEVICE_TRNG) || defined(MBEDTLS_ENTROPY_NV_SEED)
274+
#if defined(DEVICE_TRNG) || defined(MBEDTLS_ENTROPY_NV_SEED) || defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
275275
uint32_t test_buff[DEVICE_KEY_32BYTE / sizeof(int)];
276276
mbedtls_entropy_context *entropy = new mbedtls_entropy_context;
277277
mbedtls_entropy_init(entropy);

0 commit comments

Comments
 (0)