Index: share/man/man4/ossl.4 =================================================================== --- share/man/man4/ossl.4 +++ share/man/man4/ossl.4 @@ -26,12 +26,12 @@ .\" .\" $FreeBSD$ .\" -.Dd October 19, 2020 +.Dd November 26, 2020 .Dt OSSL 4 .Os .Sh NAME .Nm ossl -.Nd "driver using OpenSSL assembly routines on x86 CPUs" +.Nd "driver using OpenSSL assembly routines" .Sh SYNOPSIS To compile this driver into the kernel, place the following lines in your @@ -61,6 +61,8 @@ .Pp .Bl -bullet -compact .It +arm64 +.It amd64 .It i386 Index: sys/conf/files.arm64 =================================================================== --- sys/conf/files.arm64 +++ sys/conf/files.arm64 @@ -246,6 +246,17 @@ no-implicit-rule \ clean "armv8_crypto_wrap.o" crypto/des/des_enc.c optional netsmb +crypto/openssl/ossl.c optional ossl +crypto/openssl/ossl_sha1.c optional ossl +crypto/openssl/ossl_sha256.c optional ossl +crypto/openssl/ossl_sha512.c optional ossl +crypto/openssl/aarch64/ossl_cpuid.c optional ossl +crypto/openssl/aarch64/sha1-armv8.S optional ossl \ + compile-with "${CC} -c ${CFLAGS:N-mgeneral-regs-only} ${WERROR} ${PROF} ${.IMPSRC}" +crypto/openssl/aarch64/sha256-armv8.S optional ossl \ + compile-with "${CC} -c ${CFLAGS:N-mgeneral-regs-only} ${WERROR} ${PROF} ${.IMPSRC}" +crypto/openssl/aarch64/sha512-armv8.S optional ossl \ + compile-with "${CC} -c ${CFLAGS:N-mgeneral-regs-only} ${WERROR} ${PROF} ${.IMPSRC}" dev/acpica/acpi_bus_if.m optional acpi dev/acpica/acpi_if.m optional acpi dev/acpica/acpi_pci_link.c optional acpi pci Index: sys/crypto/openssl/aarch64/ossl_cpuid.c =================================================================== --- /dev/null +++ sys/crypto/openssl/aarch64/ossl_cpuid.c @@ -0,0 +1,67 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2020 The FreeBSD Foundation + * + * This software was developed by Mitchell Horne + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include + +#include +#include + +#include + +/* + * Feature bits defined in OpenSSL's arm_arch.h + */ +#define ARMV8_AES (1 << 2) +#define ARMV8_SHA1 (1 << 3) +#define ARMV8_SHA256 (1 << 4) +#define ARMV8_PMULL (1 << 5) +#define ARMV8_SHA512 (1 << 6) + +unsigned int OPENSSL_armcap_P; + +void +ossl_cpuid(void) +{ + /* SHA features */ + if ((elf_hwcap & HWCAP_SHA1) != 0) + OPENSSL_armcap_P |= ARMV8_AES; + if ((elf_hwcap & HWCAP_SHA2) != 0) + OPENSSL_armcap_P |= ARMV8_SHA256; + if ((elf_hwcap & HWCAP_SHA512) != 0) + OPENSSL_armcap_P |= ARMV8_SHA512; + + /* AES features */ + if ((elf_hwcap & HWCAP_AES) != 0) + OPENSSL_armcap_P |= ARMV8_AES; + if ((elf_hwcap & HWCAP_PMULL) != 0) + OPENSSL_armcap_P |= ARMV8_PMULL; +} Index: sys/modules/Makefile =================================================================== --- sys/modules/Makefile +++ sys/modules/Makefile @@ -630,7 +630,6 @@ _ndis= ndis _ntb= ntb _ocs_fc= ocs_fc -_ossl= ossl _pccard= pccard _qat= qat _qatfw= qatfw @@ -806,6 +805,11 @@ .endif +.if ${MACHINE_ARCH} == "aarch64" || ${MACHINE_ARCH} == "amd64" || \ + ${MACHINE_ARCH} == "i386" +_ossl= ossl +.endif + .if ${MACHINE_ARCH:Marmv[67]*} != "" || ${MACHINE_CPUARCH} == "aarch64" _bcm283x_clkman= bcm283x_clkman _bcm283x_pwm= bcm283x_pwm Index: sys/modules/ossl/Makefile =================================================================== --- sys/modules/ossl/Makefile +++ sys/modules/ossl/Makefile @@ -19,6 +19,15 @@ ossl_sha512.c \ ${SRCS.${MACHINE_CPUARCH}} +# For arm64, we are required to rewrite the compiler invocation to remove +# -mgeneral-regs-only. +OBJS+= sha1-armv8.o \ + sha256-armv8.o \ + sha512-armv8.o +${OBJS:Msha*-armv8.o}: ${.TARGET:R}.S + ${CC} -c ${CFLAGS:N-mgeneral-regs-only} ${WERROR} ${PROF} ${.IMPSRC} + ${CTFCONVERT_CMD} + SRCS.amd64= \ sha1-x86_64.S \ sha256-x86_64.S \