mirror of
https://github.com/espressif/openthread.git
synced 2026-08-03 17:37:46 +00:00
[efr32] call mbedtls_hardware_poll directly in otPlatEntropyGet() (#5744)
This commit is contained in:
@@ -33,29 +33,25 @@
|
||||
*/
|
||||
|
||||
#include <openthread/platform/entropy.h>
|
||||
|
||||
#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:
|
||||
|
||||
Reference in New Issue
Block a user