xref: /openbmc/qemu/tests/tcg/riscv64/test-aes.c (revision 3ef11c99)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "../multiarch/test-aes-main.c.inc"
4 
5 bool test_SB_SR(uint8_t *o, const uint8_t *i)
6 {
7     uint64_t *o8 = (uint64_t *)o;
8     const uint64_t *i8 = (const uint64_t *)i;
9 
10     /* aes64es rd, rs1, rs2 = 0011001 rs2 rs1 000 rd 0110011 */
11     asm(".insn r 0x33, 0x0, 0x19, %0, %2, %3\n\t"
12         ".insn r 0x33, 0x0, 0x19, %1, %3, %2"
13         : "=&r"(o8[0]), "=&r"(o8[1]) : "r"(i8[0]), "r"(i8[1]));
14     return true;
15 }
16 
17 bool test_MC(uint8_t *o, const uint8_t *i)
18 {
19     return false;
20 }
21 
22 bool test_SB_SR_MC_AK(uint8_t *o, const uint8_t *i, const uint8_t *k)
23 {
24     uint64_t *o8 = (uint64_t *)o;
25     const uint64_t *i8 = (const uint64_t *)i;
26     const uint64_t *k8 = (const uint64_t *)k;
27 
28     /* aesesm rd, rs1, rs2 = 0011011 rs2 rs1 000 rd 0110011 */
29     asm(".insn r 0x33, 0x0, 0x1b, %0, %2, %3\n\t"
30         ".insn r 0x33, 0x0, 0x1b, %1, %3, %2\n\t"
31         "xor %0,%0,%4\n\t"
32         "xor %1,%1,%5"
33         : "=&r"(o8[0]), "=&r"(o8[1])
34         : "r"(i8[0]), "r"(i8[1]), "r"(k8[0]), "r"(k8[1]));
35     return true;
36 }
37 
38 bool test_ISB_ISR(uint8_t *o, const uint8_t *i)
39 {
40     uint64_t *o8 = (uint64_t *)o;
41     const uint64_t *i8 = (const uint64_t *)i;
42 
43     /* aes64ds rd, rs1, rs2 = 0011101 rs2 rs1 000 rd 0110011 */
44     asm(".insn r 0x33, 0x0, 0x1d, %0, %2, %3\n\t"
45         ".insn r 0x33, 0x0, 0x1d, %1, %3, %2"
46         : "=&r"(o8[0]), "=&r"(o8[1]) : "r"(i8[0]), "r"(i8[1]));
47     return true;
48 }
49 
50 bool test_IMC(uint8_t *o, const uint8_t *i)
51 {
52     uint64_t *o8 = (uint64_t *)o;
53     const uint64_t *i8 = (const uint64_t *)i;
54 
55     /* aes64im rd, rs1 = 0011000 00000 rs1 001 rd 0010011 */
56     asm(".insn r 0x13, 0x1, 0x18, %0, %0, x0\n\t"
57         ".insn r 0x13, 0x1, 0x18, %1, %1, x0"
58         : "=r"(o8[0]), "=r"(o8[1]) : "0"(i8[0]), "1"(i8[1]));
59     return true;
60 }
61 
62 bool test_ISB_ISR_AK_IMC(uint8_t *o, const uint8_t *i, const uint8_t *k)
63 {
64     return false;
65 }
66 
67 bool test_ISB_ISR_IMC_AK(uint8_t *o, const uint8_t *i, const uint8_t *k)
68 {
69     uint64_t *o8 = (uint64_t *)o;
70     const uint64_t *i8 = (const uint64_t *)i;
71     const uint64_t *k8 = (const uint64_t *)k;
72 
73     /* aes64dsm rd, rs1, rs2 = 0011111 rs2 rs1 000 rd 0110011 */
74     asm(".insn r 0x33, 0x0, 0x1f, %0, %2, %3\n\t"
75         ".insn r 0x33, 0x0, 0x1f, %1, %3, %2\n\t"
76         "xor %0,%0,%4\n\t"
77         "xor %1,%1,%5"
78         : "=&r"(o8[0]), "=&r"(o8[1])
79         : "r"(i8[0]), "r"(i8[1]), "r"(k8[0]), "r"(k8[1]));
80     return true;
81 }
82