15
15
#define random_t unsigned long long
16
16
#define _rdseed_step _rdseed64_step
17
17
#define _rdrand_step _rdrand64_step
18
- #define fill_bytes (buf , off , data ) { \
19
- (_bp_uint8_off(buf, off))[0] = (uint8_t)((data) >> 56); \
20
- (_bp_uint8_off(buf, off))[1] = (uint8_t)((data) >> 48); \
21
- (_bp_uint8_off(buf, off))[2] = (uint8_t)((data) >> 40); \
22
- (_bp_uint8_off(buf, off))[3] = (uint8_t)((data) >> 32); \
23
- (_bp_uint8_off(buf, off))[4] = (uint8_t)((data) >> 24); \
24
- (_bp_uint8_off(buf, off))[5] = (uint8_t)((data) >> 16); \
25
- (_bp_uint8_off(buf, off))[6] = (uint8_t)((data) >> 8); \
26
- (_bp_uint8_off(buf, off))[7] = (uint8_t)((data)); \
27
- }
18
+ #define fill_bytes (buf , off , data ) memcpy(_bp_uint8_off(buf, off), data, 8)
28
19
29
20
#elif defined (__i386__ )
30
21
#define random_t unsigned int
31
22
#define _rdseed_step _rdseed32_step
32
23
#define _rdrand_step _rdrand32_step
33
- #define fill_bytes (buf , off , data ) { \
34
- (_bp_uint8_off(buf, off))[0] = (uint8_t)((data) >> 24); \
35
- (_bp_uint8_off(buf, off))[1] = (uint8_t)((data) >> 16); \
36
- (_bp_uint8_off(buf, off))[2] = (uint8_t)((data) >> 8); \
37
- (_bp_uint8_off(buf, off))[3] = (uint8_t)((data)); \
38
- }
24
+ #define fill_bytes (buf , off , data ) memcpy(_bp_uint8_off(buf, off), data, 4)
39
25
40
26
#endif
41
27
#endif /* __i386__ || __x86_64__ */
@@ -251,7 +237,7 @@ CAMLprim value mc_cpu_rdseed (value buf, value off) {
251
237
int ok = 0 ;
252
238
int i = RETRIES ;
253
239
do { ok = _rdseed_step (& r ); _mm_pause (); } while ( !(ok | !-- i ) );
254
- fill_bytes (buf , off , r );
240
+ fill_bytes (buf , off , & r );
255
241
return Val_bool (ok );
256
242
#else
257
243
/* ARM: CPU-assisted randomness here. */
@@ -265,7 +251,7 @@ CAMLprim value mc_cpu_rdrand (value buf, value off) {
265
251
int ok = 0 ;
266
252
int i = RETRIES ;
267
253
do { ok = _rdrand_step (& r ); } while ( !(ok | !-- i ) );
268
- fill_bytes (buf , off , r );
254
+ fill_bytes (buf , off , & r );
269
255
return Val_bool (ok );
270
256
#else
271
257
/* ARM: CPU-assisted randomness here. */
0 commit comments