| 1 | /* |
| 2 | * QTest testcase for the ASPEED Hash and Crypto Engine |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 5 | * Copyright 2021 IBM Corp. |
| 6 | */ |
| 7 | |
| 8 | #include "qemu/osdep.h" |
| 9 | #include "libqtest.h" |
| 10 | #include "qemu/bitops.h" |
| 11 | #include "aspeed-hace-utils.h" |
| 12 | |
| 13 | static const struct AspeedMasks ast1030_masks = { |
| 14 | .src = 0x7fffffff, |
| 15 | .dest = 0x7ffffff8, |
| 16 | .key = 0x7ffffff8, |
| 17 | .len = 0x0fffffff, |
| 18 | }; |
| 19 | |
| 20 | static const struct AspeedMasks ast2600_masks = { |
| 21 | .src = 0x7fffffff, |
| 22 | .dest = 0x7ffffff8, |
| 23 | .key = 0x7ffffff8, |
| 24 | .len = 0x0fffffff, |
| 25 | }; |
| 26 | |
| 27 | static const struct AspeedMasks ast2500_masks = { |
| 28 | .src = 0x3fffffff, |
| 29 | .dest = 0x3ffffff8, |
| 30 | .key = 0x3fffffc0, |
| 31 | .len = 0x0fffffff, |
| 32 | }; |
| 33 | |
| 34 | static const struct AspeedMasks ast2400_masks = { |
| 35 | .src = 0x0fffffff, |
| 36 | .dest = 0x0ffffff8, |
| 37 | .key = 0x0fffffc0, |
| 38 | .len = 0x0fffffff, |
| 39 | }; |
| 40 | |
| 41 | /* ast1030 */ |
| 42 | static void test_md5_ast1030(void) |
| 43 | { |
| 44 | aspeed_test_md5("-machine ast1030-evb", 0x7e6d0000, 0x00000000); |
| 45 | } |
| 46 | |
| 47 | static void test_sha256_ast1030(void) |
| 48 | { |
| 49 | aspeed_test_sha256("-machine ast1030-evb", 0x7e6d0000, 0x00000000); |
| 50 | } |
| 51 | |
| 52 | static void test_sha256_sg_ast1030(void) |
| 53 | { |
| 54 | aspeed_test_sha256_sg("-machine ast1030-evb", 0x7e6d0000, 0x00000000); |
| 55 | } |
| 56 | |
| 57 | static void test_sha384_ast1030(void) |
| 58 | { |
| 59 | aspeed_test_sha384("-machine ast1030-evb", 0x7e6d0000, 0x00000000); |
| 60 | } |
| 61 | |
| 62 | static void test_sha384_sg_ast1030(void) |
| 63 | { |
| 64 | aspeed_test_sha384_sg("-machine ast1030-evb", 0x7e6d0000, 0x00000000); |
| 65 | } |
| 66 | |
| 67 | static void test_sha512_ast1030(void) |
| 68 | { |
| 69 | aspeed_test_sha512("-machine ast1030-evb", 0x7e6d0000, 0x00000000); |
| 70 | } |
| 71 | |
| 72 | static void test_sha512_sg_ast1030(void) |
| 73 | { |
| 74 | aspeed_test_sha512_sg("-machine ast1030-evb", 0x7e6d0000, 0x00000000); |
| 75 | } |
| 76 | |
| 77 | static void test_sha256_accum_ast1030(void) |
| 78 | { |
| 79 | aspeed_test_sha256_accum("-machine ast1030-evb", 0x7e6d0000, 0x00000000); |
| 80 | } |
| 81 | |
| 82 | static void test_sha384_accum_ast1030(void) |
| 83 | { |
| 84 | aspeed_test_sha384_accum("-machine ast1030-evb", 0x7e6d0000, 0x00000000); |
| 85 | } |
| 86 | |
| 87 | static void test_sha512_accum_ast1030(void) |
| 88 | { |
| 89 | aspeed_test_sha512_accum("-machine ast1030-evb", 0x7e6d0000, 0x00000000); |
| 90 | } |
| 91 | |
| 92 | static void test_addresses_ast1030(void) |
| 93 | { |
| 94 | aspeed_test_addresses("-machine ast1030-evb", 0x7e6d0000, &ast1030_masks); |
| 95 | } |
| 96 | |
| 97 | /* ast2600 */ |
| 98 | static void test_md5_ast2600(void) |
| 99 | { |
| 100 | aspeed_test_md5("-machine ast2600-evb", 0x1e6d0000, 0x80000000); |
| 101 | } |
| 102 | |
| 103 | static void test_sha256_ast2600(void) |
| 104 | { |
| 105 | aspeed_test_sha256("-machine ast2600-evb", 0x1e6d0000, 0x80000000); |
| 106 | } |
| 107 | |
| 108 | static void test_sha256_sg_ast2600(void) |
| 109 | { |
| 110 | aspeed_test_sha256_sg("-machine ast2600-evb", 0x1e6d0000, 0x80000000); |
| 111 | } |
| 112 | |
| 113 | static void test_sha384_ast2600(void) |
| 114 | { |
| 115 | aspeed_test_sha384("-machine ast2600-evb", 0x1e6d0000, 0x80000000); |
| 116 | } |
| 117 | |
| 118 | static void test_sha384_sg_ast2600(void) |
| 119 | { |
| 120 | aspeed_test_sha384_sg("-machine ast2600-evb", 0x1e6d0000, 0x80000000); |
| 121 | } |
| 122 | |
| 123 | static void test_sha512_ast2600(void) |
| 124 | { |
| 125 | aspeed_test_sha512("-machine ast2600-evb", 0x1e6d0000, 0x80000000); |
| 126 | } |
| 127 | |
| 128 | static void test_sha512_sg_ast2600(void) |
| 129 | { |
| 130 | aspeed_test_sha512_sg("-machine ast2600-evb", 0x1e6d0000, 0x80000000); |
| 131 | } |
| 132 | |
| 133 | static void test_sha256_accum_ast2600(void) |
| 134 | { |
| 135 | aspeed_test_sha256_accum("-machine ast2600-evb", 0x1e6d0000, 0x80000000); |
| 136 | } |
| 137 | |
| 138 | static void test_sha384_accum_ast2600(void) |
| 139 | { |
| 140 | aspeed_test_sha384_accum("-machine ast2600-evb", 0x1e6d0000, 0x80000000); |
| 141 | } |
| 142 | |
| 143 | static void test_sha512_accum_ast2600(void) |
| 144 | { |
| 145 | aspeed_test_sha512_accum("-machine ast2600-evb", 0x1e6d0000, 0x80000000); |
| 146 | } |
| 147 | |
| 148 | static void test_addresses_ast2600(void) |
| 149 | { |
| 150 | aspeed_test_addresses("-machine ast2600-evb", 0x1e6d0000, &ast2600_masks); |
| 151 | } |
| 152 | |
| 153 | /* ast2500 */ |
| 154 | static void test_md5_ast2500(void) |
| 155 | { |
| 156 | aspeed_test_md5("-machine ast2500-evb", 0x1e6e3000, 0x80000000); |
| 157 | } |
| 158 | |
| 159 | static void test_sha256_ast2500(void) |
| 160 | { |
| 161 | aspeed_test_sha256("-machine ast2500-evb", 0x1e6e3000, 0x80000000); |
| 162 | } |
| 163 | |
| 164 | static void test_sha512_ast2500(void) |
| 165 | { |
| 166 | aspeed_test_sha512("-machine ast2500-evb", 0x1e6e3000, 0x80000000); |
| 167 | } |
| 168 | |
| 169 | static void test_addresses_ast2500(void) |
| 170 | { |
| 171 | aspeed_test_addresses("-machine ast2500-evb", 0x1e6e3000, &ast2500_masks); |
| 172 | } |
| 173 | |
| 174 | /* ast2400 */ |
| 175 | static void test_md5_ast2400(void) |
| 176 | { |
| 177 | aspeed_test_md5("-machine palmetto-bmc", 0x1e6e3000, 0x40000000); |
| 178 | } |
| 179 | |
| 180 | static void test_sha256_ast2400(void) |
| 181 | { |
| 182 | aspeed_test_sha256("-machine palmetto-bmc", 0x1e6e3000, 0x40000000); |
| 183 | } |
| 184 | |
| 185 | static void test_sha512_ast2400(void) |
| 186 | { |
| 187 | aspeed_test_sha512("-machine palmetto-bmc", 0x1e6e3000, 0x40000000); |
| 188 | } |
| 189 | |
| 190 | static void test_addresses_ast2400(void) |
| 191 | { |
| 192 | aspeed_test_addresses("-machine palmetto-bmc", 0x1e6e3000, &ast2400_masks); |
| 193 | } |
| 194 | |
| 195 | int main(int argc, char **argv) |
| 196 | { |
| 197 | g_test_init(&argc, &argv, NULL); |
| 198 | |
| 199 | qtest_add_func("ast1030/hace/addresses", test_addresses_ast1030); |
| 200 | qtest_add_func("ast1030/hace/sha512", test_sha512_ast1030); |
| 201 | qtest_add_func("ast1030/hace/sha384", test_sha384_ast1030); |
| 202 | qtest_add_func("ast1030/hace/sha256", test_sha256_ast1030); |
| 203 | qtest_add_func("ast1030/hace/md5", test_md5_ast1030); |
| 204 | |
| 205 | qtest_add_func("ast1030/hace/sha512_sg", test_sha512_sg_ast1030); |
| 206 | qtest_add_func("ast1030/hace/sha384_sg", test_sha384_sg_ast1030); |
| 207 | qtest_add_func("ast1030/hace/sha256_sg", test_sha256_sg_ast1030); |
| 208 | |
| 209 | qtest_add_func("ast1030/hace/sha512_accum", test_sha512_accum_ast1030); |
| 210 | qtest_add_func("ast1030/hace/sha384_accum", test_sha384_accum_ast1030); |
| 211 | qtest_add_func("ast1030/hace/sha256_accum", test_sha256_accum_ast1030); |
| 212 | |
| 213 | /* The AST1030 reuses the AST2600 crypto engine (scatter-gather, CTR). */ |
| 214 | aspeed_add_crypto_tests("ast1030", "-machine ast1030-evb", 0x7e6d0000, |
| 215 | 0x00000000, |
| 216 | CRYPT_MODE_ECB | CRYPT_MODE_CBC | CRYPT_MODE_CTR, |
| 217 | true); |
| 218 | |
| 219 | qtest_add_func("ast2600/hace/addresses", test_addresses_ast2600); |
| 220 | qtest_add_func("ast2600/hace/sha512", test_sha512_ast2600); |
| 221 | qtest_add_func("ast2600/hace/sha384", test_sha384_ast2600); |
| 222 | qtest_add_func("ast2600/hace/sha256", test_sha256_ast2600); |
| 223 | qtest_add_func("ast2600/hace/md5", test_md5_ast2600); |
| 224 | |
| 225 | qtest_add_func("ast2600/hace/sha512_sg", test_sha512_sg_ast2600); |
| 226 | qtest_add_func("ast2600/hace/sha384_sg", test_sha384_sg_ast2600); |
| 227 | qtest_add_func("ast2600/hace/sha256_sg", test_sha256_sg_ast2600); |
| 228 | |
| 229 | qtest_add_func("ast2600/hace/sha512_accum", test_sha512_accum_ast2600); |
| 230 | qtest_add_func("ast2600/hace/sha384_accum", test_sha384_accum_ast2600); |
| 231 | qtest_add_func("ast2600/hace/sha256_accum", test_sha256_accum_ast2600); |
| 232 | |
| 233 | /* The AST2600 crypto engine uses scatter-gather mode and adds CTR. */ |
| 234 | aspeed_add_crypto_tests("ast2600", "-machine ast2600-evb", 0x1e6d0000, |
| 235 | 0x80000000, |
| 236 | CRYPT_MODE_ECB | CRYPT_MODE_CBC | CRYPT_MODE_CTR, |
| 237 | true); |
| 238 | |
| 239 | qtest_add_func("ast2500/hace/addresses", test_addresses_ast2500); |
| 240 | qtest_add_func("ast2500/hace/sha512", test_sha512_ast2500); |
| 241 | qtest_add_func("ast2500/hace/sha256", test_sha256_ast2500); |
| 242 | qtest_add_func("ast2500/hace/md5", test_md5_ast2500); |
| 243 | |
| 244 | /* |
| 245 | * The AST2500 crypto engine uses direct access mode and supports ECB/CBC. |
| 246 | */ |
| 247 | aspeed_add_crypto_tests("ast2500", "-machine ast2500-evb", 0x1e6e3000, |
| 248 | 0x80000000, CRYPT_MODE_ECB | CRYPT_MODE_CBC, false); |
| 249 | |
| 250 | qtest_add_func("ast2400/hace/addresses", test_addresses_ast2400); |
| 251 | qtest_add_func("ast2400/hace/sha512", test_sha512_ast2400); |
| 252 | qtest_add_func("ast2400/hace/sha256", test_sha256_ast2400); |
| 253 | qtest_add_func("ast2400/hace/md5", test_md5_ast2400); |
| 254 | |
| 255 | return g_test_run(); |
| 256 | } |