xref: /openbmc/qemu/tests/tcg/i386/test-aes.c (revision 784155cd)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "../multiarch/test-aes-main.c.inc"
4 #include <immintrin.h>
5 
6 static bool test_SB_SR(uint8_t *o, const uint8_t *i)
7 {
8     __m128i vi = _mm_loadu_si128((const __m128i_u *)i);
9 
10     /* aesenclast also adds round key, so supply zero. */
11     vi = _mm_aesenclast_si128(vi, _mm_setzero_si128());
12 
13     _mm_storeu_si128((__m128i_u *)o, vi);
14     return true;
15 }
16 
17 static bool test_MC(uint8_t *o, const uint8_t *i)
18 {
19     return false;
20 }
21 
22 static bool test_SB_SR_MC_AK(uint8_t *o, const uint8_t *i, const uint8_t *k)
23 {
24     __m128i vi = _mm_loadu_si128((const __m128i_u *)i);
25     __m128i vk = _mm_loadu_si128((const __m128i_u *)k);
26 
27     vi = _mm_aesenc_si128(vi, vk);
28 
29     _mm_storeu_si128((__m128i_u *)o, vi);
30     return true;
31 }
32 
33 static bool test_ISB_ISR(uint8_t *o, const uint8_t *i)
34 {
35     __m128i vi = _mm_loadu_si128((const __m128i_u *)i);
36 
37     /* aesdeclast also adds round key, so supply zero. */
38     vi = _mm_aesdeclast_si128(vi, _mm_setzero_si128());
39 
40     _mm_storeu_si128((__m128i_u *)o, vi);
41     return true;
42 }
43 
44 static bool test_IMC(uint8_t *o, const uint8_t *i)
45 {
46     __m128i vi = _mm_loadu_si128((const __m128i_u *)i);
47 
48     vi = _mm_aesimc_si128(vi);
49 
50     _mm_storeu_si128((__m128i_u *)o, vi);
51     return true;
52 }
53 
54 static bool test_ISB_ISR_AK_IMC(uint8_t *o, const uint8_t *i, const uint8_t *k)
55 {
56     return false;
57 }
58 
59 static bool test_ISB_ISR_IMC_AK(uint8_t *o, const uint8_t *i, const uint8_t *k)
60 {
61     __m128i vi = _mm_loadu_si128((const __m128i_u *)i);
62     __m128i vk = _mm_loadu_si128((const __m128i_u *)k);
63 
64     vi = _mm_aesdec_si128(vi, vk);
65 
66     _mm_storeu_si128((__m128i_u *)o, vi);
67     return true;
68 }
69