xref: /freebsd/sys/crypto/openssl/ossl_arm.c (revision 44f8e1e8530e1d2e95e84bbbe3d22ac9cb2557fe)
1*44f8e1e8SMark Johnston /*-
2*44f8e1e8SMark Johnston  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*44f8e1e8SMark Johnston  *
4*44f8e1e8SMark Johnston  * Copyright (c) 2023 Stormshield
5*44f8e1e8SMark Johnston  * Copyright (c) 2023 Semihalf
6*44f8e1e8SMark Johnston  *
7*44f8e1e8SMark Johnston  * Redistribution and use in source and binary forms, with or without
8*44f8e1e8SMark Johnston  * modification, are permitted provided that the following conditions
9*44f8e1e8SMark Johnston  * are met:
10*44f8e1e8SMark Johnston  * 1. Redistributions of source code must retain the above copyright
11*44f8e1e8SMark Johnston  *    notice, this list of conditions and the following disclaimer,
12*44f8e1e8SMark Johnston  *    without modification.
13*44f8e1e8SMark Johnston  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14*44f8e1e8SMark Johnston  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
15*44f8e1e8SMark Johnston  *    redistribution must be conditioned upon including a substantially
16*44f8e1e8SMark Johnston  *    similar Disclaimer requirement for further binary redistribution.
17*44f8e1e8SMark Johnston  *
18*44f8e1e8SMark Johnston  * NO WARRANTY
19*44f8e1e8SMark Johnston  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20*44f8e1e8SMark Johnston  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21*44f8e1e8SMark Johnston  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
22*44f8e1e8SMark Johnston  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23*44f8e1e8SMark Johnston  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
24*44f8e1e8SMark Johnston  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*44f8e1e8SMark Johnston  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*44f8e1e8SMark Johnston  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27*44f8e1e8SMark Johnston  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*44f8e1e8SMark Johnston  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29*44f8e1e8SMark Johnston  * THE POSSIBILITY OF SUCH DAMAGES.
30*44f8e1e8SMark Johnston  */
31*44f8e1e8SMark Johnston 
32*44f8e1e8SMark Johnston #include <sys/cdefs.h>
33*44f8e1e8SMark Johnston __FBSDID("$FreeBSD$");
34*44f8e1e8SMark Johnston 
35*44f8e1e8SMark Johnston #include <sys/param.h>
36*44f8e1e8SMark Johnston 
37*44f8e1e8SMark Johnston #include <machine/elf.h>
38*44f8e1e8SMark Johnston #include <machine/md_var.h>
39*44f8e1e8SMark Johnston 
40*44f8e1e8SMark Johnston #include <crypto/openssl/ossl.h>
41*44f8e1e8SMark Johnston #include <crypto/openssl/ossl_cipher.h>
42*44f8e1e8SMark Johnston #include <crypto/openssl/arm/arm_arch.h>
43*44f8e1e8SMark Johnston 
44*44f8e1e8SMark Johnston ossl_cipher_setkey_t AES_set_encrypt_key;
45*44f8e1e8SMark Johnston ossl_cipher_setkey_t AES_set_decrypt_key;
46*44f8e1e8SMark Johnston 
47*44f8e1e8SMark Johnston unsigned int OPENSSL_armcap_P;
48*44f8e1e8SMark Johnston 
49*44f8e1e8SMark Johnston void
50*44f8e1e8SMark Johnston ossl_cpuid(struct ossl_softc *sc)
51*44f8e1e8SMark Johnston {
52*44f8e1e8SMark Johnston 	if (elf_hwcap & HWCAP_NEON) {
53*44f8e1e8SMark Johnston 		OPENSSL_armcap_P |= ARMV7_NEON;
54*44f8e1e8SMark Johnston 
55*44f8e1e8SMark Johnston 		sc->has_aes = true;
56*44f8e1e8SMark Johnston 		ossl_cipher_aes_cbc.set_encrypt_key = AES_set_encrypt_key;
57*44f8e1e8SMark Johnston 		ossl_cipher_aes_cbc.set_decrypt_key = AES_set_decrypt_key;
58*44f8e1e8SMark Johnston 	}
59*44f8e1e8SMark Johnston }
60