Commit Graph

353 Commits

Author SHA1 Message Date
Shawn Anastasio
3465f14dac ossl: Add support for powerpc64/powerpc64le
Summary:
Add support for building ossl(4) on powerpc64* by implementing ossl_cpuid and
other support functions for powerpc. The required assembly files for ppc were
already present in-tree.

Test Plan: The changes were tested using the in-tree tools/tools/crypto/cryptocheck.c tool on both powerpc64 and powerpc64le on a POWER9 system.

Reviewed by:	#powerpc, jhibbits, jhb
Differential Revision: https://reviews.freebsd.org/D41837
2024-06-21 03:29:04 -04:00
Mark Johnston
131c8ee733 padlock: Use device_set_descf()
No functional change intended.

MFC after:	1 week
2024-06-16 16:37:26 -04:00
Mark Johnston
0eea265a58 ossl: Remove a stray __FBSDID("$FreeBSD$")
Fixes:	44f8e1e853 ("ossl: Add support for armv7")
2023-12-04 12:29:30 -05:00
Mark Johnston
e655cc70df ossl: Move arm_arch.h to a common subdirectory
OpenSSL itself keeps only a single copy of this header.  Do the same in
sys/crypto/openssl to avoid the extra maintenance burden.  This requires
adjusting the include paths for generated asm files.

No functional change intended.

Reported by:	jrtc27
Reviewed by:	jhb
MFC after:	3 months
Differential Revision:	https://reviews.freebsd.org/D42866
2023-12-04 12:29:11 -05:00
Mark Johnston
629a72376d ossl: Add AES-GCM support for NEON-enabled armv7
This provides substantially higher throughput than the fallback
implementation.

Reviewed by:	jhb
MFC after:	3 months
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D41305
2023-11-30 12:49:48 -05:00
Mark Johnston
44f8e1e853 ossl: Add support for armv7
OpenSSL provides implementations of several AES modes which use
bitslicing and can be accelerated on CPUs which support the NEON
extension.  This patch adds arm platform support to ossl(4) and provides
an AES-CBC implementation, though bsaes_cbc_encrypt() only implements
decryption.  The real goal is to provide an accelerated AES-GCM
implementation; this will be added in a subsequent patch.

Initially derived from https://reviews.freebsd.org/D37420.

Reviewed by:	jhb
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
MFC after:	3 months
Differential Revision:	https://reviews.freebsd.org/D41304
2023-11-30 12:49:47 -05:00
Mark Johnston
47d767dab5 ossl: Fix some bugs in the fallback AES-GCM implementation
gcm_*_aesni() are used when the AVX512 implementation is not available.
Fix two bugs which manifest when handling operations spanning multiple
segments:
- Avoid underflow when the length of the input is smaller than the
  residual.
- In gcm_decrypt_aesni(), ensure that we begin the operation at the
  right offset into the input and output buffers.

Reviewed by:	jhb
Fixes:		9b1d87286c ("ossl: Add a fallback AES-GCM implementation using AES-NI")
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D42838
2023-11-30 12:49:47 -05:00
Mark Johnston
5c0dac0b7a ossl: Keep mutable AES-GCM state on the stack
ossl(4)'s AES-GCM implementation keeps mutable state in the session
structure, together with the key schedule.  This was done for
convenience, as both are initialized together.  However, some OCF
consumers, particularly ZFS, assume that requests may be dispatched to
the same session in parallel.  Without serialization, this results in
incorrect output.

Fix the problem by explicitly copying per-session state onto the stack
at the beginning of each operation.

PR:		275306
Reviewed by:	jhb
Fixes:		9a3444d91c ("ossl: Add a VAES-based AES-GCM implementation for amd64")
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D42783
2023-11-29 12:55:51 -05:00
Mark Johnston
87826c87c6 ossl: Fix handling of separate AAD buffers in ossl_aes_gcm()
Consumers may optionally provide a reference to a separate buffer
containing AAD, but ossl_aes_gcm() didn't handle this and would thus
compute an incorrect digest.

