zephyr/modules/openthread/platform/entropy.c
Przemyslaw Bida 96893e84ce net: openthread: Refactor openthread entropy otPlatEntropyGet.
This commit replaces direct entropy device driver class with
`sys_csrand_get`, which is recommended way of getting crypto
secure random buffer.

Signed-off-by: Przemyslaw Bida <przemyslaw.bida@nordicsemi.no>
2023-07-17 13:22:16 +00:00

35 lines
748 B
C

/*
* Copyright (c) 2019 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/random/rand32.h>
#include <zephyr/logging/log.h>
#include <openthread/platform/entropy.h>
LOG_MODULE_REGISTER(net_otPlat_entropy, CONFIG_OPENTHREAD_L2_LOG_LEVEL);
#if !defined(CONFIG_ENTROPY_HAS_DRIVER)
#error OpenThread requires an entropy source for a TRNG
#endif
otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
{
int err;
if ((aOutput == NULL) || (aOutputLength == 0)) {
return OT_ERROR_INVALID_ARGS;
}
err = sys_csrand_get(aOutput, aOutputLength);
if (err != 0) {
LOG_ERR("Failed to obtain entropy, err %d", err);
return OT_ERROR_FAILED;
}
return OT_ERROR_NONE;
}