Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/fipsmodule/cpucap/cpucap.c

raw
1 // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2 // SPDX-License-Identifier: Apache-2.0 OR ISC
3
4 // The contents of this file were copied from crypto/crypto.c to this file
5 // as part of the change that moves the CPU capability logic inside the FIPS
6 // module to satisfy the FIPS requirements.
7
8 #include <openssl/cpu.h>
9
10 // Our assembly does not use the GOT to reference symbols, which means
11 // references to visible symbols will often require a TEXTREL. This is
12 // undesirable, so all assembly-referenced symbols should be hidden. CPU
13 // capabilities are the only such symbols defined in C. Explicitly hide them,
14 // rather than rely on being built with -fvisibility=hidden.
15 #if defined(OPENSSL_WINDOWS)
16 #define HIDDEN
17 #else
18 #define HIDDEN __attribute__((visibility("hidden")))
19 #endif
20
21 #if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
22
23 // This value must be explicitly initialised to zero in order to work around a
24 // bug in libtool or the linker on OS X.
25 //
26 // If not initialised then it becomes a "common symbol". When put into an
27 // archive, linking on OS X will fail to resolve common symbols. By
28 // initialising it to zero, it becomes a "data symbol", which isn't so
29 // affected.
30 HIDDEN uint32_t OPENSSL_ia32cap_P[4] = {0};
31
32 #elif defined(OPENSSL_PPC64LE)
33
34 HIDDEN unsigned long OPENSSL_ppc64le_hwcap2 = 0;
35
36 #elif defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
37
38 #include <openssl/arm_arch.h>
39
40 #if defined(OPENSSL_STATIC_ARMCAP)
41
42 // See ARM ACLE for the definitions of these macros. Note |__ARM_FEATURE_AES|
43 // covers both AES and PMULL and |__ARM_FEATURE_SHA2| covers SHA-1 and SHA-256.
44 // https://developer.arm.com/architectures/system-architectures/software-standards/acle
45 // https://github.com/ARM-software/acle/issues/152
46 //
47 // TODO(davidben): Do we still need |OPENSSL_STATIC_ARMCAP_*| or are the
48 // standard flags and -march sufficient?
49 HIDDEN uint32_t OPENSSL_armcap_P =
50 #if defined(OPENSSL_STATIC_ARMCAP_NEON) || defined(__ARM_NEON)
51 ARMV7_NEON |
52 #endif
53 #if defined(OPENSSL_STATIC_ARMCAP_AES) || defined(__ARM_FEATURE_AES)
54 ARMV8_AES |
55 #endif
56 #if defined(OPENSSL_STATIC_ARMCAP_PMULL) || defined(__ARM_FEATURE_AES)
57 ARMV8_PMULL |
58 #endif
59 #if defined(OPENSSL_STATIC_ARMCAP_SHA1) || defined(__ARM_FEATURE_SHA2)
60 ARMV8_SHA1 |
61 #endif
62 #if defined(OPENSSL_STATIC_ARMCAP_SHA256) || defined(__ARM_FEATURE_SHA2)
63 ARMV8_SHA256 |
64 #endif
65 #if defined(OPENSSL_STATIC_ARMCAP_SHA512) || defined(__ARM_FEATURE_SHA512)
66 ARMV8_SHA512 |
67 #endif
68 #if defined(OPENSSL_STATIC_ARMCAP_SHA3) || defined(__ARM_FEATURE_SHA3)
69 ARMV8_SHA3 |
70 #endif
71 #if defined(OPENSSL_STATIC_ARMCAP_NEOVERSE_N1) || defined(__ARM_FEATURE_NEOVERSE_N1)
72 ARMV8_NEOVERSE_N1 |
73 #endif
74 #if defined(OPENSSL_STATIC_ARMCAP_NEOVERSE_V1) || defined(__ARM_FEATURE_NEOVERSE_V1)
75 ARMV8_NEOVERSE_V1 |
76 #endif
77 #if defined(OPENSSL_STATIC_ARMCAP_NEOVERSE_V2) || defined(__ARM_FEATURE_NEOVERSE_V2)
78 ARMV8_NEOVERSE_V2 |
79 #endif
80 0;
81
82 #else
83 HIDDEN uint32_t OPENSSL_armcap_P = 0;
84 #endif
85
86 #endif
87
88 #if defined(BORINGSSL_DISPATCH_TEST)
89 // This value must be explicitly initialized to zero. See similar comment above.
90 HIDDEN uint8_t BORINGSSL_function_hit[15] = {0};
91 #endif // BORINGSSL_DISPATCH_TEST
92
93 // This variable is used only for testing purposes to ensure that the library
94 // constructor is executed and the capability variable is initialized.
95 HIDDEN uint8_t OPENSSL_cpucap_initialized = 0;