summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2024-10-19 13:06:11 +0000
committerjsing <>2024-10-19 13:06:11 +0000
commitddd498e9dc3b8e01469736ea80d9583f6d3b978a (patch)
tree80abe0c72655c8ae71236c909363b30c8bb010ba
parentd2377970fef7d1c8e41cbb1d93b5e43185f032fc (diff)
downloadopenbsd-ddd498e9dc3b8e01469736ea80d9583f6d3b978a.tar.gz
openbsd-ddd498e9dc3b8e01469736ea80d9583f6d3b978a.tar.bz2
openbsd-ddd498e9dc3b8e01469736ea80d9583f6d3b978a.zip
Remove IA32 specific code from cryptlib.c.
Move the IA32 specific code to arch/{amd64,i386}/crypto_cpu_caps.c, rather than polluting cryptlib.c with machine dependent code. A stub version of crypto_cpu_caps_ia32() still remains for now.
-rw-r--r--src/lib/libcrypto/arch/amd64/crypto_arch.h3
-rw-r--r--src/lib/libcrypto/arch/amd64/crypto_cpu_caps.c10
-rw-r--r--src/lib/libcrypto/arch/i386/crypto_arch.h3
-rw-r--r--src/lib/libcrypto/arch/i386/crypto_cpu_caps.c10
-rw-r--r--src/lib/libcrypto/cryptlib.c44
5 files changed, 29 insertions, 41 deletions
diff --git a/src/lib/libcrypto/arch/amd64/crypto_arch.h b/src/lib/libcrypto/arch/amd64/crypto_arch.h
index 6feeaa209e..64b2da587b 100644
--- a/src/lib/libcrypto/arch/amd64/crypto_arch.h
+++ b/src/lib/libcrypto/arch/amd64/crypto_arch.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: crypto_arch.h,v 1.2 2024/10/18 13:36:24 jsing Exp $ */ 1/* $OpenBSD: crypto_arch.h,v 1.3 2024/10/19 13:06:11 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2024 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -19,6 +19,7 @@
19#define HEADER_CRYPTO_ARCH_H 19#define HEADER_CRYPTO_ARCH_H
20 20
21#define HAVE_CRYPTO_CPU_CAPS_INIT 21#define HAVE_CRYPTO_CPU_CAPS_INIT
22#define HAVE_CRYPTO_CPU_CAPS_IA32
22 23
23#ifndef OPENSSL_NO_ASM 24#ifndef OPENSSL_NO_ASM
24 25
diff --git a/src/lib/libcrypto/arch/amd64/crypto_cpu_caps.c b/src/lib/libcrypto/arch/amd64/crypto_cpu_caps.c
index 8cbf24edbd..b0da0d636c 100644
--- a/src/lib/libcrypto/arch/amd64/crypto_cpu_caps.c
+++ b/src/lib/libcrypto/arch/amd64/crypto_cpu_caps.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: crypto_cpu_caps.c,v 1.1 2024/10/18 13:36:24 jsing Exp $ */ 1/* $OpenBSD: crypto_cpu_caps.c,v 1.2 2024/10/19 13:06:11 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2024 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -22,7 +22,7 @@
22#include "x86_arch.h" 22#include "x86_arch.h"
23 23
24/* Legacy architecture specific capabilities, used by perlasm. */ 24/* Legacy architecture specific capabilities, used by perlasm. */
25extern uint64_t OPENSSL_ia32cap_P; 25uint64_t OPENSSL_ia32cap_P;
26 26
27/* Machine independent CPU capabilities. */ 27/* Machine independent CPU capabilities. */
28extern uint64_t crypto_cpu_caps; 28extern uint64_t crypto_cpu_caps;
@@ -112,3 +112,9 @@ crypto_cpu_caps_init(void)
112 112
113 OPENSSL_ia32cap_P = caps; 113 OPENSSL_ia32cap_P = caps;
114} 114}
115
116uint64_t
117crypto_cpu_caps_ia32(void)
118{
119 return OPENSSL_ia32cap_P;
120}
diff --git a/src/lib/libcrypto/arch/i386/crypto_arch.h b/src/lib/libcrypto/arch/i386/crypto_arch.h
index d566d8064a..64b2da587b 100644
--- a/src/lib/libcrypto/arch/i386/crypto_arch.h
+++ b/src/lib/libcrypto/arch/i386/crypto_arch.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: crypto_arch.h,v 1.2 2024/10/18 14:44:02 jsing Exp $ */ 1/* $OpenBSD: crypto_arch.h,v 1.3 2024/10/19 13:06:11 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2024 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -19,6 +19,7 @@
19#define HEADER_CRYPTO_ARCH_H 19#define HEADER_CRYPTO_ARCH_H
20 20
21#define HAVE_CRYPTO_CPU_CAPS_INIT 21#define HAVE_CRYPTO_CPU_CAPS_INIT
22#define HAVE_CRYPTO_CPU_CAPS_IA32
22 23
23#ifndef OPENSSL_NO_ASM 24#ifndef OPENSSL_NO_ASM
24 25
diff --git a/src/lib/libcrypto/arch/i386/crypto_cpu_caps.c b/src/lib/libcrypto/arch/i386/crypto_cpu_caps.c
index e5b36a15cc..b0da0d636c 100644
--- a/src/lib/libcrypto/arch/i386/crypto_cpu_caps.c
+++ b/src/lib/libcrypto/arch/i386/crypto_cpu_caps.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: crypto_cpu_caps.c,v 1.1 2024/10/18 14:44:02 jsing Exp $ */ 1/* $OpenBSD: crypto_cpu_caps.c,v 1.2 2024/10/19 13:06:11 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2024 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -22,7 +22,7 @@
22#include "x86_arch.h" 22#include "x86_arch.h"
23 23
24/* Legacy architecture specific capabilities, used by perlasm. */ 24/* Legacy architecture specific capabilities, used by perlasm. */
25extern uint64_t OPENSSL_ia32cap_P; 25uint64_t OPENSSL_ia32cap_P;
26 26
27/* Machine independent CPU capabilities. */ 27/* Machine independent CPU capabilities. */
28extern uint64_t crypto_cpu_caps; 28extern uint64_t crypto_cpu_caps;
@@ -112,3 +112,9 @@ crypto_cpu_caps_init(void)
112 112
113 OPENSSL_ia32cap_P = caps; 113 OPENSSL_ia32cap_P = caps;
114} 114}
115
116uint64_t
117crypto_cpu_caps_ia32(void)
118{
119 return OPENSSL_ia32cap_P;
120}
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c
index 60f14eba12..8cb05e8cbf 100644
--- a/src/lib/libcrypto/cryptlib.c
+++ b/src/lib/libcrypto/cryptlib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cryptlib.c,v 1.56 2024/10/17 14:27:57 jsing Exp $ */ 1/* $OpenBSD: cryptlib.c,v 1.57 2024/10/19 13:06:11 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 *
@@ -330,40 +330,6 @@ CRYPTO_THREADID_hash(const CRYPTO_THREADID *id)
330 return id->val; 330 return id->val;
331} 331}
332 332
333#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
334 defined(__INTEL__) || \
335 defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
336
337uint64_t OPENSSL_ia32cap_P;
338
339uint64_t
340crypto_cpu_caps_ia32(void)
341{
342 return OPENSSL_ia32cap_P;
343}
344
345#if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM)
346#define OPENSSL_CPUID_SETUP
347void
348OPENSSL_cpuid_setup(void)
349{
350 uint64_t OPENSSL_ia32_cpuid(void);
351
352 OPENSSL_ia32cap_P = OPENSSL_ia32_cpuid();
353
354 if ((OPENSSL_ia32cap_P & CPUCAP_MASK_AESNI) != 0)
355 crypto_cpu_caps |= CRYPTO_CPU_CAPS_ACCELERATED_AES;
356}
357#endif
358
359#else
360uint64_t
361crypto_cpu_caps_ia32(void)
362{
363 return 0;
364}
365#endif
366
367#if !defined(OPENSSL_CPUID_SETUP) && !defined(OPENSSL_CPUID_OBJ) 333#if !defined(OPENSSL_CPUID_SETUP) && !defined(OPENSSL_CPUID_OBJ)
368void 334void
369OPENSSL_cpuid_setup(void) 335OPENSSL_cpuid_setup(void)
@@ -379,6 +345,14 @@ crypto_cpu_caps_init(void)
379} 345}
380#endif 346#endif
381 347
348#ifndef HAVE_CRYPTO_CPU_CAPS_IA32
349uint64_t
350crypto_cpu_caps_ia32(void)
351{
352 return 0;
353}
354#endif
355
382uint64_t 356uint64_t
383OPENSSL_cpu_caps(void) 357OPENSSL_cpu_caps(void)
384{ 358{