From 1e69740d18f95a76ff1627e50ee730533129a803 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 26 Jul 2022 19:46:14 +0200 Subject: [PATCH] random: use void * in random_bytes() --- sys/include/random.h | 2 +- sys/random/random.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sys/include/random.h b/sys/include/random.h index 9e920b0b1f..49cc59aeaf 100644 --- a/sys/include/random.h +++ b/sys/include/random.h @@ -82,7 +82,7 @@ uint32_t random_uint32(void); /** * @brief writes random bytes in the [0,0xff]-interval to memory */ -void random_bytes(uint8_t *buf, size_t size); +void random_bytes(void *buf, size_t size); /** * @brief generates a random number r with a <= r < b. diff --git a/sys/random/random.c b/sys/random/random.c index 7c93312bb1..2187be0839 100644 --- a/sys/random/random.c +++ b/sys/random/random.c @@ -60,9 +60,10 @@ void auto_init_random(void) random_init(seed); } -void random_bytes(uint8_t *target, size_t n) +void random_bytes(void *target, size_t n) { uint32_t random; + uint8_t *dst = target; uint8_t *random_pos = (uint8_t*)&random; unsigned _n = 0; @@ -71,7 +72,7 @@ void random_bytes(uint8_t *target, size_t n) random = random_uint32(); random_pos = (uint8_t *) &random; } - *target++ = *random_pos++; + *dst++ = *random_pos++; } }