__wmmintrin_aes.h 6.0 KB

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