1/*===---- __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 */ 23#ifndef _WMMINTRIN_AES_H 24#define _WMMINTRIN_AES_H 25 26#include <emmintrin.h> 27 28/* Define the default attributes for the functions in this file. */ 29#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("aes"))) 30 31/// \brief Performs a single round of AES encryption using the Equivalent 32/// Inverse Cipher, transforming the state value from the first source 33/// operand using a 128-bit round key value contained in the second source 34/// operand, and writes the result to the destination. 35/// 36/// \headerfile <x86intrin.h> 37/// 38/// This intrinsic corresponds to the \c VAESENC instruction. 39/// 40/// \param __V 41/// A 128-bit integer vector containing the state value. 42/// \param __R 43/// A 128-bit integer vector containing the round key value. 44/// \returns A 128-bit integer vector containing the encrypted value. 45static __inline__ __m128i __DEFAULT_FN_ATTRS 46_mm_aesenc_si128(__m128i __V, __m128i __R) 47{ 48 return (__m128i)__builtin_ia32_aesenc128((__v2di)__V, (__v2di)__R); 49} 50 51/// \brief Performs the final round of AES encryption using the Equivalent 52/// Inverse Cipher, transforming the state value from the first source 53/// operand using a 128-bit round key value contained in the second source 54/// operand, and writes the result to the destination. 55/// 56/// \headerfile <x86intrin.h> 57/// 58/// This intrinsic corresponds to the \c VAESENCLAST instruction. 59/// 60/// \param __V 61/// A 128-bit integer vector containing the state value. 62/// \param __R 63/// A 128-bit integer vector containing the round key value. 64/// \returns A 128-bit integer vector containing the encrypted value. 65static __inline__ __m128i __DEFAULT_FN_ATTRS 66_mm_aesenclast_si128(__m128i __V, __m128i __R) 67{ 68 return (__m128i)__builtin_ia32_aesenclast128((__v2di)__V, (__v2di)__R); 69} 70 71/// \brief Performs a single round of AES decryption using the Equivalent 72/// Inverse Cipher, transforming the state value from the first source 73/// operand using a 128-bit round key value contained in the second source 74/// operand, and writes the result to the destination. 75/// 76/// \headerfile <x86intrin.h> 77/// 78/// This intrinsic corresponds to the \c VAESDEC instruction. 79/// 80/// \param __V 81/// A 128-bit integer vector containing the state value. 82/// \param __R 83/// A 128-bit integer vector containing the round key value. 84/// \returns A 128-bit integer vector containing the decrypted value. 85static __inline__ __m128i __DEFAULT_FN_ATTRS 86_mm_aesdec_si128(__m128i __V, __m128i __R) 87{ 88 return (__m128i)__builtin_ia32_aesdec128((__v2di)__V, (__v2di)__R); 89} 90 91/// \brief Performs the final round of AES decryption using the Equivalent 92/// Inverse Cipher, transforming the state value from the first source 93/// operand using a 128-bit round key value contained in the second source 94/// operand, and writes the result to the destination. 95/// 96/// \headerfile <x86intrin.h> 97/// 98/// This intrinsic corresponds to the \c VAESDECLAST instruction. 99/// 100/// \param __V 101/// A 128-bit integer vector containing the state value. 102/// \param __R 103/// A 128-bit integer vector containing the round key value. 104/// \returns A 128-bit integer vector containing the decrypted value. 105static __inline__ __m128i __DEFAULT_FN_ATTRS 106_mm_aesdeclast_si128(__m128i __V, __m128i __R) 107{ 108 return (__m128i)__builtin_ia32_aesdeclast128((__v2di)__V, (__v2di)__R); 109} 110 111/// \brief Applies the AES InvMixColumns() transformation to an expanded key 112/// contained in the source operand, and writes the result to the 113/// destination. 114/// 115/// \headerfile <x86intrin.h> 116/// 117/// This intrinsic corresponds to the \c VAESIMC instruction. 118/// 119/// \param __V 120/// A 128-bit integer vector containing the expanded key. 121/// \returns A 128-bit integer vector containing the transformed value. 122static __inline__ __m128i __DEFAULT_FN_ATTRS 123_mm_aesimc_si128(__m128i __V) 124{ 125 return (__m128i)__builtin_ia32_aesimc128((__v2di)__V); 126} 127 128/// \brief Generates a round key for AES encyption, operating on 128-bit data 129/// specified in the first source operand and using an 8-bit round constant 130/// specified by the second source operand, and writes the result to the 131/// destination. 132/// 133/// \headerfile <x86intrin.h> 134/// 135/// \code 136/// __m128i _mm_aeskeygenassist_si128(__m128i C, const int R); 137/// \endcode 138/// 139/// This intrinsic corresponds to the \c AESKEYGENASSIST instruction. 140/// 141/// \param C 142/// A 128-bit integer vector that is used to generate the AES encryption key. 143/// \param R 144/// An 8-bit round constant used to generate the AES encryption key. 145/// \returns A 128-bit round key for AES encryption. 146#define _mm_aeskeygenassist_si128(C, R) \ 147 (__m128i)__builtin_ia32_aeskeygenassist128((__v2di)(__m128i)(C), (int)(R)) 148 149#undef __DEFAULT_FN_ATTRS 150 151#endif /* _WMMINTRIN_AES_H */ 152