From 1a12fc8399638223feca8f853e2ac2cc22eeb471 Mon Sep 17 00:00:00 2001 From: miod <> Date: Fri, 4 Nov 2016 17:30:30 +0000 Subject: Replace all uses of magic numbers when operating on OPENSSL_ia32_P[] by meaningful constants in a private header file, so that reviewers can actually get a chance to figure out what the code is attempting to do without knowing all cpuid bits. While there, turn it from an array of two 32-bit ints into a properly aligned 64-bit int. Use of OPENSSL_ia32_P is now restricted to the assembler parts. C code will now always use OPENSSL_cpu_caps() and check for the proper bits in the whole 64-bit word it returns. i386 tests and ok jsing@ --- src/lib/libcrypto/engine/eng_aesni.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/lib/libcrypto/engine') diff --git a/src/lib/libcrypto/engine/eng_aesni.c b/src/lib/libcrypto/engine/eng_aesni.c index 5f9a36236a..92794f6086 100644 --- a/src/lib/libcrypto/engine/eng_aesni.c +++ b/src/lib/libcrypto/engine/eng_aesni.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eng_aesni.c,v 1.8 2015/02/10 09:46:30 miod Exp $ */ +/* $OpenBSD: eng_aesni.c,v 1.9 2016/11/04 17:30:30 miod Exp $ */ /* * Support for Intel AES-NI intruction set * Author: Huang Ying @@ -93,10 +93,11 @@ defined(_M_AMD64) || defined(_M_X64) || \ defined(OPENSSL_IA32_SSE2)) && !defined(OPENSSL_NO_ASM) && !defined(__i386__) #define COMPILE_HW_AESNI +#include "x86_arch.h" #endif -static ENGINE *ENGINE_aesni (void); +static ENGINE *ENGINE_aesni(void); -void ENGINE_load_aesni (void) +void ENGINE_load_aesni(void) { /* On non-x86 CPUs it just returns. */ #ifdef COMPILE_HW_AESNI @@ -302,20 +303,13 @@ aesni_ofb128_encrypt(const unsigned char *in, unsigned char *out, } /* ===== Engine "management" functions ===== */ -typedef unsigned long long IA32CAP; - /* Prepare the ENGINE structure for registration */ static int aesni_bind_helper(ENGINE *e) { int engage; - if (sizeof(OPENSSL_ia32cap_P) > 4) { - engage = ((IA32CAP)OPENSSL_ia32cap_P >> 57) & 1; - } else { - IA32CAP OPENSSL_ia32_cpuid(void); - engage = (OPENSSL_ia32_cpuid() >> 57) & 1; - } + engage = (OPENSSL_cpu_caps() & CPUCAP_MASK_AESNI) != 0; /* Register everything or return with an error */ if (!ENGINE_set_id(e, aesni_id) || -- cgit v1.2.3-55-g6feb