From 43acd6490a041708391fee33210efbf9343e1ec6 Mon Sep 17 00:00:00 2001 From: Artem Godlevskyi Date: Thu, 1 Feb 2024 18:39:54 +0200 Subject: [PATCH] Added Zephyr integration --- impl/random.h | 2 ++ impl/random/zephyr.h | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 impl/random/zephyr.h diff --git a/impl/random.h b/impl/random.h index 9b82bcf..152b995 100644 --- a/impl/random.h +++ b/impl/random.h @@ -11,6 +11,8 @@ static TLS struct { # include "random/esp32.h" #elif defined(PARTICLE) && defined(PLATFORM_ID) && PLATFORM_ID > 2 && !defined(__unix__) # include "random/particle.h" +#elif defined(__ZEPHYR__) +# include "random/zephyr.h" #elif (defined(NRF52832_XXAA) || defined(NRF52832_XXAB)) && !defined(__unix__) # include "random/nrf52832.h" #elif defined(_WIN32) diff --git a/impl/random/zephyr.h b/impl/random/zephyr.h new file mode 100644 index 0000000..6a2baf4 --- /dev/null +++ b/impl/random/zephyr.h @@ -0,0 +1,13 @@ +#include + +static int +hydro_random_init(void) +{ + if (sys_csrand_get(&hydro_random_context.state, sizeof hydro_random_context.state) != 0) { + return -1; + } + + hydro_random_context.counter = ~LOAD64_LE(hydro_random_context.state); + + return 0; +}