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