diff options
| author | miod <> | 2016-11-04 17:30:30 +0000 |
|---|---|---|
| committer | miod <> | 2016-11-04 17:30:30 +0000 |
| commit | 1a12fc8399638223feca8f853e2ac2cc22eeb471 (patch) | |
| tree | 77b413175d422148cfb0ef7b2062340230aa5413 /src/lib/libcrypto/engine | |
| parent | 78e68d71838891e44ddbb5238203ccfce3b62d80 (diff) | |
| download | openbsd-1a12fc8399638223feca8f853e2ac2cc22eeb471.tar.gz openbsd-1a12fc8399638223feca8f853e2ac2cc22eeb471.tar.bz2 openbsd-1a12fc8399638223feca8f853e2ac2cc22eeb471.zip | |
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@
Diffstat (limited to 'src/lib/libcrypto/engine')
| -rw-r--r-- | src/lib/libcrypto/engine/eng_aesni.c | 16 |
1 files changed, 5 insertions, 11 deletions
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 @@ | |||
| 1 | /* $OpenBSD: eng_aesni.c,v 1.8 2015/02/10 09:46:30 miod Exp $ */ | 1 | /* $OpenBSD: eng_aesni.c,v 1.9 2016/11/04 17:30:30 miod Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Support for Intel AES-NI intruction set | 3 | * Support for Intel AES-NI intruction set |
| 4 | * Author: Huang Ying <ying.huang@intel.com> | 4 | * Author: Huang Ying <ying.huang@intel.com> |
| @@ -93,10 +93,11 @@ | |||
| 93 | defined(_M_AMD64) || defined(_M_X64) || \ | 93 | defined(_M_AMD64) || defined(_M_X64) || \ |
| 94 | defined(OPENSSL_IA32_SSE2)) && !defined(OPENSSL_NO_ASM) && !defined(__i386__) | 94 | defined(OPENSSL_IA32_SSE2)) && !defined(OPENSSL_NO_ASM) && !defined(__i386__) |
| 95 | #define COMPILE_HW_AESNI | 95 | #define COMPILE_HW_AESNI |
| 96 | #include "x86_arch.h" | ||
| 96 | #endif | 97 | #endif |
| 97 | static ENGINE *ENGINE_aesni (void); | 98 | static ENGINE *ENGINE_aesni(void); |
| 98 | 99 | ||
| 99 | void ENGINE_load_aesni (void) | 100 | void ENGINE_load_aesni(void) |
| 100 | { | 101 | { |
| 101 | /* On non-x86 CPUs it just returns. */ | 102 | /* On non-x86 CPUs it just returns. */ |
| 102 | #ifdef COMPILE_HW_AESNI | 103 | #ifdef COMPILE_HW_AESNI |
| @@ -302,20 +303,13 @@ aesni_ofb128_encrypt(const unsigned char *in, unsigned char *out, | |||
| 302 | } | 303 | } |
| 303 | /* ===== Engine "management" functions ===== */ | 304 | /* ===== Engine "management" functions ===== */ |
| 304 | 305 | ||
| 305 | typedef unsigned long long IA32CAP; | ||
| 306 | |||
| 307 | /* Prepare the ENGINE structure for registration */ | 306 | /* Prepare the ENGINE structure for registration */ |
| 308 | static int | 307 | static int |
| 309 | aesni_bind_helper(ENGINE *e) | 308 | aesni_bind_helper(ENGINE *e) |
| 310 | { | 309 | { |
| 311 | int engage; | 310 | int engage; |
| 312 | 311 | ||
| 313 | if (sizeof(OPENSSL_ia32cap_P) > 4) { | 312 | engage = (OPENSSL_cpu_caps() & CPUCAP_MASK_AESNI) != 0; |
| 314 | engage = ((IA32CAP)OPENSSL_ia32cap_P >> 57) & 1; | ||
| 315 | } else { | ||
| 316 | IA32CAP OPENSSL_ia32_cpuid(void); | ||
| 317 | engage = (OPENSSL_ia32_cpuid() >> 57) & 1; | ||
| 318 | } | ||
| 319 | 313 | ||
| 320 | /* Register everything or return with an error */ | 314 | /* Register everything or return with an error */ |
| 321 | if (!ENGINE_set_id(e, aesni_id) || | 315 | if (!ENGINE_set_id(e, aesni_id) || |
