144f8e1e8SMark Johnston /*- 244f8e1e8SMark Johnston * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 344f8e1e8SMark Johnston * 444f8e1e8SMark Johnston * Copyright (c) 2023 Stormshield 544f8e1e8SMark Johnston * Copyright (c) 2023 Semihalf 644f8e1e8SMark Johnston * 744f8e1e8SMark Johnston * Redistribution and use in source and binary forms, with or without 844f8e1e8SMark Johnston * modification, are permitted provided that the following conditions 944f8e1e8SMark Johnston * are met: 1044f8e1e8SMark Johnston * 1. Redistributions of source code must retain the above copyright 1144f8e1e8SMark Johnston * notice, this list of conditions and the following disclaimer, 1244f8e1e8SMark Johnston * without modification. 1344f8e1e8SMark Johnston * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1444f8e1e8SMark Johnston * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 1544f8e1e8SMark Johnston * redistribution must be conditioned upon including a substantially 1644f8e1e8SMark Johnston * similar Disclaimer requirement for further binary redistribution. 1744f8e1e8SMark Johnston * 1844f8e1e8SMark Johnston * NO WARRANTY 1944f8e1e8SMark Johnston * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2044f8e1e8SMark Johnston * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2144f8e1e8SMark Johnston * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 2244f8e1e8SMark Johnston * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 2344f8e1e8SMark Johnston * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 2444f8e1e8SMark Johnston * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2544f8e1e8SMark Johnston * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2644f8e1e8SMark Johnston * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 2744f8e1e8SMark Johnston * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2844f8e1e8SMark Johnston * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 2944f8e1e8SMark Johnston * THE POSSIBILITY OF SUCH DAMAGES. 3044f8e1e8SMark Johnston */ 3144f8e1e8SMark Johnston 3244f8e1e8SMark Johnston #include <sys/cdefs.h> 3344f8e1e8SMark Johnston __FBSDID("$FreeBSD$"); 3444f8e1e8SMark Johnston 3544f8e1e8SMark Johnston #include <sys/param.h> 3644f8e1e8SMark Johnston 3744f8e1e8SMark Johnston #include <machine/elf.h> 3844f8e1e8SMark Johnston #include <machine/md_var.h> 3944f8e1e8SMark Johnston 4044f8e1e8SMark Johnston #include <crypto/openssl/ossl.h> 4144f8e1e8SMark Johnston #include <crypto/openssl/ossl_cipher.h> 42*e655cc70SMark Johnston #include <crypto/openssl/arm_arch.h> 4344f8e1e8SMark Johnston 4444f8e1e8SMark Johnston ossl_cipher_setkey_t AES_set_encrypt_key; 4544f8e1e8SMark Johnston ossl_cipher_setkey_t AES_set_decrypt_key; 4644f8e1e8SMark Johnston 47629a7237SMark Johnston ossl_cipher_setkey_t ossl_aes_gcm_setkey; 48629a7237SMark Johnston 4944f8e1e8SMark Johnston unsigned int OPENSSL_armcap_P; 5044f8e1e8SMark Johnston 5144f8e1e8SMark Johnston void 5244f8e1e8SMark Johnston ossl_cpuid(struct ossl_softc *sc) 5344f8e1e8SMark Johnston { 5444f8e1e8SMark Johnston if (elf_hwcap & HWCAP_NEON) { 5544f8e1e8SMark Johnston OPENSSL_armcap_P |= ARMV7_NEON; 5644f8e1e8SMark Johnston 5744f8e1e8SMark Johnston sc->has_aes = true; 5844f8e1e8SMark Johnston ossl_cipher_aes_cbc.set_encrypt_key = AES_set_encrypt_key; 5944f8e1e8SMark Johnston ossl_cipher_aes_cbc.set_decrypt_key = AES_set_decrypt_key; 60629a7237SMark Johnston 61629a7237SMark Johnston sc->has_aes_gcm = true; 62629a7237SMark Johnston ossl_cipher_aes_gcm.set_encrypt_key = ossl_aes_gcm_setkey; 63629a7237SMark Johnston ossl_cipher_aes_gcm.set_decrypt_key = ossl_aes_gcm_setkey; 6444f8e1e8SMark Johnston } 6544f8e1e8SMark Johnston } 66