Skip to content

Commit

Permalink
use memcpy instead of manual copying
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed Jan 8, 2025
1 parent f5031a6 commit 2f1743d
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions src/native/entropy_cpu_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
Expand Down

0 comments on commit 2f1743d

Please sign in to comment.