Module Name: src
Committed By: riastradh
Date: Tue Jun 30 20:32:11 UTC 2020
Modified Files:
src/distrib/sets/lists/debug: mi
src/distrib/sets/lists/tests: mi
src/etc/mtree: NetBSD.dist.tests
src/sys/crypto/aes: aes_bear.c aes_ct.c aes_selftest.c
src/sys/crypto/aes/arch/arm: aes_armv8.c aes_neon.c aes_neon_impl.c
aes_neon_subr.c
src/sys/crypto/aes/arch/x86: aes_ni.c aes_sse2.c aes_sse2_impl.c
aes_sse2_subr.c aes_ssse3.c aes_ssse3_impl.c aes_ssse3_subr.c
aes_via.c
src/tests/sys: Makefile
Added Files:
src/tests/sys/crypto: Makefile
src/tests/sys/crypto/aes: Makefile t_aes.c
Log Message:
New test sys/crypto/aes/t_aes.
Runs aes_selftest on all kernel AES implementations supported on the
current hardware, not just the preferred one.
To generate a diff of this commit:
cvs rdiff -u -r1.321 -r1.322 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.866 -r1.867 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.170 -r1.171 src/etc/mtree/NetBSD.dist.tests
cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/aes/aes_bear.c \
src/sys/crypto/aes/aes_selftest.c
cvs rdiff -u -r1.2 -r1.3 src/sys/crypto/aes/aes_ct.c
cvs rdiff -u -r1.2 -r1.3 src/sys/crypto/aes/arch/arm/aes_armv8.c \
src/sys/crypto/aes/arch/arm/aes_neon.c
cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/aes/arch/arm/aes_neon_impl.c \
src/sys/crypto/aes/arch/arm/aes_neon_subr.c
cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/aes/arch/x86/aes_ni.c \
src/sys/crypto/aes/arch/x86/aes_sse2.c \
src/sys/crypto/aes/arch/x86/aes_sse2_subr.c \
src/sys/crypto/aes/arch/x86/aes_ssse3.c \
src/sys/crypto/aes/arch/x86/aes_ssse3_impl.c \
src/sys/crypto/aes/arch/x86/aes_ssse3_subr.c
cvs rdiff -u -r1.2 -r1.3 src/sys/crypto/aes/arch/x86/aes_sse2_impl.c \
src/sys/crypto/aes/arch/x86/aes_via.c
cvs rdiff -u -r1.3 -r1.4 src/tests/sys/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/sys/crypto/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/sys/crypto/aes/Makefile \
src/tests/sys/crypto/aes/t_aes.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.321 src/distrib/sets/lists/debug/mi:1.322
--- src/distrib/sets/lists/debug/mi:1.321 Tue Jun 30 16:09:40 2020
+++ src/distrib/sets/lists/debug/mi Tue Jun 30 20:32:10 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.321 2020/06/30 16:09:40 jruoho Exp $
+# $NetBSD: mi,v 1.322 2020/06/30 20:32:10 riastradh Exp $
./etc/mtree/set.debug comp-sys-root
./usr/lib comp-sys-usr compatdir
./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib,compatfile
@@ -2408,6 +2408,9 @@
./usr/libdata/debug/usr/tests/rump/rumpvfs/t_etfs.debug tests-syscall-debug debug,atf,rump
./usr/libdata/debug/usr/tests/rump/rumpvfs/t_p2kifs.debug tests-syscall-debug debug,atf,rump
./usr/libdata/debug/usr/tests/sys tests-sys-debug debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/sys/crypto tests-sys-debug debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/sys/crypto/aes tests-sys-debug debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/sys/crypto/aes/t_aes.debug tests-sys-debug debug,atf,compattestfile
./usr/libdata/debug/usr/tests/sys/net tests-sys-debug debug,atf,compattestfile
./usr/libdata/debug/usr/tests/sys/net/t_print.debug tests-sys-debug debug,atf,compattestfile
./usr/libdata/debug/usr/tests/sys/netatalk tests-sys-debug debug,atf,compattestfile
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.866 src/distrib/sets/lists/tests/mi:1.867
--- src/distrib/sets/lists/tests/mi:1.866 Tue Jun 30 16:09:40 2020
+++ src/distrib/sets/lists/tests/mi Tue Jun 30 20:32:10 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.866 2020/06/30 16:09:40 jruoho Exp $
+# $NetBSD: mi,v 1.867 2020/06/30 20:32:10 riastradh Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -182,6 +182,8 @@
./usr/libdata/debug/usr/tests/sbin tests-sbin-tests compattestfile,atf
./usr/libdata/debug/usr/tests/sbin/resize_ffs tests-sbin-tests compattestfile,atf
./usr/libdata/debug/usr/tests/sys tests-sys-debug compattestfile,atf
+./usr/libdata/debug/usr/tests/sys/crypto tests-sys-debug compattestfile,atf
+./usr/libdata/debug/usr/tests/sys/crypto/aes tests-sys-debug compattestfile,atf
./usr/libdata/debug/usr/tests/sys/net tests-sys-debug compattestfile,atf
./usr/libdata/debug/usr/tests/sys/netatalk tests-sys-debug compattestfile,atf
./usr/libdata/debug/usr/tests/sys/netinet tests-sys-debug compattestfile,atf
@@ -4061,6 +4063,13 @@
./usr/tests/sys tests-sys-tests compattestfile,atf
./usr/tests/sys/Atffile tests-sys-tests compattestfile,atf
./usr/tests/sys/Kyuafile tests-sys-tests compattestfile,atf,kyua
+./usr/tests/sys/crypto tests-sys-tests compattestfile,atf
+./usr/tests/sys/crypto/Atffile tests-sys-tests compattestfile,atf
+./usr/tests/sys/crypto/Kyuafile tests-sys-tests compattestfile,atf,kyua
+./usr/tests/sys/crypto/aes tests-sys-tests compattestfile,atf
+./usr/tests/sys/crypto/aes/Atffile tests-sys-tests compattestfile,atf
+./usr/tests/sys/crypto/aes/Kyuafile tests-sys-tests compattestfile,atf,kyua
+./usr/tests/sys/crypto/aes/t_aes tests-sys-tests compattestfile,atf
./usr/tests/sys/net tests-sys-tests compattestfile,atf
./usr/tests/sys/net/Atffile tests-sys-tests compattestfile,atf
./usr/tests/sys/net/Kyuafile tests-sys-tests compattestfile,atf,kyua
Index: src/etc/mtree/NetBSD.dist.tests
diff -u src/etc/mtree/NetBSD.dist.tests:1.170 src/etc/mtree/NetBSD.dist.tests:1.171
--- src/etc/mtree/NetBSD.dist.tests:1.170 Tue Jun 30 14:30:49 2020
+++ src/etc/mtree/NetBSD.dist.tests Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-# $NetBSD: NetBSD.dist.tests,v 1.170 2020/06/30 14:30:49 jruoho Exp $
+# $NetBSD: NetBSD.dist.tests,v 1.171 2020/06/30 20:32:11 riastradh Exp $
./usr/libdata/debug/usr/tests
./usr/libdata/debug/usr/tests/atf
@@ -162,6 +162,8 @@
./usr/libdata/debug/usr/tests/sbin
./usr/libdata/debug/usr/tests/sbin/resize_ffs
./usr/libdata/debug/usr/tests/sys
+./usr/libdata/debug/usr/tests/sys/crypto
+./usr/libdata/debug/usr/tests/sys/crypto/aes
./usr/libdata/debug/usr/tests/sys/net
./usr/libdata/debug/usr/tests/sys/netatalk
./usr/libdata/debug/usr/tests/sys/netinet
@@ -386,6 +388,8 @@
./usr/tests/share/examples/lutok
./usr/tests/share/mk
./usr/tests/sys
+./usr/tests/sys/crypto
+./usr/tests/sys/crypto/aes
./usr/tests/sys/net
./usr/tests/sys/netatalk
./usr/tests/sys/netinet
Index: src/sys/crypto/aes/aes_bear.c
diff -u src/sys/crypto/aes/aes_bear.c:1.1 src/sys/crypto/aes/aes_bear.c:1.2
--- src/sys/crypto/aes/aes_bear.c:1.1 Mon Jun 29 23:27:52 2020
+++ src/sys/crypto/aes/aes_bear.c Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aes_bear.c,v 1.1 2020/06/29 23:27:52 riastradh Exp $ */
+/* $NetBSD: aes_bear.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,11 +27,20 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_bear.c,v 1.1 2020/06/29 23:27:52 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_bear.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $");
#include <sys/types.h>
#include <sys/endian.h>
+
+#ifdef _KERNEL
#include <sys/systm.h>
+#else
+#include <assert.h>
+#include <err.h>
+#include <string.h>
+#define KASSERT assert
+#define panic(fmt, args...) err(1, fmt, args)
+#endif
#include <crypto/aes/aes.h>
#include <crypto/aes/aes_bear.h>
Index: src/sys/crypto/aes/aes_selftest.c
diff -u src/sys/crypto/aes/aes_selftest.c:1.1 src/sys/crypto/aes/aes_selftest.c:1.2
--- src/sys/crypto/aes/aes_selftest.c:1.1 Mon Jun 29 23:27:52 2020
+++ src/sys/crypto/aes/aes_selftest.c Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aes_selftest.c,v 1.1 2020/06/29 23:27:52 riastradh Exp $ */
+/* $NetBSD: aes_selftest.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,13 +27,44 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_selftest.c,v 1.1 2020/06/29 23:27:52 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_selftest.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $");
+
+#ifdef _KERNEL
#include <sys/types.h>
#include <sys/systm.h>
#include <lib/libkern/libkern.h>
+#else /* !_KERNEL */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+static void
+hexdump(int (*prf)(const char *, ...) __printflike(1,2), const char *prefix,
+ const void *buf, size_t len)
+{
+ const uint8_t *p = buf;
+ size_t i;
+
+ (*prf)("%s (%zu bytes)\n", prefix, len);
+ for (i = 0; i < len; i++) {
+ if (i % 16 == 8)
+ (*prf)(" ");
+ else
+ (*prf)(" ");
+ (*prf)("%02hhx", p[i]);
+ if ((i + 1) % 16 == 0)
+ (*prf)("\n");
+ }
+ if (i % 16)
+ (*prf)("\n");
+}
+
+#endif /* _KERNEL */
+
#include <crypto/aes/aes.h>
static const unsigned aes_keybytes[] __unused = { 16, 24, 32 };
Index: src/sys/crypto/aes/aes_ct.c
diff -u src/sys/crypto/aes/aes_ct.c:1.2 src/sys/crypto/aes/aes_ct.c:1.3
--- src/sys/crypto/aes/aes_ct.c:1.2 Mon Jun 29 23:36:59 2020
+++ src/sys/crypto/aes/aes_ct.c Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aes_ct.c,v 1.2 2020/06/29 23:36:59 riastradh Exp $ */
+/* $NetBSD: aes_ct.c,v 1.3 2020/06/30 20:32:11 riastradh Exp $ */
/*
* Copyright (c) 2016 Thomas Pornin <[email protected]>
@@ -25,11 +25,15 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_ct.c,v 1.2 2020/06/29 23:36:59 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_ct.c,v 1.3 2020/06/30 20:32:11 riastradh Exp $");
#include <sys/types.h>
+#ifdef _KERNEL
#include <lib/libkern/libkern.h>
+#else
+#include <string.h>
+#endif
#include <crypto/aes/aes_bear.h>
Index: src/sys/crypto/aes/arch/arm/aes_armv8.c
diff -u src/sys/crypto/aes/arch/arm/aes_armv8.c:1.2 src/sys/crypto/aes/arch/arm/aes_armv8.c:1.3
--- src/sys/crypto/aes/arch/arm/aes_armv8.c:1.2 Mon Jun 29 23:53:12 2020
+++ src/sys/crypto/aes/arch/arm/aes_armv8.c Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aes_armv8.c,v 1.2 2020/06/29 23:53:12 riastradh Exp $ */
+/* $NetBSD: aes_armv8.c,v 1.3 2020/06/30 20:32:11 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,19 +27,35 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_armv8.c,v 1.2 2020/06/29 23:53:12 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_armv8.c,v 1.3 2020/06/30 20:32:11 riastradh Exp $");
+#ifdef _KERNEL
#include <sys/types.h>
#include <sys/proc.h>
#include <sys/systm.h>
+#else
+#include <assert.h>
+#include <err.h>
+#include <stdint.h>
+#include <string.h>
+#define KASSERT assert
+#define panic(fmt, args...) err(1, fmt, args)
+#endif
#include <crypto/aes/aes.h>
#include <crypto/aes/arch/arm/aes_armv8.h>
-#include <arm/fpu.h>
-
#include <aarch64/armreg.h>
+#ifdef _KERNEL
+#include <arm/fpu.h>
+#else
+#include <sys/sysctl.h>
+#include <stddef.h>
+#define fpu_kern_enter() ((void)0)
+#define fpu_kern_leave() ((void)0)
+#endif
+
static void
aesarmv8_setenckey(struct aesenc *enc, const uint8_t key[static 16],
uint32_t nrounds)
@@ -226,7 +242,18 @@ aesarmv8_probe(void)
int result = 0;
/* Verify that the CPU supports AES. */
+#ifdef _KERNEL
id = &curcpu()->ci_id;
+#else
+ struct aarch64_sysctl_cpu_id ids;
+ size_t idlen;
+ id = &ids;
+ idlen = sizeof ids;
+ if (sysctlbyname("machdep.cpu0.cpu_id", id, &idlen, NULL, 0))
+ return -1;
+ if (idlen != sizeof ids)
+ return -1;
+#endif
switch (__SHIFTOUT(id->ac_aa64isar0, ID_AA64ISAR0_EL1_AES)) {
case ID_AA64ISAR0_EL1_AES_AES:
case ID_AA64ISAR0_EL1_AES_PMUL:
Index: src/sys/crypto/aes/arch/arm/aes_neon.c
diff -u src/sys/crypto/aes/arch/arm/aes_neon.c:1.2 src/sys/crypto/aes/arch/arm/aes_neon.c:1.3
--- src/sys/crypto/aes/arch/arm/aes_neon.c:1.2 Mon Jun 29 23:57:56 2020
+++ src/sys/crypto/aes/arch/arm/aes_neon.c Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aes_neon.c,v 1.2 2020/06/29 23:57:56 riastradh Exp $ */
+/* $NetBSD: aes_neon.c,v 1.3 2020/06/30 20:32:11 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -39,11 +39,16 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_neon.c,v 1.2 2020/06/29 23:57:56 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_neon.c,v 1.3 2020/06/30 20:32:11 riastradh Exp $");
#include <sys/types.h>
+#ifdef _KERNEL
#include <sys/systm.h>
+#else
+#include <err.h>
+#define panic(fmt, args...) err(1, fmt, ##args)
+#endif
#include "aes_neon_impl.h"
Index: src/sys/crypto/aes/arch/arm/aes_neon_impl.c
diff -u src/sys/crypto/aes/arch/arm/aes_neon_impl.c:1.1 src/sys/crypto/aes/arch/arm/aes_neon_impl.c:1.2
--- src/sys/crypto/aes/arch/arm/aes_neon_impl.c:1.1 Mon Jun 29 23:56:31 2020
+++ src/sys/crypto/aes/arch/arm/aes_neon_impl.c Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aes_neon_impl.c,v 1.1 2020/06/29 23:56:31 riastradh Exp $ */
+/* $NetBSD: aes_neon_impl.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_neon_impl.c,v 1.1 2020/06/29 23:56:31 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_neon_impl.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $");
#include <sys/types.h>
#include <sys/proc.h>
@@ -35,13 +35,21 @@ __KERNEL_RCSID(1, "$NetBSD: aes_neon_imp
#include <crypto/aes/aes.h>
#include <crypto/aes/arch/arm/aes_neon.h>
-#include <arm/fpu.h>
-
#ifdef __aarch64__
#include <aarch64/armreg.h>
-#else
+#endif
+
+#ifdef _KERNEL
+#ifndef __aarch64__
#include <arm/locore.h>
#endif
+#include <arm/fpu.h>
+#else
+#include <sys/sysctl.h>
+#include <stddef.h>
+#define fpu_kern_enter() ((void)0)
+#define fpu_kern_leave() ((void)0)
+#endif
static void
aes_neon_setenckey_impl(struct aesenc *enc, const uint8_t *key,
@@ -145,7 +153,18 @@ aes_neon_probe(void)
/* Verify that the CPU supports NEON. */
#ifdef __aarch64__
+#ifdef _KERNEL
id = &curcpu()->ci_id;
+#else
+ struct aarch64_sysctl_cpu_id ids;
+ size_t idlen;
+ id = &ids;
+ idlen = sizeof ids;
+ if (sysctlbyname("machdep.cpu0.cpu_id", id, &idlen, NULL, 0))
+ return -1;
+ if (idlen != sizeof ids)
+ return -1;
+#endif
switch (__SHIFTOUT(id->ac_aa64pfr0, ID_AA64PFR0_EL1_ADVSIMD)) {
case ID_AA64PFR0_EL1_ADV_SIMD_IMPL:
break;
@@ -153,8 +172,17 @@ aes_neon_probe(void)
return -1;
}
#else
+#ifdef _KERNEL
if (!cpu_neon_present)
return -1;
+#else
+ int neon;
+ size_t neonlen = sizeof neon;
+ if (0 && sysctlbyname("machdep.neon_present", &neon, &neonlen, NULL, 0))
+ return -1;
+ if (0 && !neon)
+ return -1;
+#endif
#endif
fpu_kern_enter();
Index: src/sys/crypto/aes/arch/arm/aes_neon_subr.c
diff -u src/sys/crypto/aes/arch/arm/aes_neon_subr.c:1.1 src/sys/crypto/aes/arch/arm/aes_neon_subr.c:1.2
--- src/sys/crypto/aes/arch/arm/aes_neon_subr.c:1.1 Mon Jun 29 23:56:31 2020
+++ src/sys/crypto/aes/arch/arm/aes_neon_subr.c Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aes_neon_subr.c,v 1.1 2020/06/29 23:56:31 riastradh Exp $ */
+/* $NetBSD: aes_neon_subr.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,11 +27,17 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_neon_subr.c,v 1.1 2020/06/29 23:56:31 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_neon_subr.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $");
+#ifdef _KERNEL
#include <sys/systm.h>
-
#include <lib/libkern/libkern.h>
+#else
+#include <assert.h>
+#include <inttypes.h>
+#include <stdio.h>
+#define KASSERT assert
+#endif
#include <crypto/aes/arch/arm/aes_neon.h>
Index: src/sys/crypto/aes/arch/x86/aes_ni.c
diff -u src/sys/crypto/aes/arch/x86/aes_ni.c:1.1 src/sys/crypto/aes/arch/x86/aes_ni.c:1.2
--- src/sys/crypto/aes/arch/x86/aes_ni.c:1.1 Mon Jun 29 23:29:40 2020
+++ src/sys/crypto/aes/arch/x86/aes_ni.c Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aes_ni.c,v 1.1 2020/06/29 23:29:40 riastradh Exp $ */
+/* $NetBSD: aes_ni.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,17 +27,32 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_ni.c,v 1.1 2020/06/29 23:29:40 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_ni.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $");
+#ifdef _KERNEL
#include <sys/types.h>
#include <sys/systm.h>
+#else
+#include <assert.h>
+#include <err.h>
+#include <stdint.h>
+#include <string.h>
+#define KASSERT assert
+#define panic(fmt, args...) err(1, fmt, args)
+#endif
#include <crypto/aes/aes.h>
#include <crypto/aes/arch/x86/aes_ni.h>
+#ifdef _KERNEL
#include <x86/cpuvar.h>
#include <x86/fpu.h>
#include <x86/specialreg.h>
+#else
+#include <cpuid.h>
+#define fpu_kern_enter() ((void)0)
+#define fpu_kern_leave() ((void)0)
+#endif
static void
aesni_setenckey(struct aesenc *enc, const uint8_t key[static 16],
@@ -224,8 +239,16 @@ aesni_probe(void)
int result = 0;
/* Verify that the CPU supports AES-NI. */
+#ifdef _KERNEL
if ((cpu_feature[1] & CPUID2_AES) == 0)
return -1;
+#else
+ unsigned eax, ebx, ecx, edx;
+ if (!__get_cpuid(1, &eax, &ebx, &ecx, &edx))
+ return -1;
+ if ((ecx & bit_AES) == 0)
+ return -1;
+#endif
fpu_kern_enter();
Index: src/sys/crypto/aes/arch/x86/aes_sse2.c
diff -u src/sys/crypto/aes/arch/x86/aes_sse2.c:1.1 src/sys/crypto/aes/arch/x86/aes_sse2.c:1.2
--- src/sys/crypto/aes/arch/x86/aes_sse2.c:1.1 Mon Jun 29 23:47:54 2020
+++ src/sys/crypto/aes/arch/x86/aes_sse2.c Tue Jun 30 20:32:11 2020
@@ -23,11 +23,16 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_sse2.c,v 1.1 2020/06/29 23:47:54 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_sse2.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $");
#include <sys/types.h>
+#ifdef _KERNEL
#include <lib/libkern/libkern.h>
+#else
+#include <stdint.h>
+#include <string.h>
+#endif
#include "aes_sse2_impl.h"
Index: src/sys/crypto/aes/arch/x86/aes_sse2_subr.c
diff -u src/sys/crypto/aes/arch/x86/aes_sse2_subr.c:1.1 src/sys/crypto/aes/arch/x86/aes_sse2_subr.c:1.2
--- src/sys/crypto/aes/arch/x86/aes_sse2_subr.c:1.1 Mon Jun 29 23:50:05 2020
+++ src/sys/crypto/aes/arch/x86/aes_sse2_subr.c Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aes_sse2_subr.c,v 1.1 2020/06/29 23:50:05 riastradh Exp $ */
+/* $NetBSD: aes_sse2_subr.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,11 +27,20 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_sse2_subr.c,v 1.1 2020/06/29 23:50:05 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_sse2_subr.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $");
+#ifdef _KERNEL
#include <sys/systm.h>
-
#include <lib/libkern/libkern.h>
+#else
+#include <err.h>
+#include <assert.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#define KASSERT assert
+#define panic(fmt, args...) err(1, fmt, ##args)
+#endif
#include <crypto/aes/aes.h>
#include <crypto/aes/arch/x86/aes_sse2.h>
Index: src/sys/crypto/aes/arch/x86/aes_ssse3.c
diff -u src/sys/crypto/aes/arch/x86/aes_ssse3.c:1.1 src/sys/crypto/aes/arch/x86/aes_ssse3.c:1.2
--- src/sys/crypto/aes/arch/x86/aes_ssse3.c:1.1 Mon Jun 29 23:51:35 2020
+++ src/sys/crypto/aes/arch/x86/aes_ssse3.c Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aes_ssse3.c,v 1.1 2020/06/29 23:51:35 riastradh Exp $ */
+/* $NetBSD: aes_ssse3.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -39,11 +39,16 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_ssse3.c,v 1.1 2020/06/29 23:51:35 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_ssse3.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $");
#include <sys/types.h>
+#ifdef _KERNEL
#include <sys/systm.h>
+#else
+#include <err.h>
+#define panic(fmt, args...) err(1, fmt, ##args)
+#endif
#include "aes_ssse3_impl.h"
Index: src/sys/crypto/aes/arch/x86/aes_ssse3_impl.c
diff -u src/sys/crypto/aes/arch/x86/aes_ssse3_impl.c:1.1 src/sys/crypto/aes/arch/x86/aes_ssse3_impl.c:1.2
--- src/sys/crypto/aes/arch/x86/aes_ssse3_impl.c:1.1 Mon Jun 29 23:51:35 2020
+++ src/sys/crypto/aes/arch/x86/aes_ssse3_impl.c Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aes_ssse3_impl.c,v 1.1 2020/06/29 23:51:35 riastradh Exp $ */
+/* $NetBSD: aes_ssse3_impl.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,15 +27,21 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_ssse3_impl.c,v 1.1 2020/06/29 23:51:35 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_ssse3_impl.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $");
#include <crypto/aes/aes.h>
#include <crypto/aes/arch/x86/aes_ssse3.h>
+#ifdef _KERNEL
#include <x86/cpu.h>
#include <x86/cpuvar.h>
#include <x86/fpu.h>
#include <x86/specialreg.h>
+#else
+#include <cpuid.h>
+#define fpu_kern_enter() ((void)0)
+#define fpu_kern_leave() ((void)0)
+#endif
static void
aes_ssse3_setenckey_impl(struct aesenc *enc, const uint8_t *key,
@@ -135,6 +141,7 @@ aes_ssse3_probe(void)
int result = 0;
/* Verify that the CPU supports SSE, SSE2, SSE3, and SSSE3. */
+#ifdef _KERNEL
if (!i386_has_sse)
return -1;
if (!i386_has_sse2)
@@ -143,6 +150,19 @@ aes_ssse3_probe(void)
return -1;
if (((cpu_feature[1]) & CPUID2_SSSE3) == 0)
return -1;
+#else
+ unsigned eax, ebx, ecx, edx;
+ if (!__get_cpuid(1, &eax, &ebx, &ecx, &edx))
+ return -1;
+ if ((edx & bit_SSE) == 0)
+ return -1;
+ if ((edx & bit_SSE2) == 0)
+ return -1;
+ if ((ecx & bit_SSE3) == 0)
+ return -1;
+ if ((ecx & bit_SSSE3) == 0)
+ return -1;
+#endif
fpu_kern_enter();
result = aes_ssse3_selftest();
Index: src/sys/crypto/aes/arch/x86/aes_ssse3_subr.c
diff -u src/sys/crypto/aes/arch/x86/aes_ssse3_subr.c:1.1 src/sys/crypto/aes/arch/x86/aes_ssse3_subr.c:1.2
--- src/sys/crypto/aes/arch/x86/aes_ssse3_subr.c:1.1 Mon Jun 29 23:51:35 2020
+++ src/sys/crypto/aes/arch/x86/aes_ssse3_subr.c Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aes_ssse3_subr.c,v 1.1 2020/06/29 23:51:35 riastradh Exp $ */
+/* $NetBSD: aes_ssse3_subr.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,11 +27,17 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_ssse3_subr.c,v 1.1 2020/06/29 23:51:35 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_ssse3_subr.c,v 1.2 2020/06/30 20:32:11 riastradh Exp $");
+#ifdef _KERNEL
#include <sys/systm.h>
-
#include <lib/libkern/libkern.h>
+#else
+#include <assert.h>
+#include <inttypes.h>
+#include <stdio.h>
+#define KASSERT assert
+#endif
#include "aes_ssse3_impl.h"
Index: src/sys/crypto/aes/arch/x86/aes_sse2_impl.c
diff -u src/sys/crypto/aes/arch/x86/aes_sse2_impl.c:1.2 src/sys/crypto/aes/arch/x86/aes_sse2_impl.c:1.3
--- src/sys/crypto/aes/arch/x86/aes_sse2_impl.c:1.2 Mon Jun 29 23:50:05 2020
+++ src/sys/crypto/aes/arch/x86/aes_sse2_impl.c Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aes_sse2_impl.c,v 1.2 2020/06/29 23:50:05 riastradh Exp $ */
+/* $NetBSD: aes_sse2_impl.c,v 1.3 2020/06/30 20:32:11 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_sse2_impl.c,v 1.2 2020/06/29 23:50:05 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_sse2_impl.c,v 1.3 2020/06/30 20:32:11 riastradh Exp $");
#include <sys/types.h>
#include <sys/endian.h>
@@ -35,10 +35,16 @@ __KERNEL_RCSID(1, "$NetBSD: aes_sse2_imp
#include <crypto/aes/aes.h>
#include <crypto/aes/arch/x86/aes_sse2.h>
+#ifdef _KERNEL
#include <x86/cpu.h>
#include <x86/cpuvar.h>
#include <x86/fpu.h>
#include <x86/specialreg.h>
+#else
+#include <cpuid.h>
+#define fpu_kern_enter() ((void)0)
+#define fpu_kern_leave() ((void)0)
+#endif
static void
aes_sse2_setenckey_impl(struct aesenc *enc, const uint8_t *key,
@@ -142,10 +148,20 @@ aes_sse2_probe(void)
int result = 0;
/* Verify that the CPU supports SSE and SSE2. */
+#ifdef _KERNEL
if (!i386_has_sse)
return -1;
if (!i386_has_sse2)
return -1;
+#else
+ unsigned eax, ebx, ecx, edx;
+ if (!__get_cpuid(1, &eax, &ebx, &ecx, &edx))
+ return -1;
+ if ((edx & bit_SSE) == 0)
+ return -1;
+ if ((edx & bit_SSE2) == 0)
+ return -1;
+#endif
fpu_kern_enter();
result = aes_sse2_selftest();
Index: src/sys/crypto/aes/arch/x86/aes_via.c
diff -u src/sys/crypto/aes/arch/x86/aes_via.c:1.2 src/sys/crypto/aes/arch/x86/aes_via.c:1.3
--- src/sys/crypto/aes/arch/x86/aes_via.c:1.2 Mon Jun 29 23:41:35 2020
+++ src/sys/crypto/aes/arch/x86/aes_via.c Tue Jun 30 20:32:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aes_via.c,v 1.2 2020/06/29 23:41:35 riastradh Exp $ */
+/* $NetBSD: aes_via.c,v 1.3 2020/06/30 20:32:11 riastradh Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,20 +27,51 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_via.c,v 1.2 2020/06/29 23:41:35 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_via.c,v 1.3 2020/06/30 20:32:11 riastradh Exp $");
+#ifdef _KERNEL
#include <sys/types.h>
#include <sys/evcnt.h>
#include <sys/systm.h>
+#else
+#include <assert.h>
+#include <err.h>
+#include <stdint.h>
+#include <string.h>
+#define KASSERT assert
+#define panic(fmt, args...) err(1, fmt, args)
+struct evcnt { uint64_t ev_count; };
+#define EVCNT_INITIALIZER(a,b,c,d) {0}
+#define EVCNT_ATTACH_STATIC(name) static char name##_attach __unused = 0
+#endif
#include <crypto/aes/aes.h>
#include <crypto/aes/aes_bear.h>
+#ifdef _KERNEL
#include <x86/cpufunc.h>
#include <x86/cpuvar.h>
#include <x86/fpu.h>
#include <x86/specialreg.h>
#include <x86/via_padlock.h>
+#else
+#include <cpuid.h>
+#define fpu_kern_enter() ((void)0)
+#define fpu_kern_leave() ((void)0)
+#define C3_CRYPT_CWLO_ROUND_M 0x0000000f
+#define C3_CRYPT_CWLO_ALG_M 0x00000070
+#define C3_CRYPT_CWLO_ALG_AES 0x00000000
+#define C3_CRYPT_CWLO_KEYGEN_M 0x00000080
+#define C3_CRYPT_CWLO_KEYGEN_HW 0x00000000
+#define C3_CRYPT_CWLO_KEYGEN_SW 0x00000080
+#define C3_CRYPT_CWLO_NORMAL 0x00000000
+#define C3_CRYPT_CWLO_INTERMEDIATE 0x00000100
+#define C3_CRYPT_CWLO_ENCRYPT 0x00000000
+#define C3_CRYPT_CWLO_DECRYPT 0x00000200
+#define C3_CRYPT_CWLO_KEY128 0x0000000a /* 128bit, 10 rds */
+#define C3_CRYPT_CWLO_KEY192 0x0000040c /* 192bit, 12 rds */
+#define C3_CRYPT_CWLO_KEY256 0x0000080e /* 256bit, 15 rds */
+#endif
static void
aesvia_reload_keys(void)
@@ -647,8 +678,34 @@ aesvia_probe(void)
{
/* Verify that the CPU advertises VIA ACE support. */
+#ifdef _KERNEL
if ((cpu_feature[4] & CPUID_VIA_HAS_ACE) == 0)
return -1;
+#else
+ /*
+ * From the VIA PadLock Programming Guide:
+ * http://linux.via.com.tw/support/beginDownload.action?eleid=181&fid=261
+ */
+ unsigned eax, ebx, ecx, edx;
+ if (!__get_cpuid(0, &eax, &ebx, &ecx, &edx))
+ return -1;
+ if (ebx != signature_CENTAUR_ebx ||
+ ecx != signature_CENTAUR_ecx ||
+ edx != signature_CENTAUR_edx)
+ return -1;
+ if (eax < 0xc0000000)
+ return -1;
+ if (!__get_cpuid(0xc0000000, &eax, &ebx, &ecx, &edx))
+ return -1;
+ if (eax < 0xc0000001)
+ return -1;
+ if (!__get_cpuid(0xc0000001, &eax, &ebx, &ecx, &edx))
+ return -1;
+ /* Check whether ACE or ACE2 is both supported and enabled. */
+ if ((edx & 0x000000c0) != 0x000000c0 ||
+ (edx & 0x00000300) != 0x00000300)
+ return -1;
+#endif
/* Verify that our XTS tweak update logic works. */
if (aesvia_xts_update_selftest())
Index: src/tests/sys/Makefile
diff -u src/tests/sys/Makefile:1.3 src/tests/sys/Makefile:1.4
--- src/tests/sys/Makefile:1.3 Tue Dec 2 19:48:21 2014
+++ src/tests/sys/Makefile Tue Jun 30 20:32:11 2020
@@ -1,9 +1,14 @@
-# $NetBSD: Makefile,v 1.3 2014/12/02 19:48:21 christos Exp $
+# $NetBSD: Makefile,v 1.4 2020/06/30 20:32:11 riastradh Exp $
.include <bsd.own.mk>
TESTSDIR= ${TESTSBASE}/sys
-TESTS_SUBDIRS+= net netatalk netinet netinet6 rc
+TESTS_SUBDIRS+= crypto
+TESTS_SUBDIRS+= net
+TESTS_SUBDIRS+= netatalk
+TESTS_SUBDIRS+= netinet
+TESTS_SUBDIRS+= netinet6
+TESTS_SUBDIRS+= rc
.include <bsd.test.mk>
Added files:
Index: src/tests/sys/crypto/Makefile
diff -u /dev/null src/tests/sys/crypto/Makefile:1.1
--- /dev/null Tue Jun 30 20:32:12 2020
+++ src/tests/sys/crypto/Makefile Tue Jun 30 20:32:11 2020
@@ -0,0 +1,9 @@
+# $NetBSD: Makefile,v 1.1 2020/06/30 20:32:11 riastradh Exp $
+
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/sys/crypto
+
+TESTS_SUBDIRS+= aes
+
+.include <bsd.test.mk>
Index: src/tests/sys/crypto/aes/Makefile
diff -u /dev/null src/tests/sys/crypto/aes/Makefile:1.1
--- /dev/null Tue Jun 30 20:32:12 2020
+++ src/tests/sys/crypto/aes/Makefile Tue Jun 30 20:32:11 2020
@@ -0,0 +1,66 @@
+# $NetBSD: Makefile,v 1.1 2020/06/30 20:32:11 riastradh Exp $
+
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/sys/crypto/aes
+
+TESTS_C= t_aes
+
+.PATH: ${NETBSDSRCDIR}/sys/crypto/aes
+CPPFLAGS+= -I${NETBSDSRCDIR}/sys
+
+SRCS.t_aes+= t_aes.c
+
+SRCS.t_aes+= aes_bear.c
+SRCS.t_aes+= aes_ct.c
+SRCS.t_aes+= aes_ct_dec.c
+SRCS.t_aes+= aes_ct_enc.c
+SRCS.t_aes+= aes_selftest.c
+
+.if !empty(MACHINE_ARCH:Mearmv7*) || !empty(MACHINE_ARCH:Maarch64*)
+
+.PATH: ${NETBSDSRCDIR}/sys/crypto/aes/arch/arm
+CPPFLAGS+= -I${NETBSDSRCDIR}/sys/crypto/aes/arch/arm
+
+.if !empty(MACHINE_ARCH:Maarch64*) # XXX no AESE/AESD in 32-bit mode yet
+SRCS.t_aes+= aes_armv8.c
+SRCS.t_aes+= aes_armv8_64.S
+.endif
+
+SRCS.t_aes+= aes_neon.c
+SRCS.t_aes+= aes_neon_impl.c
+SRCS.t_aes+= aes_neon_subr.c
+.if !empty(MACHINE_ARCH:Mearmv7*)
+SRCS.t_aes+= aes_neon_32.S
+.endif
+
+.endif # earmv7/aarch64
+
+.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64"
+
+.PATH: ${NETBSDSRCDIR}/sys/crypto/aes/arch/x86
+CPPFLAGS+= -I${NETBSDSRCDIR}/sys/crypto/aes/arch/x86
+
+.if ${MACHINE_ARCH} == "x86_64" # XXX no AES-NI in 32-bit mode yet
+SRCS.t_aes+= aes_ni.c
+SRCS.t_aes+= aes_ni_64.S
+.endif
+
+SRCS.t_aes+= aes_sse2.c
+SRCS.t_aes+= aes_sse2_dec.c
+SRCS.t_aes+= aes_sse2_enc.c
+SRCS.t_aes+= aes_sse2_impl.c
+SRCS.t_aes+= aes_sse2_subr.c
+
+SRCS.t_aes+= aes_ssse3.c
+SRCS.t_aes+= aes_ssse3_impl.c
+SRCS.t_aes+= aes_ssse3_subr.c
+COPTS.aes_ssse3.c+= -msse3 -mssse3
+
+SRCS.t_aes+= aes_via.c
+
+.endif # x86
+
+WARNS= 5
+
+.include <bsd.test.mk>
Index: src/tests/sys/crypto/aes/t_aes.c
diff -u /dev/null src/tests/sys/crypto/aes/t_aes.c:1.1
--- /dev/null Tue Jun 30 20:32:12 2020
+++ src/tests/sys/crypto/aes/t_aes.c Tue Jun 30 20:32:11 2020
@@ -0,0 +1,135 @@
+/* $NetBSD: t_aes.c,v 1.1 2020/06/30 20:32:11 riastradh Exp $ */
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/types.h>
+
+#include <crypto/aes/aes.h>
+#include <crypto/aes/aes_bear.h>
+
+#if defined(__i386__) || defined(__x86_64__)
+#include <crypto/aes/arch/x86/aes_ni.h>
+#include <crypto/aes/arch/x86/aes_sse2.h>
+#include <crypto/aes/arch/x86/aes_ssse3.h>
+#include <crypto/aes/arch/x86/aes_via.h>
+#endif
+
+#ifdef __aarch64__
+#include <crypto/aes/arch/arm/aes_armv8.h>
+#endif
+
+#ifdef __ARM_NEON
+#include <crypto/aes/arch/arm/aes_neon.h>
+#endif
+
+#include <atf-c.h>
+
+ATF_TC(aes_ct_selftest);
+ATF_TC_HEAD(aes_ct_selftest, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "BearSSL aes_ct tests");
+}
+
+ATF_TC_BODY(aes_ct_selftest, tc)
+{
+
+ if (aes_bear_impl.ai_probe()) {
+ /*
+ * aes_ct is the portable software fallback, so probe
+ * should never fail.
+ */
+ atf_tc_fail("BearSSL aes_ct probe failed");
+ }
+
+ if (aes_selftest(&aes_bear_impl))
+ atf_tc_fail("BearSSL aes_ct self-test failed");
+}
+
+#define AES_SELFTEST(name, impl, descr) \
+ATF_TC(name); \
+ATF_TC_HEAD(name, tc) \
+{ \
+ \
+ atf_tc_set_md_var(tc, "descr", descr); \
+} \
+ \
+ATF_TC_BODY(name, tc) \
+{ \
+ \
+ if ((impl)->ai_probe()) \
+ atf_tc_skip("%s not supported on this hardware", \
+ (impl)->ai_name); \
+ if (aes_selftest(impl)) \
+ atf_tc_fail("%s self-test failed", (impl)->ai_name); \
+}
+
+#ifdef __aarch64__
+AES_SELFTEST(aes_armv8_selftest, &aes_armv8_impl, "ARMv8.0-AES self-test")
+#endif
+
+#ifdef __ARM_NEON
+AES_SELFTEST(aes_neon_selftest, &aes_neon_impl, "ARM NEON vpaes self-test")
+#endif
+
+#ifdef __x86_64__
+AES_SELFTEST(aes_ni_selftest, &aes_ni_impl, "Intel AES-NI self-test")
+#endif
+
+#if defined(__i386__) || defined(__x86_64__)
+AES_SELFTEST(aes_sse2_selftest, &aes_sse2_impl,
+ "Intel SSE2 bitsliced self-test")
+AES_SELFTEST(aes_ssse3_selftest, &aes_ssse3_impl,
+ "Intel SSSE3 vpaes self-test")
+AES_SELFTEST(aes_via_selftest, &aes_via_impl, "VIA ACE AES self-test")
+#endif
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, aes_ct_selftest);
+
+#ifdef __aarch64__
+ ATF_TP_ADD_TC(tp, aes_armv8_selftest);
+#endif
+
+#ifdef __ARM_NEON
+ ATF_TP_ADD_TC(tp, aes_neon_selftest);
+#endif
+
+#ifdef __x86_64__
+ ATF_TP_ADD_TC(tp, aes_ni_selftest);
+#endif
+
+#if defined(__i386__) || defined(__x86_64__)
+ ATF_TP_ADD_TC(tp, aes_sse2_selftest);
+ ATF_TP_ADD_TC(tp, aes_ssse3_selftest);
+ ATF_TP_ADD_TC(tp, aes_via_selftest);
+#endif
+
+ return atf_no_error();
+}