Skip to content

Commit

Permalink
Remove usage of Mbed TLS internal function from DeviceKey.
Browse files Browse the repository at this point in the history
DeviceKey was using mbedtls_ssl_safer_memcmp() to compare result against
buffer of equal length, but zero content. This comparison makes no sense
as the entropy function is already returning proper error, if it fails.
  • Loading branch information
Seppo Takalo authored and adbridge committed Nov 18, 2019
1 parent 90b7cc4 commit 1a90105
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions features/device_key/source/DeviceKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,12 @@ int DeviceKey::generate_key_by_random(uint32_t *output, size_t size)
}

#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);
memset(output, 0, size);
memset(test_buff, 0, size);

ret = mbedtls_entropy_func(entropy, (unsigned char *)output, size);
if (ret != MBED_SUCCESS || mbedtls_ssl_safer_memcmp(test_buff, (unsigned char *)output, size) == 0) {
if (ret != MBED_SUCCESS) {
ret = DEVICEKEY_GENERATE_RANDOM_ERROR;
} else {
ret = DEVICEKEY_SUCCESS;
Expand Down

0 comments on commit 1a90105

Please sign in to comment.