1 // Copyright 2022 The BoringSSL Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "internal.h"
16
17 #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM) && \
18 defined(OPENSSL_FREEBSD) && !defined(OPENSSL_STATIC_ARMCAP)
19 #include <sys/auxv.h>
20 #include <sys/types.h>
21
22 #include <openssl/mem.h>
23
24
OPENSSL_cpuid_setup(void)25 void OPENSSL_cpuid_setup(void) {
26 unsigned long hwcap = 0, hwcap2 = 0;
27
28 // |elf_aux_info| may fail, in which case |hwcap| and |hwcap2| will be
29 // left at zero. The rest of this function will then gracefully report
30 // the features are absent.
31 elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
32 elf_aux_info(AT_HWCAP2, &hwcap2, sizeof(hwcap2));
33
34 // Matching OpenSSL, only report other features if NEON is present.
35 if (hwcap & HWCAP_NEON) {
36 OPENSSL_armcap_P |= ARMV7_NEON;
37
38 if (hwcap2 & HWCAP2_AES) {
39 OPENSSL_armcap_P |= ARMV8_AES;
40 }
41 if (hwcap2 & HWCAP2_PMULL) {
42 OPENSSL_armcap_P |= ARMV8_PMULL;
43 }
44 if (hwcap2 & HWCAP2_SHA1) {
45 OPENSSL_armcap_P |= ARMV8_SHA1;
46 }
47 if (hwcap2 & HWCAP2_SHA2) {
48 OPENSSL_armcap_P |= ARMV8_SHA256;
49 }
50 }
51 }
52
53 #endif // OPENSSL_ARM && OPENSSL_OPENBSD && !OPENSSL_STATIC_ARMCAP
54