1 /* Copyright (c) 2022, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15 #include "internal.h"
16
17 #if defined(OPENSSL_ARM) && defined(OPENSSL_FREEBSD) && \
18 !defined(OPENSSL_STATIC_ARMCAP)
19 #include <sys/auxv.h>
20 #include <sys/types.h>
21
22 #include <openssl/arm_arch.h>
23 #include <openssl/mem.h>
24
25
OPENSSL_cpuid_setup(void)26 void OPENSSL_cpuid_setup(void) {
27 unsigned long hwcap = 0, hwcap2 = 0;
28
29 // |elf_aux_info| may fail, in which case |hwcap| and |hwcap2| will be
30 // left at zero. The rest of this function will then gracefully report
31 // the features are absent.
32 elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
33 elf_aux_info(AT_HWCAP2, &hwcap2, sizeof(hwcap2));
34
35 // Matching OpenSSL, only report other features if NEON is present.
36 if (hwcap & HWCAP_NEON) {
37 OPENSSL_armcap_P |= ARMV7_NEON;
38
39 if (hwcap2 & HWCAP2_AES) {
40 OPENSSL_armcap_P |= ARMV8_AES;
41 }
42 if (hwcap2 & HWCAP2_PMULL) {
43 OPENSSL_armcap_P |= ARMV8_PMULL;
44 }
45 if (hwcap2 & HWCAP2_SHA1) {
46 OPENSSL_armcap_P |= ARMV8_SHA1;
47 }
48 if (hwcap2 & HWCAP2_SHA2) {
49 OPENSSL_armcap_P |= ARMV8_SHA256;
50 }
51 }
52 }
53
54 #endif // OPENSSL_ARM && OPENSSL_OPENBSD && !OPENSSL_STATIC_ARMCAP
55