diff options
author | jsing <> | 2024-08-31 12:43:58 +0000 |
---|---|---|
committer | jsing <> | 2024-08-31 12:43:58 +0000 |
commit | 4d860a7d33bdb05e5782330d5085fda5e809bd72 (patch) | |
tree | ce0f04393328694fbea716953d4d7ed39d8db04c /src/lib | |
parent | 2049348fa6a328167273a9ddbd4a308041e0fe16 (diff) | |
download | openbsd-4d860a7d33bdb05e5782330d5085fda5e809bd72.tar.gz openbsd-4d860a7d33bdb05e5782330d5085fda5e809bd72.tar.bz2 openbsd-4d860a7d33bdb05e5782330d5085fda5e809bd72.zip |
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@
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/cryptlib.c | 30 | ||||
-rw-r--r-- | src/lib/libcrypto/crypto.h | 11 |
2 files changed, 23 insertions, 18 deletions
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 @@ | |||
1 | /* $OpenBSD: cryptlib.c,v 1.52 2024/07/09 07:16:44 beck Exp $ */ | 1 | /* $OpenBSD: cryptlib.c,v 1.53 2024/08/31 12:43:58 jsing 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 | * |
@@ -125,6 +125,10 @@ | |||
125 | #include <openssl/crypto.h> | 125 | #include <openssl/crypto.h> |
126 | 126 | ||
127 | #include "crypto_local.h" | 127 | #include "crypto_local.h" |
128 | #include "x86_arch.h" | ||
129 | |||
130 | /* Machine independent capabilities. */ | ||
131 | uint64_t crypto_cpu_caps; | ||
128 | 132 | ||
129 | static void (*locking_callback)(int mode, int type, | 133 | static void (*locking_callback)(int mode, int type, |
130 | const char *file, int line) = NULL; | 134 | const char *file, int line) = NULL; |
@@ -330,13 +334,6 @@ CRYPTO_THREADID_hash(const CRYPTO_THREADID *id) | |||
330 | 334 | ||
331 | uint64_t OPENSSL_ia32cap_P; | 335 | uint64_t OPENSSL_ia32cap_P; |
332 | 336 | ||
333 | uint64_t | ||
334 | OPENSSL_cpu_caps(void) | ||
335 | { | ||
336 | return OPENSSL_ia32cap_P; | ||
337 | } | ||
338 | LCRYPTO_ALIAS(OPENSSL_cpu_caps); | ||
339 | |||
340 | #if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) | 337 | #if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) |
341 | #define OPENSSL_CPUID_SETUP | 338 | #define OPENSSL_CPUID_SETUP |
342 | void | 339 | void |
@@ -349,16 +346,12 @@ OPENSSL_cpuid_setup(void) | |||
349 | return; | 346 | return; |
350 | trigger = 1; | 347 | trigger = 1; |
351 | OPENSSL_ia32cap_P = OPENSSL_ia32_cpuid(); | 348 | OPENSSL_ia32cap_P = OPENSSL_ia32_cpuid(); |
349 | |||
350 | if ((OPENSSL_ia32cap_P & CPUCAP_MASK_AESNI) != 0) | ||
351 | crypto_cpu_caps |= CRYPTO_CPU_CAPS_ACCELERATED_AES; | ||
352 | } | 352 | } |
353 | #endif | 353 | #endif |
354 | 354 | ||
355 | #else | ||
356 | uint64_t | ||
357 | OPENSSL_cpu_caps(void) | ||
358 | { | ||
359 | return 0; | ||
360 | } | ||
361 | LCRYPTO_ALIAS(OPENSSL_cpu_caps); | ||
362 | #endif | 355 | #endif |
363 | 356 | ||
364 | #if !defined(OPENSSL_CPUID_SETUP) && !defined(OPENSSL_CPUID_OBJ) | 357 | #if !defined(OPENSSL_CPUID_SETUP) && !defined(OPENSSL_CPUID_OBJ) |
@@ -368,6 +361,13 @@ OPENSSL_cpuid_setup(void) | |||
368 | } | 361 | } |
369 | #endif | 362 | #endif |
370 | 363 | ||
364 | uint64_t | ||
365 | OPENSSL_cpu_caps(void) | ||
366 | { | ||
367 | return crypto_cpu_caps; | ||
368 | } | ||
369 | LCRYPTO_ALIAS(OPENSSL_cpu_caps); | ||
370 | |||
371 | static void | 371 | static void |
372 | OPENSSL_showfatal(const char *fmta, ...) | 372 | OPENSSL_showfatal(const char *fmta, ...) |
373 | { | 373 | { |
diff --git a/src/lib/libcrypto/crypto.h b/src/lib/libcrypto/crypto.h index 40d3a43f4f..bcca5a0ace 100644 --- a/src/lib/libcrypto/crypto.h +++ b/src/lib/libcrypto/crypto.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: crypto.h,v 1.74 2024/04/10 15:13:23 beck Exp $ */ | 1 | /* $OpenBSD: crypto.h,v 1.75 2024/08/31 12:43:58 jsing 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 | * |
@@ -373,8 +373,6 @@ __attribute__((__noreturn__)) | |||
373 | void OpenSSLDie(const char *file, int line, const char *assertion); | 373 | void OpenSSLDie(const char *file, int line, const char *assertion); |
374 | #define OPENSSL_assert(e) (void)((e) ? 0 : (OpenSSLDie(__FILE__, __LINE__, #e),1)) | 374 | #define OPENSSL_assert(e) (void)((e) ? 0 : (OpenSSLDie(__FILE__, __LINE__, #e),1)) |
375 | 375 | ||
376 | uint64_t OPENSSL_cpu_caps(void); | ||
377 | |||
378 | int FIPS_mode(void); | 376 | int FIPS_mode(void); |
379 | int FIPS_mode_set(int r); | 377 | int FIPS_mode_set(int r); |
380 | 378 | ||
@@ -423,6 +421,13 @@ int OPENSSL_init_crypto(uint64_t opts, const void *settings); | |||
423 | void OPENSSL_cleanup(void); | 421 | void OPENSSL_cleanup(void); |
424 | 422 | ||
425 | /* | 423 | /* |
424 | * CPU capabilities. | ||
425 | */ | ||
426 | #define CRYPTO_CPU_CAPS_ACCELERATED_AES 0x00000001ULL | ||
427 | |||
428 | uint64_t OPENSSL_cpu_caps(void); | ||
429 | |||
430 | /* | ||
426 | * OpenSSL helpfully put OPENSSL_gmtime() here because all other time related | 431 | * OpenSSL helpfully put OPENSSL_gmtime() here because all other time related |
427 | * functions are in asn1.h. | 432 | * functions are in asn1.h. |
428 | */ | 433 | */ |