Fixes:		9a3444d91c ("ossl: Add a VAES-based AES-GCM implementation for amd64")
Reviewed by:	jhb
MFC after:	3 days
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D42736
2023-11-28 14:35:49 -05:00
Warner Losh
fdafd315ad sys: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:00 -07:00
Ed Maste
575878a533 OpenSSL: regenerate asm files for 3.0.12
Fixes: ad991e4c14 ("OpenSSL: update to 3.0.12")
Sponsored by:	The FreeBSD Foundation
2023-10-25 13:29:35 -04:00
Andrew Turner
bd9588bca0 ossl: Rebuild the openssl asm
This adds the new BTI instructions when needed to the arm64 assembly.

Sponsored by:	Arm Ltd

Reviewed by:	Pierre Pronchery <pierre@freebsdfoundation.org> (earlier version)
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D41941
2023-10-02 17:12:50 +01:00
Andrew Turner
2f198d313b ossl: Update arm_arch.h from OpenSSL 1.1.1 to 3.0
Reviewed by:	emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D41939
2023-09-22 18:15:14 +01:00
Zachary Leaf
565c887a77 armv8_crypto: fix recursive fpu_kern_enter call
Now armv8_crypto is using FPU_KERN_NOCTX, this results in a kernel panic
in armv8_crypto.c:armv8_crypto_cipher_setup:

    panic: recursive fpu_kern_enter while in PCB_FP_NOSAVE state

This is because in armv8_crypto.c:armv8_crypto_cipher_process,
directly after calling fpu_kern_enter() a call is made to
armv8_crypto_cipher_setup(), resulting in nested calls to
fpu_kern_enter() without the required fpu_kern_leave() in between.

Move fpu_kern_enter() in armv8_crypto_cipher_process() after the
call to armv8_crypto_cipher_setup() to resolve this.

Reviewed by:	markj, andrew
Fixes: 6485286f53 ("armv8_crypto: Switch to using FPU_KERN_NOCTX")
Sponsored by: Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D41671
2023-09-01 10:56:58 +01:00
John Baldwin
c0855eaa3e ossl: Update the generated assembly files from OpenSSL 3.0.
Tested with:	cryptocheck -d ossl0 -a all -z on amd64
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D41568
2023-08-29 14:44:15 -07:00
Mark Johnston
6b635c74fd aesni: Push FPU sections down further
After commit 937b4473be aesni_cipher_crypt() and aesni_cipher_mac()
execute in a FPU_KERN_NOCTX section, which means that they must run with
preemption disabled.  These functions handle discontiguous I/O buffers
by allocating a contiguous buffer and copying as necessary, but this
allocation cannot happen with preemption disabled.  Fix the problem by
pushing the FPU section down into aesni_cipher_crypt() and
aesni_cipher_mac().  In particular, encrypt-then-auth transforms need
not be handled with a single FPU section.

Reported by:	syzbot+78258dbb02eb92157357@syzkaller.appspotmail.com
Discussed with:	jhb
Fixes:		937b4473be ("aesni: Switch to using FPU_KERN_NOCTX.")
2023-08-28 21:26:53 -04:00
John Baldwin
79aeecc89f blake2: Remove dieing flag and rw lock
crypto_unregister_all already disables new sessions and waits for
existing sessions to be destroyed before returning.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D41581
2023-08-28 16:24:42 -07:00
John Baldwin
3e912bdc31 blake2: Switch to using FPU_KERN_NOCTX
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D41580
2023-08-28 16:24:32 -07:00
John Baldwin
fdd51760c2 armv8_crypto: Remove dieing flag and rw lock
crypto_unregister_all already disables new sessions and waits for
existing sessions to be destroyed before returning.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D41579
2023-08-28 16:23:43 -07:00
John Baldwin
6485286f53 armv8_crypto: Switch to using FPU_KERN_NOCTX
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D41578
2023-08-28 16:22:33 -07:00
John Baldwin
937b4473be aesni: Switch to using FPU_KERN_NOCTX.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D41577
2023-08-28 16:22:15 -07:00
John Baldwin
3b0e353fe6 padlock: Switch to using FPU_KERN_NOCTX
Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D41582
2023-08-25 12:34:05 -07:00
Warner Losh
682d5a87e5 Delete trailing whitespace from $FreeBSD$ removal
Fixes: d4bf8003ee
Sponsored by: Netflix
2023-08-21 19:37:28 -06:00
Warner Losh
78d146160d sys: Remove $FreeBSD$: one-line bare tag
Remove /^\s*\$FreeBSD\$$\n/
2023-08-16 11:55:17 -06:00
Warner Losh
031beb4e23 sys: Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:58 -06:00
Warner Losh
d4bf8003ee sys: Remove $FreeBSD$: one-line .S pattern
Remove /^\s\.(asciz|ident)\s+\"\$FreeBSD\$\".*\n/
2023-08-16 11:54:54 -06:00
Warner Losh
685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh
71625ec9ad sys: Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:24 -06:00
Warner Losh
95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Mark Johnston
454c425dbe ossl: Add missing labels to bsaes-armv7.S
There is a bug in the OpenSSL script which generates this file; the bug
is in the process of being fixed upstream.

