X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/89717a56084f7cac56330c8527fbaff99b15709b..7b0d1a63587f3cb1ae3bb8b248bbb1b82bdca7bd:/rand/rand.c diff --git a/rand/rand.c b/rand/rand.c index 6787c11a..32605ac0 100644 --- a/rand/rand.c +++ b/rand/rand.c @@ -161,24 +161,14 @@ CPU_DISPATCH(static, return, int, quick, (rand_pool *r), (r), static int trivial_quick(rand_pool *r) { return (-1); } -#if __GNUC__ && (CPUFAM_X86 || CPUFAM_AMD64) -static int rdrand_quick(rand_pool *r) -{ - unsigned long rr; - int i = 16; - - __asm__ ("0: rdrand %0; jc 9f; dec %1; jnz 0b; 9:" - : "=r" (rr), "=r" (i) : "1" (i) : "cc"); - if (!i) return (-1); - rand_add(r, &rr, sizeof(rr), 8*sizeof(rr)); - return (0); -} +#if CPUFAM_X86 || CPUFAM_AMD64 +extern int rand_quick_x86ish_rdrand(rand_pool */*r*/); #endif static quick__functype *pick_quick(void) { -#if __GNUC__ && (CPUFAM_X86 || CPUFAM_AMD64) - DISPATCH_PICK_COND(rand_quick, rdrand_quick, +#if CPUFAM_X86 || CPUFAM_AMD64 + DISPATCH_PICK_COND(rand_quick, rand_quick_x86ish_rdrand, cpu_feature_p(CPUFEAT_X86_RDRAND)); #endif DISPATCH_PICK_FALLBACK(rand_quick, trivial_quick); @@ -261,9 +251,7 @@ void rand_add(rand_pool *r, const void *p, size_t sz, unsigned goodbits) const octet *c = p; int i, rot; -#if RAND_POOLSZ != 128 -# error Polynomial in rand_add is out of date. Fix it. -#endif + STATIC_ASSERT(RAND_POOLSZ == 128, "Polynomial doesn't match pool size"); RAND_RESOLVE(r);