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