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:

https://github.com/ARMmbed/mbed-os/issues/11680
pull/11725/head
Chun-Chieh Li 2019-10-22 17:06:12 +08:00
parent 9db54bc1ee
commit 1bb351f410
2 changed files with 3 additions and 2 deletions

View File

@ -15,6 +15,7 @@
*/
#include "DeviceKey.h"
#include "mbedtls/config.h"
#include "utest/utest.h"
#include "mbed_error.h"
#include "unity/unity.h"
@ -51,7 +52,7 @@ void generate_derived_key_consistency_32_byte_key_long_consistency_test(char *ke
*/
int inject_dummy_rot_key()
{
#if !DEVICE_TRNG
#if !DEVICE_TRNG && !defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
uint32_t key[DEVICE_KEY_16BYTE / sizeof(uint32_t)];
memcpy(key, "1234567812345678", DEVICE_KEY_16BYTE);

View File

@ -271,7 +271,7 @@ int DeviceKey::generate_key_by_random(uint32_t *output, size_t size)
return DEVICEKEY_INVALID_PARAM;
}
#if defined(DEVICE_TRNG) || defined(MBEDTLS_ENTROPY_NV_SEED)
#if defined(DEVICE_TRNG) || defined(MBEDTLS_ENTROPY_NV_SEED) || defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
uint32_t test_buff[DEVICE_KEY_32BYTE / sizeof(int)];
mbedtls_entropy_context *entropy = new mbedtls_entropy_context;
mbedtls_entropy_init(entropy);