diff --git a/examples/platforms/efr32/src/entropy.c b/examples/platforms/efr32/src/entropy.c index 64b19aadc..3a755e156 100644 --- a/examples/platforms/efr32/src/entropy.c +++ b/examples/platforms/efr32/src/entropy.c @@ -33,29 +33,25 @@ */ #include - #include "mbedtls/entropy_poll.h" #include "utils/code_utils.h" -static uint32_t randomUint32Get(void) -{ - uint32_t random = 0; - size_t ouputLen = 0; - - mbedtls_hardware_poll(NULL, (unsigned char *)&random, sizeof(random), &ouputLen); - - return random; -} - otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; + size_t outputLen = 0; otEXPECT_ACTION(aOutput, error = OT_ERROR_INVALID_ARGS); - for (uint16_t length = 0; length < aOutputLength; length++) + for (size_t partialLen = 0; outputLen < aOutputLength; outputLen += partialLen) { - aOutput[length] = (uint8_t)randomUint32Get(); + const uint16_t remaining = aOutputLength - outputLen; + partialLen = 0; + + // Non-zero return values for mbedtls_hardware_poll() signify an error has occurred + otEXPECT_ACTION(0 == mbedtls_hardware_poll(NULL, &aOutput[outputLen], remaining, &partialLen), + error = OT_ERROR_FAILED); + otEXPECT_ACTION(partialLen > 0, error = OT_ERROR_FAILED); } exit: