1 /* 2 * Copyright (c) 2019 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/kernel.h> 8 #include <zephyr/random/random.h> 9 #include <zephyr/logging/log.h> 10 11 #include <openthread/platform/entropy.h> 12 13 LOG_MODULE_REGISTER(net_otPlat_entropy, CONFIG_OPENTHREAD_L2_LOG_LEVEL); 14 15 #if !defined(CONFIG_CSPRNG_ENABLED) 16 #error OpenThread requires an entropy source for a TRNG 17 #endif 18 otPlatEntropyGet(uint8_t * aOutput,uint16_t aOutputLength)19otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) 20 { 21 int err; 22 23 if ((aOutput == NULL) || (aOutputLength == 0)) { 24 return OT_ERROR_INVALID_ARGS; 25 } 26 27 err = sys_csrand_get(aOutput, aOutputLength); 28 if (err != 0) { 29 LOG_ERR("Failed to obtain entropy, err %d", err); 30 return OT_ERROR_FAILED; 31 } 32 33 return OT_ERROR_NONE; 34 } 35