t_aes.c revision 1.1 1 1.1 riastrad /* $NetBSD: t_aes.c,v 1.1 2020/06/30 20:32:11 riastradh Exp $ */
2 1.1 riastrad
3 1.1 riastrad /*-
4 1.1 riastrad * Copyright (c) 2020 The NetBSD Foundation, Inc.
5 1.1 riastrad * All rights reserved.
6 1.1 riastrad *
7 1.1 riastrad * Redistribution and use in source and binary forms, with or without
8 1.1 riastrad * modification, are permitted provided that the following conditions
9 1.1 riastrad * are met:
10 1.1 riastrad * 1. Redistributions of source code must retain the above copyright
11 1.1 riastrad * notice, this list of conditions and the following disclaimer.
12 1.1 riastrad * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 riastrad * notice, this list of conditions and the following disclaimer in the
14 1.1 riastrad * documentation and/or other materials provided with the distribution.
15 1.1 riastrad *
16 1.1 riastrad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 riastrad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 riastrad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 riastrad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 riastrad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 riastrad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 riastrad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 riastrad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 riastrad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 riastrad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 riastrad * POSSIBILITY OF SUCH DAMAGE.
27 1.1 riastrad */
28 1.1 riastrad
29 1.1 riastrad #include <sys/types.h>
30 1.1 riastrad
31 1.1 riastrad #include <crypto/aes/aes.h>
32 1.1 riastrad #include <crypto/aes/aes_bear.h>
33 1.1 riastrad
34 1.1 riastrad #if defined(__i386__) || defined(__x86_64__)
35 1.1 riastrad #include <crypto/aes/arch/x86/aes_ni.h>
36 1.1 riastrad #include <crypto/aes/arch/x86/aes_sse2.h>
37 1.1 riastrad #include <crypto/aes/arch/x86/aes_ssse3.h>
38 1.1 riastrad #include <crypto/aes/arch/x86/aes_via.h>
39 1.1 riastrad #endif
40 1.1 riastrad
41 1.1 riastrad #ifdef __aarch64__
42 1.1 riastrad #include <crypto/aes/arch/arm/aes_armv8.h>
43 1.1 riastrad #endif
44 1.1 riastrad
45 1.1 riastrad #ifdef __ARM_NEON
46 1.1 riastrad #include <crypto/aes/arch/arm/aes_neon.h>
47 1.1 riastrad #endif
48 1.1 riastrad
49 1.1 riastrad #include <atf-c.h>
50 1.1 riastrad
51 1.1 riastrad ATF_TC(aes_ct_selftest);
52 1.1 riastrad ATF_TC_HEAD(aes_ct_selftest, tc)
53 1.1 riastrad {
54 1.1 riastrad
55 1.1 riastrad atf_tc_set_md_var(tc, "descr", "BearSSL aes_ct tests");
56 1.1 riastrad }
57 1.1 riastrad
58 1.1 riastrad ATF_TC_BODY(aes_ct_selftest, tc)
59 1.1 riastrad {
60 1.1 riastrad
61 1.1 riastrad if (aes_bear_impl.ai_probe()) {
62 1.1 riastrad /*
63 1.1 riastrad * aes_ct is the portable software fallback, so probe
64 1.1 riastrad * should never fail.
65 1.1 riastrad */
66 1.1 riastrad atf_tc_fail("BearSSL aes_ct probe failed");
67 1.1 riastrad }
68 1.1 riastrad
69 1.1 riastrad if (aes_selftest(&aes_bear_impl))
70 1.1 riastrad atf_tc_fail("BearSSL aes_ct self-test failed");
71 1.1 riastrad }
72 1.1 riastrad
73 1.1 riastrad #define AES_SELFTEST(name, impl, descr) \
74 1.1 riastrad ATF_TC(name); \
75 1.1 riastrad ATF_TC_HEAD(name, tc) \
76 1.1 riastrad { \
77 1.1 riastrad \
78 1.1 riastrad atf_tc_set_md_var(tc, "descr", descr); \
79 1.1 riastrad } \
80 1.1 riastrad \
81 1.1 riastrad ATF_TC_BODY(name, tc) \
82 1.1 riastrad { \
83 1.1 riastrad \
84 1.1 riastrad if ((impl)->ai_probe()) \
85 1.1 riastrad atf_tc_skip("%s not supported on this hardware", \
86 1.1 riastrad (impl)->ai_name); \
87 1.1 riastrad if (aes_selftest(impl)) \
88 1.1 riastrad atf_tc_fail("%s self-test failed", (impl)->ai_name); \
89 1.1 riastrad }
90 1.1 riastrad
91 1.1 riastrad #ifdef __aarch64__
92 1.1 riastrad AES_SELFTEST(aes_armv8_selftest, &aes_armv8_impl, "ARMv8.0-AES self-test")
93 1.1 riastrad #endif
94 1.1 riastrad
95 1.1 riastrad #ifdef __ARM_NEON
96 1.1 riastrad AES_SELFTEST(aes_neon_selftest, &aes_neon_impl, "ARM NEON vpaes self-test")
97 1.1 riastrad #endif
98 1.1 riastrad
99 1.1 riastrad #ifdef __x86_64__
100 1.1 riastrad AES_SELFTEST(aes_ni_selftest, &aes_ni_impl, "Intel AES-NI self-test")
101 1.1 riastrad #endif
102 1.1 riastrad
103 1.1 riastrad #if defined(__i386__) || defined(__x86_64__)
104 1.1 riastrad AES_SELFTEST(aes_sse2_selftest, &aes_sse2_impl,
105 1.1 riastrad "Intel SSE2 bitsliced self-test")
106 1.1 riastrad AES_SELFTEST(aes_ssse3_selftest, &aes_ssse3_impl,
107 1.1 riastrad "Intel SSSE3 vpaes self-test")
108 1.1 riastrad AES_SELFTEST(aes_via_selftest, &aes_via_impl, "VIA ACE AES self-test")
109 1.1 riastrad #endif
110 1.1 riastrad
111 1.1 riastrad ATF_TP_ADD_TCS(tp)
112 1.1 riastrad {
113 1.1 riastrad
114 1.1 riastrad ATF_TP_ADD_TC(tp, aes_ct_selftest);
115 1.1 riastrad
116 1.1 riastrad #ifdef __aarch64__
117 1.1 riastrad ATF_TP_ADD_TC(tp, aes_armv8_selftest);
118 1.1 riastrad #endif
119 1.1 riastrad
120 1.1 riastrad #ifdef __ARM_NEON
121 1.1 riastrad ATF_TP_ADD_TC(tp, aes_neon_selftest);
122 1.1 riastrad #endif
123 1.1 riastrad
124 1.1 riastrad #ifdef __x86_64__
125 1.1 riastrad ATF_TP_ADD_TC(tp, aes_ni_selftest);
126 1.1 riastrad #endif
127 1.1 riastrad
128 1.1 riastrad #if defined(__i386__) || defined(__x86_64__)
129 1.1 riastrad ATF_TP_ADD_TC(tp, aes_sse2_selftest);
130 1.1 riastrad ATF_TP_ADD_TC(tp, aes_ssse3_selftest);
131 1.1 riastrad ATF_TP_ADD_TC(tp, aes_via_selftest);
132 1.1 riastrad #endif
133 1.1 riastrad
134 1.1 riastrad return atf_no_error();
135 1.1 riastrad }
136