__wmmintrin_aes.h 5.9 KB

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