From 2f1743dad08e1486f68adbac6a42286596a115d3 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Wed, 8 Jan 2025 17:05:26 +0100 Subject: [PATCH] use memcpy instead of manual copying --- src/native/entropy_cpu_stubs.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/native/entropy_cpu_stubs.c b/src/native/entropy_cpu_stubs.c index 37fe794d..ea9989cb 100644 --- a/src/native/entropy_cpu_stubs.c +++ b/src/native/entropy_cpu_stubs.c @@ -15,27 +15,13 @@ #define random_t unsigned long long #define _rdseed_step _rdseed64_step #define _rdrand_step _rdrand64_step -#define fill_bytes(buf, off, data) { \ - (_bp_uint8_off(buf, off))[0] = (uint8_t)((data) >> 56); \ - (_bp_uint8_off(buf, off))[1] = (uint8_t)((data) >> 48); \ - (_bp_uint8_off(buf, off))[2] = (uint8_t)((data) >> 40); \ - (_bp_uint8_off(buf, off))[3] = (uint8_t)((data) >> 32); \ - (_bp_uint8_off(buf, off))[4] = (uint8_t)((data) >> 24); \ - (_bp_uint8_off(buf, off))[5] = (uint8_t)((data) >> 16); \ - (_bp_uint8_off(buf, off))[6] = (uint8_t)((data) >> 8); \ - (_bp_uint8_off(buf, off))[7] = (uint8_t)((data)); \ - } +#define fill_bytes(buf, off, data) memcpy(_bp_uint8_off(buf, off), &data, 8) #elif defined (__i386__) #define random_t unsigned int #define _rdseed_step _rdseed32_step #define _rdrand_step _rdrand32_step -#define fill_bytes(buf, off, data) { \ - (_bp_uint8_off(buf, off))[0] = (uint8_t)((data) >> 24); \ - (_bp_uint8_off(buf, off))[1] = (uint8_t)((data) >> 16); \ - (_bp_uint8_off(buf, off))[2] = (uint8_t)((data) >> 8); \ - (_bp_uint8_off(buf, off))[3] = (uint8_t)((data)); \ - } +#define fill_bytes(buf, off, data) memcpy(_bp_uint8_off(buf, off), &data, 4) #endif #endif /* __i386__ || __x86_64__ */