From: H. Peter Anvin Date: Tue, 4 Mar 2014 22:49:10 +0000 (-0800) Subject: rngd_rdrand: Support compiling for x32 by adding unative_t X-Git-Tag: v5~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0ad21ad0a4d02faf48b5ff94db0ffb7cb43773c2;p=thirdparty%2Frng-tools.git rngd_rdrand: Support compiling for x32 by adding unative_t On the x32 ABI for x86-64, sizeof(long) == 4, but we still use the 8-byte randomness instructions and flags. In order to support compilation for x32, introduce a new type "unative_t" which is typedef'd to the appropriate type for the architecture. Signed-off-by: H. Peter Anvin --- diff --git a/rngd_rdrand.c b/rngd_rdrand.c index d50993d..064702f 100644 --- a/rngd_rdrand.c +++ b/rngd_rdrand.c @@ -60,10 +60,16 @@ extern void x86_aes_mangle(void *data, void *state); /* Expand an AES key for future use */ extern void x86_aes_expand_key(const void *key); +#ifdef __x86_64__ +typedef uint64_t unative_t; /* x86-64 or x32 */ +#else +typedef uint32_t unative_t; /* i386 */ +#endif + /* Checking eflags to confirm cpuid instruction available */ -static inline int x86_has_eflag(unsigned long flag) +static inline int x86_has_eflag(unative_t flag) { - unsigned long f0, f1; + unative_t f0, f1; asm("pushf ; " "pushf ; " "pop %0 ; " @@ -160,7 +166,7 @@ int xread_drng(void *buf, size_t size, struct rng *ent_src) while (size) { for (i = 0; i < rdrand_round_count; i++) { - if (!x86_rdrand_nlong(tmp, CHUNK_SIZE/sizeof(long))) { + if (!x86_rdrand_nlong(tmp, CHUNK_SIZE/sizeof(unative_t))) { message(LOG_DAEMON|LOG_ERR, "read error\n"); return -1; } @@ -262,7 +268,7 @@ int init_drng_entropy_source(struct rng *ent_src) have_aesni = !!(info.ecx & features_ecx1_aesni); /* Randomize the AES data reduction key the best we can */ - if (!x86_rdrand_nlong(xkey, sizeof xkey/sizeof(long))) + if (!x86_rdrand_nlong(xkey, sizeof xkey/sizeof(unative_t))) return 1; fd = open("/dev/urandom", O_RDONLY); @@ -275,7 +281,7 @@ int init_drng_entropy_source(struct rng *ent_src) key[i] ^= xkey[i]; /* Initialize the IV buffer */ - if (!x86_rdrand_nlong(iv_buf, CHUNK_SIZE/sizeof(long))) + if (!x86_rdrand_nlong(iv_buf, CHUNK_SIZE/sizeof(unative_t))) return 1; if (init_aesni(key) && init_gcrypt(key))