/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2020 The FreeBSD Foundation4*5* This software was developed by Mitchell Horne <[email protected]>6* under sponsorship from the FreeBSD Foundation.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions10* are met:11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE21* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT25* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY26* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF27* SUCH DAMAGE.28*/2930#include <sys/types.h>3132#include <machine/elf.h>33#include <machine/md_var.h>3435#include <crypto/openssl/ossl.h>36#include <crypto/openssl/ossl_cipher.h>37#include <crypto/openssl/arm_arch.h>3839/*40* Feature bits defined in arm_arch.h41*/42unsigned int OPENSSL_armcap_P;4344ossl_cipher_setkey_t aes_v8_set_encrypt_key;45ossl_cipher_setkey_t aes_v8_set_decrypt_key;4647ossl_cipher_setkey_t vpaes_set_encrypt_key;48ossl_cipher_setkey_t vpaes_set_decrypt_key;4950void51ossl_cpuid(struct ossl_softc *sc)52{53/* SHA features */54if ((elf_hwcap & HWCAP_SHA1) != 0)55OPENSSL_armcap_P |= ARMV8_SHA1;56if ((elf_hwcap & HWCAP_SHA2) != 0)57OPENSSL_armcap_P |= ARMV8_SHA256;58if ((elf_hwcap & HWCAP_SHA512) != 0)59OPENSSL_armcap_P |= ARMV8_SHA512;6061/* AES features */62if ((elf_hwcap & HWCAP_AES) != 0)63OPENSSL_armcap_P |= ARMV8_AES;64if ((elf_hwcap & HWCAP_PMULL) != 0)65OPENSSL_armcap_P |= ARMV8_PMULL;6667if ((OPENSSL_armcap_P & ARMV8_AES) == 0 &&68(OPENSSL_armcap_P & ARMV7_NEON) == 0) {69sc->has_aes = false;70return;71}72sc->has_aes = true;73if (OPENSSL_armcap_P & ARMV8_AES) {74ossl_cipher_aes_cbc.set_encrypt_key = aes_v8_set_encrypt_key;75ossl_cipher_aes_cbc.set_decrypt_key = aes_v8_set_decrypt_key;76} else {77ossl_cipher_aes_cbc.set_encrypt_key = vpaes_set_encrypt_key;78ossl_cipher_aes_cbc.set_decrypt_key = vpaes_set_decrypt_key;79}80}818283