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>
This commit is contained in:
Przemyslaw Bida 2023-07-17 08:47:42 +02:00 committed by Fabio Baltieri
commit 96893e84ce

View file

@ -5,22 +5,17 @@
*/
#include <zephyr/kernel.h>
#include <string.h>
#include <zephyr/drivers/entropy.h>
#include <zephyr/random/rand32.h>
#include <zephyr/logging/log.h>
#include <openthread/platform/entropy.h>
#include "platform-zephyr.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
static const struct device *const dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy));
otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
{
int err;
@ -29,12 +24,7 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength)
return OT_ERROR_INVALID_ARGS;
}
if (!device_is_ready(dev)) {
LOG_ERR("Entropy device not ready");
return OT_ERROR_FAILED;
}
err = entropy_get_entropy(dev, aOutput, aOutputLength);
err = sys_csrand_get(aOutput, aOutputLength);
if (err != 0) {
LOG_ERR("Failed to obtain entropy, err %d", err);
return OT_ERROR_FAILED;