1*67e74705SXin Li /*===---- __wmmintrin_aes.h - AES intrinsics -------------------------------===
2*67e74705SXin Li *
3*67e74705SXin Li * Permission is hereby granted, free of charge, to any person obtaining a copy
4*67e74705SXin Li * of this software and associated documentation files (the "Software"), to deal
5*67e74705SXin Li * in the Software without restriction, including without limitation the rights
6*67e74705SXin Li * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*67e74705SXin Li * copies of the Software, and to permit persons to whom the Software is
8*67e74705SXin Li * furnished to do so, subject to the following conditions:
9*67e74705SXin Li *
10*67e74705SXin Li * The above copyright notice and this permission notice shall be included in
11*67e74705SXin Li * all copies or substantial portions of the Software.
12*67e74705SXin Li *
13*67e74705SXin Li * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14*67e74705SXin Li * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15*67e74705SXin Li * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16*67e74705SXin Li * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17*67e74705SXin Li * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18*67e74705SXin Li * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19*67e74705SXin Li * THE SOFTWARE.
20*67e74705SXin Li *
21*67e74705SXin Li *===-----------------------------------------------------------------------===
22*67e74705SXin Li */
23*67e74705SXin Li #ifndef _WMMINTRIN_AES_H
24*67e74705SXin Li #define _WMMINTRIN_AES_H
25*67e74705SXin Li
26*67e74705SXin Li #include <emmintrin.h>
27*67e74705SXin Li
28*67e74705SXin Li /* Define the default attributes for the functions in this file. */
29*67e74705SXin Li #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("aes")))
30*67e74705SXin Li
31*67e74705SXin Li /// \brief Performs a single round of AES encryption using the Equivalent
32*67e74705SXin Li /// Inverse Cipher, transforming the state value from the first source
33*67e74705SXin Li /// operand using a 128-bit round key value contained in the second source
34*67e74705SXin Li /// operand, and writes the result to the destination.
35*67e74705SXin Li ///
36*67e74705SXin Li /// \headerfile <x86intrin.h>
37*67e74705SXin Li ///
38*67e74705SXin Li /// This intrinsic corresponds to the \c VAESENC instruction.
39*67e74705SXin Li ///
40*67e74705SXin Li /// \param __V
41*67e74705SXin Li /// A 128-bit integer vector containing the state value.
42*67e74705SXin Li /// \param __R
43*67e74705SXin Li /// A 128-bit integer vector containing the round key value.
44*67e74705SXin Li /// \returns A 128-bit integer vector containing the encrypted value.
45*67e74705SXin Li static __inline__ __m128i __DEFAULT_FN_ATTRS
_mm_aesenc_si128(__m128i __V,__m128i __R)46*67e74705SXin Li _mm_aesenc_si128(__m128i __V, __m128i __R)
47*67e74705SXin Li {
48*67e74705SXin Li return (__m128i)__builtin_ia32_aesenc128((__v2di)__V, (__v2di)__R);
49*67e74705SXin Li }
50*67e74705SXin Li
51*67e74705SXin Li /// \brief Performs the final round of AES encryption using the Equivalent
52*67e74705SXin Li /// Inverse Cipher, transforming the state value from the first source
53*67e74705SXin Li /// operand using a 128-bit round key value contained in the second source
54*67e74705SXin Li /// operand, and writes the result to the destination.
55*67e74705SXin Li ///
56*67e74705SXin Li /// \headerfile <x86intrin.h>
57*67e74705SXin Li ///
58*67e74705SXin Li /// This intrinsic corresponds to the \c VAESENCLAST instruction.
59*67e74705SXin Li ///
60*67e74705SXin Li /// \param __V
61*67e74705SXin Li /// A 128-bit integer vector containing the state value.
62*67e74705SXin Li /// \param __R
63*67e74705SXin Li /// A 128-bit integer vector containing the round key value.
64*67e74705SXin Li /// \returns A 128-bit integer vector containing the encrypted value.
65*67e74705SXin Li static __inline__ __m128i __DEFAULT_FN_ATTRS
_mm_aesenclast_si128(__m128i __V,__m128i __R)66*67e74705SXin Li _mm_aesenclast_si128(__m128i __V, __m128i __R)
67*67e74705SXin Li {
68*67e74705SXin Li return (__m128i)__builtin_ia32_aesenclast128((__v2di)__V, (__v2di)__R);
69*67e74705SXin Li }
70*67e74705SXin Li
71*67e74705SXin Li /// \brief Performs a single round of AES decryption using the Equivalent
72*67e74705SXin Li /// Inverse Cipher, transforming the state value from the first source
73*67e74705SXin Li /// operand using a 128-bit round key value contained in the second source
74*67e74705SXin Li /// operand, and writes the result to the destination.
75*67e74705SXin Li ///
76*67e74705SXin Li /// \headerfile <x86intrin.h>
77*67e74705SXin Li ///
78*67e74705SXin Li /// This intrinsic corresponds to the \c VAESDEC instruction.
79*67e74705SXin Li ///
80*67e74705SXin Li /// \param __V
81*67e74705SXin Li /// A 128-bit integer vector containing the state value.
82*67e74705SXin Li /// \param __R
83*67e74705SXin Li /// A 128-bit integer vector containing the round key value.
84*67e74705SXin Li /// \returns A 128-bit integer vector containing the decrypted value.
85*67e74705SXin Li static __inline__ __m128i __DEFAULT_FN_ATTRS
_mm_aesdec_si128(__m128i __V,__m128i __R)86*67e74705SXin Li _mm_aesdec_si128(__m128i __V, __m128i __R)
87*67e74705SXin Li {
88*67e74705SXin Li return (__m128i)__builtin_ia32_aesdec128((__v2di)__V, (__v2di)__R);
89*67e74705SXin Li }
90*67e74705SXin Li
91*67e74705SXin Li /// \brief Performs the final round of AES decryption using the Equivalent
92*67e74705SXin Li /// Inverse Cipher, transforming the state value from the first source
93*67e74705SXin Li /// operand using a 128-bit round key value contained in the second source
94*67e74705SXin Li /// operand, and writes the result to the destination.
95*67e74705SXin Li ///
96*67e74705SXin Li /// \headerfile <x86intrin.h>
97*67e74705SXin Li ///
98*67e74705SXin Li /// This intrinsic corresponds to the \c VAESDECLAST instruction.
99*67e74705SXin Li ///
100*67e74705SXin Li /// \param __V
101*67e74705SXin Li /// A 128-bit integer vector containing the state value.
102*67e74705SXin Li /// \param __R
103*67e74705SXin Li /// A 128-bit integer vector containing the round key value.
104*67e74705SXin Li /// \returns A 128-bit integer vector containing the decrypted value.
105*67e74705SXin Li static __inline__ __m128i __DEFAULT_FN_ATTRS
_mm_aesdeclast_si128(__m128i __V,__m128i __R)106*67e74705SXin Li _mm_aesdeclast_si128(__m128i __V, __m128i __R)
107*67e74705SXin Li {
108*67e74705SXin Li return (__m128i)__builtin_ia32_aesdeclast128((__v2di)__V, (__v2di)__R);
109*67e74705SXin Li }
110*67e74705SXin Li
111*67e74705SXin Li /// \brief Applies the AES InvMixColumns() transformation to an expanded key
112*67e74705SXin Li /// contained in the source operand, and writes the result to the
113*67e74705SXin Li /// destination.
114*67e74705SXin Li ///
115*67e74705SXin Li /// \headerfile <x86intrin.h>
116*67e74705SXin Li ///
117*67e74705SXin Li /// This intrinsic corresponds to the \c VAESIMC instruction.
118*67e74705SXin Li ///
119*67e74705SXin Li /// \param __V
120*67e74705SXin Li /// A 128-bit integer vector containing the expanded key.
121*67e74705SXin Li /// \returns A 128-bit integer vector containing the transformed value.
122*67e74705SXin Li static __inline__ __m128i __DEFAULT_FN_ATTRS
_mm_aesimc_si128(__m128i __V)123*67e74705SXin Li _mm_aesimc_si128(__m128i __V)
124*67e74705SXin Li {
125*67e74705SXin Li return (__m128i)__builtin_ia32_aesimc128((__v2di)__V);
126*67e74705SXin Li }
127*67e74705SXin Li
128*67e74705SXin Li /// \brief Generates a round key for AES encyption, operating on 128-bit data
129*67e74705SXin Li /// specified in the first source operand and using an 8-bit round constant
130*67e74705SXin Li /// specified by the second source operand, and writes the result to the
131*67e74705SXin Li /// destination.
132*67e74705SXin Li ///
133*67e74705SXin Li /// \headerfile <x86intrin.h>
134*67e74705SXin Li ///
135*67e74705SXin Li /// \code
136*67e74705SXin Li /// __m128i _mm_aeskeygenassist_si128(__m128i C, const int R);
137*67e74705SXin Li /// \endcode
138*67e74705SXin Li ///
139*67e74705SXin Li /// This intrinsic corresponds to the \c AESKEYGENASSIST instruction.
140*67e74705SXin Li ///
141*67e74705SXin Li /// \param C
142*67e74705SXin Li /// A 128-bit integer vector that is used to generate the AES encryption key.
143*67e74705SXin Li /// \param R
144*67e74705SXin Li /// An 8-bit round constant used to generate the AES encryption key.
145*67e74705SXin Li /// \returns A 128-bit round key for AES encryption.
146*67e74705SXin Li #define _mm_aeskeygenassist_si128(C, R) \
147*67e74705SXin Li (__m128i)__builtin_ia32_aeskeygenassist128((__v2di)(__m128i)(C), (int)(R))
148*67e74705SXin Li
149*67e74705SXin Li #undef __DEFAULT_FN_ATTRS
150*67e74705SXin Li
151*67e74705SXin Li #endif /* _WMMINTRIN_AES_H */
152