/* SPDX-License-Identifier: LGPL-2.1+ */
-#ifdef __x86_64__
+#if defined(__i386__) || defined(__x86_64__)
#include <cpuid.h>
#endif
#include <sanitizer/msan_interface.h>
#endif
-int rdrand64(uint64_t *ret) {
+int rdrand(unsigned long *ret) {
-#ifdef __x86_64__
+#if defined(__i386__) || defined(__x86_64__)
static int have_rdrand = -1;
unsigned char err;
* allows us too, since this way we won't drain the kernel randomness pool if we don't need it, as the
* pool's entropy is scarce. */
for (;;) {
- uint64_t u;
+ unsigned long u;
size_t m;
- if (rdrand64(&u) < 0) {
+ if (rdrand(&u) < 0) {
if (got_some && FLAGS_SET(flags, RANDOM_EXTEND_WITH_PSEUDO)) {
/* Fill in the remaining bytes using pseudo-random values */
pseudo_random_bytes(p, n);
#if HAVE_SYS_AUXV_H
const void *auxv;
#endif
- uint64_t k;
+ unsigned long k;
if (srand_called)
return;
x ^= (unsigned) now(CLOCK_REALTIME);
x ^= (unsigned) gettid();
- if (rdrand64(&k) >= 0)
+ if (rdrand(&k) >= 0)
x ^= (unsigned) k;
srand(x);
}
}
-static void test_rdrand64(void) {
+static void test_rdrand(void) {
int r, i;
for (i = 0; i < 10; i++) {
- uint64_t x = 0;
+ unsigned long x = 0;
- r = rdrand64(&x);
+ r = rdrand(&x);
if (r < 0) {
log_error_errno(r, "RDRAND failed: %m");
return;
}
- printf("%" PRIx64 "\n", x);
+ printf("%lx\n", x);
}
}
test_pseudo_random_bytes();
- test_rdrand64();
+ test_rdrand();
return 0;
}