From 4d860a7d33bdb05e5782330d5085fda5e809bd72 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sat, 31 Aug 2024 12:43:58 +0000 Subject: Make OPENSSL_cpu_caps() machine independent. OPENSSL_cpu_caps() is currently machine dependent and exposes CPUID data on amd64 and i386. However, what it is really used for is to indicate whether specific algorithms are accelerated on the given hardware. Change OPENSSL_cpu_caps() so that it returns a machine indepent value, which decouples it from amd64/i386 and will allow it to be used appropriately on other platforms in the future. ok tb@ --- src/lib/libcrypto/cryptlib.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/lib/libcrypto/cryptlib.c') diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c index b9ea39285d..d929b0daaa 100644 --- a/src/lib/libcrypto/cryptlib.c +++ b/src/lib/libcrypto/cryptlib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cryptlib.c,v 1.52 2024/07/09 07:16:44 beck Exp $ */ +/* $OpenBSD: cryptlib.c,v 1.53 2024/08/31 12:43:58 jsing Exp $ */ /* ==================================================================== * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. * @@ -125,6 +125,10 @@ #include #include "crypto_local.h" +#include "x86_arch.h" + +/* Machine independent capabilities. */ +uint64_t crypto_cpu_caps; static void (*locking_callback)(int mode, int type, const char *file, int line) = NULL; @@ -330,13 +334,6 @@ CRYPTO_THREADID_hash(const CRYPTO_THREADID *id) uint64_t OPENSSL_ia32cap_P; -uint64_t -OPENSSL_cpu_caps(void) -{ - return OPENSSL_ia32cap_P; -} -LCRYPTO_ALIAS(OPENSSL_cpu_caps); - #if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) #define OPENSSL_CPUID_SETUP void @@ -349,16 +346,12 @@ OPENSSL_cpuid_setup(void) return; trigger = 1; OPENSSL_ia32cap_P = OPENSSL_ia32_cpuid(); + + if ((OPENSSL_ia32cap_P & CPUCAP_MASK_AESNI) != 0) + crypto_cpu_caps |= CRYPTO_CPU_CAPS_ACCELERATED_AES; } #endif -#else -uint64_t -OPENSSL_cpu_caps(void) -{ - return 0; -} -LCRYPTO_ALIAS(OPENSSL_cpu_caps); #endif #if !defined(OPENSSL_CPUID_SETUP) && !defined(OPENSSL_CPUID_OBJ) @@ -368,6 +361,13 @@ OPENSSL_cpuid_setup(void) } #endif +uint64_t +OPENSSL_cpu_caps(void) +{ + return crypto_cpu_caps; +} +LCRYPTO_ALIAS(OPENSSL_cpu_caps); + static void OPENSSL_showfatal(const char *fmta, ...) { -- cgit v1.2.3-55-g6feb