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