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/evp | |
| 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/evp')
| -rw-r--r-- | src/lib/libcrypto/evp/e_aes.c | 8 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c | 11 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/e_rc4_hmac_md5.c | 8 |
3 files changed, 13 insertions, 14 deletions
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c index 25199dca36..b20543a90c 100644 --- a/src/lib/libcrypto/evp/e_aes.c +++ b/src/lib/libcrypto/evp/e_aes.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: e_aes.c,v 1.30 2016/11/04 13:56:05 miod Exp $ */ | 1 | /* $OpenBSD: e_aes.c,v 1.31 2016/11/04 17:30:30 miod Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| @@ -150,10 +150,10 @@ void AES_xts_decrypt(const char *inp, char *out, size_t len, | |||
| 150 | defined(_M_AMD64) || defined(_M_X64) || \ | 150 | defined(_M_AMD64) || defined(_M_X64) || \ |
| 151 | defined(__INTEL__) ) | 151 | defined(__INTEL__) ) |
| 152 | 152 | ||
| 153 | extern unsigned int OPENSSL_ia32cap_P[]; | 153 | #include "x86_arch.h" |
| 154 | 154 | ||
| 155 | #ifdef VPAES_ASM | 155 | #ifdef VPAES_ASM |
| 156 | #define VPAES_CAPABLE (OPENSSL_ia32cap_P[1]&(1<<(41-32))) | 156 | #define VPAES_CAPABLE (OPENSSL_cpu_caps() & CPUCAP_MASK_SSSE3) |
| 157 | #endif | 157 | #endif |
| 158 | #ifdef BSAES_ASM | 158 | #ifdef BSAES_ASM |
| 159 | #define BSAES_CAPABLE VPAES_CAPABLE | 159 | #define BSAES_CAPABLE VPAES_CAPABLE |
| @@ -161,7 +161,7 @@ extern unsigned int OPENSSL_ia32cap_P[]; | |||
| 161 | /* | 161 | /* |
| 162 | * AES-NI section | 162 | * AES-NI section |
| 163 | */ | 163 | */ |
| 164 | #define AESNI_CAPABLE (OPENSSL_ia32cap_P[1]&(1<<(57-32))) | 164 | #define AESNI_CAPABLE (OPENSSL_cpu_caps() & CPUCAP_MASK_AESNI) |
| 165 | 165 | ||
| 166 | int aesni_set_encrypt_key(const unsigned char *userKey, int bits, | 166 | int aesni_set_encrypt_key(const unsigned char *userKey, int bits, |
| 167 | AES_KEY *key); | 167 | AES_KEY *key); |
diff --git a/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c b/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c index 8574823aed..3f82cf5967 100644 --- a/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c +++ b/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: e_aes_cbc_hmac_sha1.c,v 1.12 2016/05/04 15:01:33 tedu Exp $ */ | 1 | /* $OpenBSD: e_aes_cbc_hmac_sha1.c,v 1.13 2016/11/04 17:30:30 miod Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 2011-2013 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2011-2013 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| @@ -87,13 +87,12 @@ typedef struct { | |||
| 87 | defined(_M_AMD64) || defined(_M_X64) || \ | 87 | defined(_M_AMD64) || defined(_M_X64) || \ |
| 88 | defined(__INTEL__) ) | 88 | defined(__INTEL__) ) |
| 89 | 89 | ||
| 90 | #include "x86_arch.h" | ||
| 91 | |||
| 90 | #if defined(__GNUC__) && __GNUC__>=2 | 92 | #if defined(__GNUC__) && __GNUC__>=2 |
| 91 | # define BSWAP(x) ({ unsigned int r=(x); asm ("bswapl %0":"=r"(r):"0"(r)); r; }) | 93 | # define BSWAP(x) ({ unsigned int r=(x); asm ("bswapl %0":"=r"(r):"0"(r)); r; }) |
| 92 | #endif | 94 | #endif |
| 93 | 95 | ||
| 94 | extern unsigned int OPENSSL_ia32cap_P[2]; | ||
| 95 | #define AESNI_CAPABLE (1<<(57-32)) | ||
| 96 | |||
| 97 | int aesni_set_encrypt_key(const unsigned char *userKey, int bits, AES_KEY *key); | 96 | int aesni_set_encrypt_key(const unsigned char *userKey, int bits, AES_KEY *key); |
| 98 | int aesni_set_decrypt_key(const unsigned char *userKey, int bits, AES_KEY *key); | 97 | int aesni_set_decrypt_key(const unsigned char *userKey, int bits, AES_KEY *key); |
| 99 | 98 | ||
| @@ -578,14 +577,14 @@ static EVP_CIPHER aesni_256_cbc_hmac_sha1_cipher = { | |||
| 578 | const EVP_CIPHER * | 577 | const EVP_CIPHER * |
| 579 | EVP_aes_128_cbc_hmac_sha1(void) | 578 | EVP_aes_128_cbc_hmac_sha1(void) |
| 580 | { | 579 | { |
| 581 | return OPENSSL_ia32cap_P[1] & AESNI_CAPABLE ? | 580 | return (OPENSSL_cpu_caps() & CPUCAP_MASK_AESNI) ? |
| 582 | &aesni_128_cbc_hmac_sha1_cipher : NULL; | 581 | &aesni_128_cbc_hmac_sha1_cipher : NULL; |
| 583 | } | 582 | } |
| 584 | 583 | ||
| 585 | const EVP_CIPHER * | 584 | const EVP_CIPHER * |
| 586 | EVP_aes_256_cbc_hmac_sha1(void) | 585 | EVP_aes_256_cbc_hmac_sha1(void) |
| 587 | { | 586 | { |
| 588 | return OPENSSL_ia32cap_P[1] & AESNI_CAPABLE ? | 587 | return (OPENSSL_cpu_caps() & CPUCAP_MASK_AESNI) ? |
| 589 | &aesni_256_cbc_hmac_sha1_cipher : NULL; | 588 | &aesni_256_cbc_hmac_sha1_cipher : NULL; |
| 590 | } | 589 | } |
| 591 | #else | 590 | #else |
diff --git a/src/lib/libcrypto/evp/e_rc4_hmac_md5.c b/src/lib/libcrypto/evp/e_rc4_hmac_md5.c index 1f085af403..39527cafe6 100644 --- a/src/lib/libcrypto/evp/e_rc4_hmac_md5.c +++ b/src/lib/libcrypto/evp/e_rc4_hmac_md5.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: e_rc4_hmac_md5.c,v 1.5 2014/08/11 13:29:43 bcook Exp $ */ | 1 | /* $OpenBSD: e_rc4_hmac_md5.c,v 1.6 2016/11/04 17:30:30 miod Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 2011 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2011 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| @@ -105,6 +105,7 @@ rc4_hmac_md5_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *inkey, | |||
| 105 | defined(__INTEL__) ) && \ | 105 | defined(__INTEL__) ) && \ |
| 106 | !(defined(__APPLE__) && defined(__MACH__)) | 106 | !(defined(__APPLE__) && defined(__MACH__)) |
| 107 | #define STITCHED_CALL | 107 | #define STITCHED_CALL |
| 108 | #include "x86_arch.h" | ||
| 108 | #endif | 109 | #endif |
| 109 | 110 | ||
| 110 | #if !defined(STITCHED_CALL) | 111 | #if !defined(STITCHED_CALL) |
| @@ -122,7 +123,6 @@ rc4_hmac_md5_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
| 122 | md5_off = MD5_CBLOCK - key->md.num, | 123 | md5_off = MD5_CBLOCK - key->md.num, |
| 123 | blocks; | 124 | blocks; |
| 124 | unsigned int l; | 125 | unsigned int l; |
| 125 | extern unsigned int OPENSSL_ia32cap_P[]; | ||
| 126 | #endif | 126 | #endif |
| 127 | size_t plen = key->payload_length; | 127 | size_t plen = key->payload_length; |
| 128 | 128 | ||
| @@ -139,7 +139,7 @@ rc4_hmac_md5_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
| 139 | 139 | ||
| 140 | if (plen > md5_off && | 140 | if (plen > md5_off && |
| 141 | (blocks = (plen - md5_off) / MD5_CBLOCK) && | 141 | (blocks = (plen - md5_off) / MD5_CBLOCK) && |
| 142 | (OPENSSL_ia32cap_P[0]&(1 << 20)) == 0) { | 142 | (OPENSSL_cpu_caps() & CPUCAP_MASK_INTELP4) == 0) { |
| 143 | MD5_Update(&key->md, in, md5_off); | 143 | MD5_Update(&key->md, in, md5_off); |
| 144 | RC4(&key->ks, rc4_off, in, out); | 144 | RC4(&key->ks, rc4_off, in, out); |
| 145 | 145 | ||
| @@ -187,7 +187,7 @@ rc4_hmac_md5_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
| 187 | rc4_off += MD5_CBLOCK; | 187 | rc4_off += MD5_CBLOCK; |
| 188 | 188 | ||
| 189 | if (len > rc4_off && (blocks = (len - rc4_off) / MD5_CBLOCK) && | 189 | if (len > rc4_off && (blocks = (len - rc4_off) / MD5_CBLOCK) && |
| 190 | (OPENSSL_ia32cap_P[0] & (1 << 20)) == 0) { | 190 | (OPENSSL_cpu_caps() & CPUCAP_MASK_INTELP4) == 0) { |
| 191 | RC4(&key->ks, rc4_off, in, out); | 191 | RC4(&key->ks, rc4_off, in, out); |
| 192 | MD5_Update(&key->md, out, md5_off); | 192 | MD5_Update(&key->md, out, md5_off); |
| 193 | 193 | ||
