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; +}