8 uint32_t ax,bx,cx,dx,func=1;
9 __asm__ volatile ("cpuid":\
10 "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func));
11 return (cx & 0x40000000);
15// Returns 1 on success
16static inline int _rdrand64_step(uint64_t *therand)
19 asm volatile("rdrand %0 ; setc %1"
20 : "=r" (*therand), "=qm" (err));
24// Returns 0 on success, non-zero on failure.
25int get_rand_bytes(uint8_t *therand, size_t len)
30 uint8_t *end = therand + len;
31 if((uint64_t)p%8 != 0) {
33 fail |= !_rdrand64_step(&tmp);
34 while((uint64_t)p%8 != 0 && p != end) {
35 *p = (uint8_t)(tmp & 0xFF);
40 for(; p <= end - sizeof(uint64_t); p+=sizeof(uint64_t)) {
41 fail |= !_rdrand64_step((uint64_t *)p);
46 fail |= !_rdrand64_step(&tmp);
48 *p = (uint8_t)(tmp & 0xFF);
58// Returns 1 on success
59static inline int _rdrand32_step(uint32_t *therand)
62 asm volatile("rdrand %0 ; setc %1"
63 : "=r" (*therand), "=qm" (err));
67int get_rand_bytes(uint8_t *therand, size_t len)
72 uint8_t *end = therand + len;
73 if((uint32_t)p % sizeof(uint32_t) != 0) {
75 fail |= !_rdrand32_step(&tmp);
76 while((uint32_t)p % sizeof(uint32_t) != 0 && p != end) {
77 *p = (uint8_t)(tmp & 0xFF);
82 for(; p <= end - sizeof(uint32_t); p+=sizeof(uint32_t)) {
83 fail |= !_rdrand32_step((uint32_t *)p);
88 fail |= !_rdrand32_step(&tmp);
90 *p = (uint8_t)(tmp & 0xFF);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list