Specifically, when generating the output, bsaes-armv7.pl strips some
labels that are used when the output asm is compiled with __KERNEL__
defined, resulting in a build error.  As a step towards adding armv7
support to ossl(4), manually patch the generated asm.  The upstream fix
will be imported later.

Reviewed by:	andrew, jhb, emaste
MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D41303
2023-08-07 10:17:16 -04:00
John Baldwin
474d9290eb ossl: Don't try to initialize the cipher for Chacha20+Poly1305.
Chacha20+Poly1305 doesn't use an ossl_cipher instance the way AES-GCM
does, so ossl_lookup_cipher() failed causing ossl_newsession() to
always fail for Chacha20+Poly1305 sessions.

Reported by:	gallatin (ktls_test fails with ossl.ko loaded)
Fixes:		9a3444d91c ossl: Add a VAES-based AES-GCM implementation for amd64
Tested by:	gallatin
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D40580
2023-06-20 07:53:50 -07:00
Mark Johnston
9d5a47e13c ossl: Provide a fallback definition of __uint128_t when needed
This is required on i386.  The patch has no functional change, since
AES-GCM isn't implemented for that platform.

Fixes:	9a3444d91c ("ossl: Add a VAES-based AES-GCM implementation for amd64")
Reported by:	Jenkins
2023-06-04 12:39:44 -04:00
Mark Johnston
9b1d87286c ossl: Add a fallback AES-GCM implementation using AES-NI
This lets one use ossl(4) for AES-GCM operations on contemporary amd64
platforms.  A kernel benchmark indicates that this gives roughly
equivalent throughput to aesni(4) for various buffer sizes.

Bulk processing is done in aesni-gcm-x86_64.S, the rest is handled in a
C wrapper ported from OpenSSL's gcm128.c.

Sponsored by:	Stormshield
Sponsored by:	Klara, Inc.
Reviewed by:	jhb
MFC after:	3 months
Differential Revision:	https://reviews.freebsd.org/D39967
2023-06-02 12:17:11 -04:00
Mark Johnston
9a3444d91c ossl: Add a VAES-based AES-GCM implementation for amd64
aes-gcm-avx512.S is generated from OpenSSL 3.1 and implements AES-GCM.
ossl_x86.c detects whether the CPU implements the required AVX512
instructions; if not, the ossl(4) module does not provide an AES-GCM
implementation.  The VAES implementation increases throughput for all
buffer sizes in both directions, up to 2x for sufficiently large
buffers.

The "process" implementation is in two parts: a generic OCF layer in
ossl_aes.c that calls a set of MD functions to do the heavy lifting.
The intent there is to make it possible to add other implementations for
other platforms, e.g., to reduce the diff required for D37421.

A follow-up commit will add a fallback path to legacy AES-NI, so that
ossl(4) can be used in preference to aesni(4) on all amd64 platforms.
In the long term we would like to replace aesni(4) and armv8crypto(4)
with ossl(4).

Note, currently this implementation will not be selected by default
since aesni(4) and ossl(4) return the same probe priority for crypto
sessions, and the opencrypto framework selects the first registered
implementation to break a tie.  Since aesni(4) is compiled into the
kernel, aesni(4) wins.  A separate change may modify ossl(4) to have
priority.

