summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2024-09-06 09:57:32 +0000
committertb <>2024-09-06 09:57:32 +0000
commit2f477ae2728d0ed1462508692e09b8f3c8398d90 (patch)
treec22e39e94e81983bcd1b3626eb8f8209d4c33a03
parent1cf5f5e953944e829c982d02e497cddf8a7ed9c4 (diff)
downloadopenbsd-2f477ae2728d0ed1462508692e09b8f3c8398d90.tar.gz
openbsd-2f477ae2728d0ed1462508692e09b8f3c8398d90.tar.bz2
openbsd-2f477ae2728d0ed1462508692e09b8f3c8398d90.zip
Reenable AES-NI in libcrypto
The OPENSSL_cpu_caps() change after the last bump missed a crucial bit: there is more MD mess in the MI code than anticipated, with the result that AES is now used without AES-NI on amd64 and i386, hurting machines that previously greatly benefitted from it. Temporarily add an internal crypto_cpu_caps_ia32() API that returns the OPENSSL_ia32cap_P or 0 like OPENSSL_cpu_caps() previously did. This can be improved after the release. Regression reported and fix tested by Mark Patruck. No impact on public ABI or API. with/ok jsing PS: Next time my pkg_add feels very slow, I should perhaps not mechanically blame IEEE 802.11...
-rw-r--r--src/lib/libcrypto/cryptlib.c14
-rw-r--r--src/lib/libcrypto/crypto_internal.h4
-rw-r--r--src/lib/libcrypto/evp/e_aes.c8
-rw-r--r--src/lib/libcrypto/modes/gcm128.c13
4 files changed, 29 insertions, 10 deletions
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c
index d929b0daaa..59e6456bbb 100644
--- a/src/lib/libcrypto/cryptlib.c
+++ b/src/lib/libcrypto/cryptlib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cryptlib.c,v 1.53 2024/08/31 12:43:58 jsing Exp $ */ 1/* $OpenBSD: cryptlib.c,v 1.54 2024/09/06 09:57:32 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -334,6 +334,12 @@ CRYPTO_THREADID_hash(const CRYPTO_THREADID *id)
334 334
335uint64_t OPENSSL_ia32cap_P; 335uint64_t OPENSSL_ia32cap_P;
336 336
337uint64_t
338crypto_cpu_caps_ia32(void)
339{
340 return OPENSSL_ia32cap_P;
341}
342
337#if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) 343#if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM)
338#define OPENSSL_CPUID_SETUP 344#define OPENSSL_CPUID_SETUP
339void 345void
@@ -352,6 +358,12 @@ OPENSSL_cpuid_setup(void)
352} 358}
353#endif 359#endif
354 360
361#else
362uint64_t
363crypto_cpu_caps_ia32(void)
364{
365 return 0;
366}
355#endif 367#endif
356 368
357#if !defined(OPENSSL_CPUID_SETUP) && !defined(OPENSSL_CPUID_OBJ) 369#if !defined(OPENSSL_CPUID_SETUP) && !defined(OPENSSL_CPUID_OBJ)
diff --git a/src/lib/libcrypto/crypto_internal.h b/src/lib/libcrypto/crypto_internal.h
index 7676076f67..fc617472ad 100644
--- a/src/lib/libcrypto/crypto_internal.h
+++ b/src/lib/libcrypto/crypto_internal.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: crypto_internal.h,v 1.11 2024/08/11 13:02:39 jsing Exp $ */ 1/* $OpenBSD: crypto_internal.h,v 1.12 2024/09/06 09:57:32 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -220,4 +220,6 @@ crypto_ror_u64(uint64_t v, size_t shift)
220} 220}
221#endif 221#endif
222 222
223uint64_t crypto_cpu_caps_ia32(void);
224
223#endif 225#endif
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c
index 6135c7d84a..7753c18c15 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.58 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: e_aes.c,v 1.59 2024/09/06 09:57:32 tb 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 *
@@ -55,6 +55,8 @@
55 55
56#include <openssl/opensslconf.h> 56#include <openssl/opensslconf.h>
57 57
58#include "crypto_internal.h"
59
58#ifndef OPENSSL_NO_AES 60#ifndef OPENSSL_NO_AES
59#include <openssl/aes.h> 61#include <openssl/aes.h>
60#include <openssl/err.h> 62#include <openssl/err.h>
@@ -154,7 +156,7 @@ void AES_xts_decrypt(const char *inp, char *out, size_t len,
154#include "x86_arch.h" 156#include "x86_arch.h"
155 157
156#ifdef VPAES_ASM 158#ifdef VPAES_ASM
157#define VPAES_CAPABLE (OPENSSL_cpu_caps() & CPUCAP_MASK_SSSE3) 159#define VPAES_CAPABLE (crypto_cpu_caps_ia32() & CPUCAP_MASK_SSSE3)
158#endif 160#endif
159#ifdef BSAES_ASM 161#ifdef BSAES_ASM
160#define BSAES_CAPABLE VPAES_CAPABLE 162#define BSAES_CAPABLE VPAES_CAPABLE
@@ -162,7 +164,7 @@ void AES_xts_decrypt(const char *inp, char *out, size_t len,
162/* 164/*
163 * AES-NI section 165 * AES-NI section
164 */ 166 */
165#define AESNI_CAPABLE (OPENSSL_cpu_caps() & CPUCAP_MASK_AESNI) 167#define AESNI_CAPABLE (crypto_cpu_caps_ia32() & CPUCAP_MASK_AESNI)
166 168
167int aesni_set_encrypt_key(const unsigned char *userKey, int bits, 169int aesni_set_encrypt_key(const unsigned char *userKey, int bits,
168 AES_KEY *key); 170 AES_KEY *key);
diff --git a/src/lib/libcrypto/modes/gcm128.c b/src/lib/libcrypto/modes/gcm128.c
index cbda8ad097..6c89bd44b7 100644
--- a/src/lib/libcrypto/modes/gcm128.c
+++ b/src/lib/libcrypto/modes/gcm128.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gcm128.c,v 1.26 2023/08/10 07:18:43 jsing Exp $ */ 1/* $OpenBSD: gcm128.c,v 1.27 2024/09/06 09:57:32 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2010 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2010 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -50,9 +50,12 @@
50 50
51#define OPENSSL_FIPSAPI 51#define OPENSSL_FIPSAPI
52 52
53#include <string.h>
54
53#include <openssl/crypto.h> 55#include <openssl/crypto.h>
56
57#include "crypto_internal.h"
54#include "modes_local.h" 58#include "modes_local.h"
55#include <string.h>
56 59
57#ifndef MODES_DEBUG 60#ifndef MODES_DEBUG
58# ifndef NDEBUG 61# ifndef NDEBUG
@@ -660,7 +663,7 @@ CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block)
660# if defined(GHASH_ASM_X86_OR_64) 663# if defined(GHASH_ASM_X86_OR_64)
661# if !defined(GHASH_ASM_X86) || defined(OPENSSL_IA32_SSE2) 664# if !defined(GHASH_ASM_X86) || defined(OPENSSL_IA32_SSE2)
662 /* check FXSR and PCLMULQDQ bits */ 665 /* check FXSR and PCLMULQDQ bits */
663 if ((OPENSSL_cpu_caps() & (CPUCAP_MASK_FXSR | CPUCAP_MASK_PCLMUL)) == 666 if ((crypto_cpu_caps_ia32() & (CPUCAP_MASK_FXSR | CPUCAP_MASK_PCLMUL)) ==
664 (CPUCAP_MASK_FXSR | CPUCAP_MASK_PCLMUL)) { 667 (CPUCAP_MASK_FXSR | CPUCAP_MASK_PCLMUL)) {
665 gcm_init_clmul(ctx->Htable, ctx->H.u); 668 gcm_init_clmul(ctx->Htable, ctx->H.u);
666 ctx->gmult = gcm_gmult_clmul; 669 ctx->gmult = gcm_gmult_clmul;
@@ -671,9 +674,9 @@ CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block)
671 gcm_init_4bit(ctx->Htable, ctx->H.u); 674 gcm_init_4bit(ctx->Htable, ctx->H.u);
672# if defined(GHASH_ASM_X86) /* x86 only */ 675# if defined(GHASH_ASM_X86) /* x86 only */
673# if defined(OPENSSL_IA32_SSE2) 676# if defined(OPENSSL_IA32_SSE2)
674 if (OPENSSL_cpu_caps() & CPUCAP_MASK_SSE) { /* check SSE bit */ 677 if (crypto_cpu_caps_ia32() & CPUCAP_MASK_SSE) { /* check SSE bit */
675# else 678# else
676 if (OPENSSL_cpu_caps() & CPUCAP_MASK_MMX) { /* check MMX bit */ 679 if (crypto_cpu_caps_ia32() & CPUCAP_MASK_MMX) { /* check MMX bit */
677# endif 680# endif
678 ctx->gmult = gcm_gmult_4bit_mmx; 681 ctx->gmult = gcm_gmult_4bit_mmx;
679 ctx->ghash = gcm_ghash_4bit_mmx; 682 ctx->ghash = gcm_ghash_4bit_mmx;