• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2016, 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 <openssl/cpu.h>
16 
17 #if defined(OPENSSL_AARCH64) && !defined(OPENSSL_STATIC_ARMCAP)
18 
19 #include <sys/auxv.h>
20 
21 #include <openssl/arm_arch.h>
22 
23 #include "internal.h"
24 
25 
26 extern uint32_t OPENSSL_armcap_P;
27 
OPENSSL_cpuid_setup(void)28 void OPENSSL_cpuid_setup(void) {
29   unsigned long hwcap = getauxval(AT_HWCAP);
30 
31   /* See /usr/include/asm/hwcap.h on an aarch64 installation for the source of
32    * these values. */
33   static const unsigned long kNEON = 1 << 1;
34   static const unsigned long kAES = 1 << 3;
35   static const unsigned long kPMULL = 1 << 4;
36   static const unsigned long kSHA1 = 1 << 5;
37   static const unsigned long kSHA256 = 1 << 6;
38 
39   if ((hwcap & kNEON) == 0) {
40     /* Matching OpenSSL, if NEON is missing, don't report other features
41      * either. */
42     return;
43   }
44 
45   OPENSSL_armcap_P |= ARMV7_NEON;
46 
47   if (hwcap & kAES) {
48     OPENSSL_armcap_P |= ARMV8_AES;
49   }
50   if (hwcap & kPMULL) {
51     OPENSSL_armcap_P |= ARMV8_PMULL;
52   }
53   if (hwcap & kSHA1) {
54     OPENSSL_armcap_P |= ARMV8_SHA1;
55   }
56   if (hwcap & kSHA256) {
57     OPENSSL_armcap_P |= ARMV8_SHA256;
58   }
59 }
60 
61 #endif /* OPENSSL_AARCH64 && !OPENSSL_STATIC_ARMCAP */
62