Sponsored by:	Stormshield
Sponsored by:	Klara, Inc.
Reviewed by:	jhb
MFC after:	3 months
Differential Revision:	https://reviews.freebsd.org/D39783
2023-06-02 12:15:01 -04:00
Mark Johnston
9ad8dc721e ossl: Expose more CPUID bits in OPENSSL_ia32cap_P
This is needed to let OpenSSL 3.1 routines detect VAES and VPCLMULQDQ
extensions.  The intent is to import ASM routines which implement
AES-GCM using VEX-prefixed AES-NI instructions.

No functional change intended.

Sponsored by:	Stormshield
Sponsored by:	Klara, Inc.
MFC after:	3 months
Differential Revision:	https://reviews.freebsd.org/D39782
2023-06-02 12:15:01 -04:00
Warner Losh
4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Jung-uk Kim
e415d255a6 OpenSSL: Regen an assembly file for arm
X-MFC with:	af19988f6c
2023-03-21 15:13:51 -04:00
Jung-uk Kim
f1cf49002d OpenSSL: Regen assembly files for OpenSSL 1.1.1t 2023-02-07 13:55:17 -05:00
John Baldwin
70efe1a2fe ccr,ccp: Fix argument order to sglist_append_vmpages.
The offset comes before the byte count.

Reported by:	br
Reviewed by:	asomers, markj
MFC after:	1 week
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D38375
2023-02-06 13:51:57 -08:00
Sebastian Huber
6680cfe8e0 sha512_224: Fix SHA512_224_Final() on little-endian machines.
PR:		266863
MFC after:	1 week
Reviewed by:	allanjude, cperciva, des
Differential Revision:	https://reviews.freebsd.org/D38372
2023-02-06 18:02:49 +01:00
John Baldwin
d256a06fe8 aesni: Remove misleading array bounds for aesni_decryt_ecb.
All the other functions used pointers for from/to instead of
fixed-size array parameters.  More importantly, this function can
accept pointers to buffers of multiple blocks, not just a single
block.

Reported by:	GCC -Warray-parameter
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D37547
2022-12-07 12:32:19 -08:00
Jung-uk Kim
f443d0802a OpenSSL: Regen assembly file for OpenSSSL 1.1.1s 2022-11-01 19:12:09 -04:00
Andrew Turner
7c4cfece6b Fix the IV length in the armv8 AES GCM code
Reviewed by:	cem, delphij
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36403
2022-09-06 13:11:04 +01:00
Warner Losh
414924d921 skein: Update guard define check
OpenZFS changed the define _OPENSOLARIS_SYS_TYPES_H_ to
_SPL_SYS_TYPES_H_ to guard the sys/types.h compatibility file
inclusion. Follow the change here. The only place in the tree
_OPENSOLARIS_SYS_TYPES_H_ is mentioned is in the /*
_OPENSOLARIS_SYS_TYPES_H_ */ at the end of sys/types.h. That needs to be
changed upstream in OpenZFS since we don't like changing things in
FreeBSD's tree.

Sponsored by:		Netflix
Reviewed by:		tsoome, delphij
Differential Revision:	https://reviews.freebsd.org/D35891
2022-07-24 16:53:35 -06:00
Jung-uk Kim
9576bca583 OpenSSL: Regen assembly file for OpenSSSL 1.1.1q 2022-07-05 12:06:50 -04:00
Jung-uk Kim
ec4d9b059e OpenSSL: Regen assembly file for OpenSSSL 1.1.1p 2022-06-21 14:20:33 -04:00
John Baldwin
ab050b2b8f crypto: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-06 15:46:58 -07:00
John Baldwin
907f35efff ccp: Use devclass_find to lookup devclass in db_show_ccp.
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D35003
2022-04-21 10:29:14 -07:00
John Baldwin
56f5947a71 Remove checks for __GNUCLIKE_ASM assuming it is always true.
All supported compilers (modern versions of GCC and clang) support
this.

Many places didn't have an #else so would just silently do the wrong
thing.  Ancient versions of icc (the original motivation for this) are
no longer a compiler FreeBSD supports.

PR:		263102 (exp-run)
Reviewed by:	brooks, imp
Differential Revision:	https://reviews.freebsd.org/D34797
2022-04-12 10:05:45 -07:00
Mark Johnston
c89def05b5 armv8crypto: Remove leftover debug printfs
Fixes:	26b08c5d21 ("armv8crypto: Use cursors to access crypto buffer data")
Reported by:	bz
2022-02-17 14:25:45 -05:00