aesni-mingw-i386.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. diff --git a/library/aesni.c b/library/aesni.c
  2. index 59bcd3d92..b92c73c29 100644
  3. --- a/library/aesni.c
  4. +++ b/library/aesni.c
  5. @@ -21,14 +21,27 @@
  6. #if defined(MBEDTLS_AESNI_HAVE_CODE)
  7. #if MBEDTLS_AESNI_HAVE_CODE == 2
  8. -#if !defined(_WIN32)
  9. +#if defined(__GNUC__)
  10. #include <cpuid.h>
  11. -#else
  12. +#elif defined(_MSC_VER)
  13. #include <intrin.h>
  14. +#else
  15. +#error "`__cpuid` required by MBEDTLS_AESNI_C is not supported by the compiler"
  16. #endif
  17. #include <immintrin.h>
  18. #endif
  19. +#if defined(MBEDTLS_ARCH_IS_X86)
  20. +#if defined(MBEDTLS_COMPILER_IS_GCC)
  21. +#pragma GCC push_options
  22. +#pragma GCC target ("pclmul,sse2,aes")
  23. +#define MBEDTLS_POP_TARGET_PRAGMA
  24. +#elif defined(__clang__)
  25. +#pragma clang attribute push (__attribute__((target("pclmul,sse2,aes"))), apply_to=function)
  26. +#define MBEDTLS_POP_TARGET_PRAGMA
  27. +#endif
  28. +#endif
  29. +
  30. #if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
  31. /*
  32. * AES-NI support detection routine
  33. @@ -40,7 +53,7 @@ int mbedtls_aesni_has_support(unsigned int what)
  34. if (!done) {
  35. #if MBEDTLS_AESNI_HAVE_CODE == 2
  36. - static unsigned info[4] = { 0, 0, 0, 0 };
  37. + static int info[4] = { 0, 0, 0, 0 };
  38. #if defined(_MSC_VER)
  39. __cpuid(info, 1);
  40. #else
  41. @@ -175,7 +188,7 @@ void mbedtls_aesni_gcm_mult(unsigned char c[16],
  42. const unsigned char a[16],
  43. const unsigned char b[16])
  44. {
  45. - __m128i aa, bb, cc, dd;
  46. + __m128i aa = { 0 }, bb = { 0 }, cc, dd;
  47. /* The inputs are in big-endian order, so byte-reverse them */
  48. for (size_t i = 0; i < 16; i++) {
  49. @@ -384,6 +397,15 @@ static void aesni_setkey_enc_256(unsigned char *rk_bytes,
  50. }
  51. #endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
  52. +#if defined(MBEDTLS_POP_TARGET_PRAGMA)
  53. +#if defined(__clang__)
  54. +#pragma clang attribute pop
  55. +#elif defined(__GNUC__)
  56. +#pragma GCC pop_options
  57. +#endif
  58. +#undef MBEDTLS_POP_TARGET_PRAGMA
  59. +#endif
  60. +
  61. #else /* MBEDTLS_AESNI_HAVE_CODE == 1 */
  62. #if defined(__has_feature)