Skip to content

Commit b0b4013

Browse files
author
Cruz Monrreal
authored
Merge pull request #9302 from yossi2le/yossi_add_trng_checkup_devicekey
Add TRNG checkup in devicekey
2 parents a6509cf + 2adf5db commit b0b4013

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

features/device_key/source/DeviceKey.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "entropy.h"
3131
#include "platform_mbed.h"
3232
#include "mbed_trace.h"
33+
#include "ssl_internal.h"
3334

3435
#define TRACE_GROUP "DEVKEY"
3536

@@ -260,12 +261,14 @@ int DeviceKey::generate_key_by_random(uint32_t *output, size_t size)
260261
}
261262

262263
#if DEVICE_TRNG
264+
uint32_t test_buff[DEVICE_KEY_32BYTE / sizeof(int)];
263265
mbedtls_entropy_context *entropy = new mbedtls_entropy_context;
264266
mbedtls_entropy_init(entropy);
265267
memset(output, 0, size);
268+
memset(test_buff, 0, size);
266269

267270
ret = mbedtls_entropy_func(entropy, (unsigned char *)output, size);
268-
if (ret != MBED_SUCCESS) {
271+
if (ret != MBED_SUCCESS || mbedtls_ssl_safer_memcmp(test_buff, (unsigned char *)output, size) == 0) {
269272
ret = DEVICEKEY_GENERATE_RANDOM_ERROR;
270273
} else {
271274
ret = DEVICEKEY_SUCCESS;

0 commit comments

Comments
 (0)