| 1 | /* |
| 2 | * QTest testcase for the ASPEED Hash and Crypto Engine |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 5 | * Copyright (C) 2025 ASPEED Technology Inc. |
| 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 as2700_masks = { |
| 14 | .src = 0x7fffffff, |
| 15 | .dest = 0x7ffffff8, |
| 16 | .key = 0x7ffffff8, |
| 17 | .len = 0x0fffffff, |
| 18 | .src_hi = 0x00000003, |
| 19 | .dest_hi = 0x00000003, |
| 20 | .key_hi = 0x00000003, |
| 21 | }; |
| 22 | |
| 23 | /* ast2700 */ |
| 24 | static void test_md5_ast2700(void) |
| 25 | { |
| 26 | aspeed_test_md5("-machine ast2700-evb", 0x12070000, 0x400000000); |
| 27 | } |
| 28 | |
| 29 | static void test_sha256_ast2700(void) |
| 30 | { |
| 31 | aspeed_test_sha256("-machine ast2700-evb", 0x12070000, 0x400000000); |
| 32 | } |
| 33 | |
| 34 | static void test_sha256_sg_ast2700(void) |
| 35 | { |
| 36 | aspeed_test_sha256_sg("-machine ast2700-evb", 0x12070000, 0x400000000); |
| 37 | } |
| 38 | |
| 39 | static void test_sha384_ast2700(void) |
| 40 | { |
| 41 | aspeed_test_sha384("-machine ast2700-evb", 0x12070000, 0x400000000); |
| 42 | } |
| 43 | |
| 44 | static void test_sha384_sg_ast2700(void) |
| 45 | { |
| 46 | aspeed_test_sha384_sg("-machine ast2700-evb", 0x12070000, 0x400000000); |
| 47 | } |
| 48 | |
| 49 | static void test_sha512_ast2700(void) |
| 50 | { |
| 51 | aspeed_test_sha512("-machine ast2700-evb", 0x12070000, 0x400000000); |
| 52 | } |
| 53 | |
| 54 | static void test_sha512_sg_ast2700(void) |
| 55 | { |
| 56 | aspeed_test_sha512_sg("-machine ast2700-evb", 0x12070000, 0x400000000); |
| 57 | } |
| 58 | |
| 59 | static void test_sha256_accum_ast2700(void) |
| 60 | { |
| 61 | aspeed_test_sha256_accum("-machine ast2700-evb", 0x12070000, 0x400000000); |
| 62 | } |
| 63 | |
| 64 | static void test_sha384_accum_ast2700(void) |
| 65 | { |
| 66 | aspeed_test_sha384_accum("-machine ast2700-evb", 0x12070000, 0x400000000); |
| 67 | } |
| 68 | |
| 69 | static void test_sha512_accum_ast2700(void) |
| 70 | { |
| 71 | aspeed_test_sha512_accum("-machine ast2700-evb", 0x12070000, 0x400000000); |
| 72 | } |
| 73 | |
| 74 | static void test_addresses_ast2700(void) |
| 75 | { |
| 76 | aspeed_test_addresses("-machine ast2700-evb", 0x12070000, &as2700_masks); |
| 77 | } |
| 78 | |
| 79 | int main(int argc, char **argv) |
| 80 | { |
| 81 | g_test_init(&argc, &argv, NULL); |
| 82 | |
| 83 | qtest_add_func("ast2700/hace/addresses", test_addresses_ast2700); |
| 84 | qtest_add_func("ast2700/hace/sha512", test_sha512_ast2700); |
| 85 | qtest_add_func("ast2700/hace/sha384", test_sha384_ast2700); |
| 86 | qtest_add_func("ast2700/hace/sha256", test_sha256_ast2700); |
| 87 | qtest_add_func("ast2700/hace/md5", test_md5_ast2700); |
| 88 | |
| 89 | qtest_add_func("ast2700/hace/sha512_sg", test_sha512_sg_ast2700); |
| 90 | qtest_add_func("ast2700/hace/sha384_sg", test_sha384_sg_ast2700); |
| 91 | qtest_add_func("ast2700/hace/sha256_sg", test_sha256_sg_ast2700); |
| 92 | |
| 93 | qtest_add_func("ast2700/hace/sha512_accum", test_sha512_accum_ast2700); |
| 94 | qtest_add_func("ast2700/hace/sha384_accum", test_sha384_accum_ast2700); |
| 95 | qtest_add_func("ast2700/hace/sha256_accum", test_sha256_accum_ast2700); |
| 96 | |
| 97 | /* |
| 98 | * The AST2700 crypto engine uses scatter-gather with 64-bit DMA and adds |
| 99 | * AES-GCM on top of the ECB/CBC/CTR modes shared with the AST2600. |
| 100 | */ |
| 101 | aspeed_add_crypto_tests("ast2700", "-machine ast2700-evb", 0x12070000, |
| 102 | 0x400000000, |
| 103 | CRYPT_MODE_ECB | CRYPT_MODE_CBC | CRYPT_MODE_CTR | |
| 104 | CRYPT_MODE_GCM, true); |
| 105 | |
| 106 | return g_test_run(); |
| 107 | } |