Advertisement
Guest User

dirtyHackForCompilingCryptoppWithGcc49

a guest
May 28th, 2014
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.32 KB | None | 0 0
  1. commit 1e9c8cc4439edaa81aa33c12165b3ccca5b2ea25
  2. Author: Pierre Chevalier <pierrechevalier83@hotmail.fr>
  3. Date:   Thu May 29 02:11:19 2014 +0100
  4.  
  5.     Dirty Hack to get cryptopp to compile
  6.    
  7.     The new file: dirtyHackForGcc49.h
  8.     contains the relevant bits of gpu.h
  9.     that needs to be included in gcm.cpp and rijndael.cpp
  10.  
  11. diff --git a/src/third_party_libs/cryptopp/dirtyHackForGcc49.h b/src/third_party_libs/cryptopp/dirtyHackForGcc49.h
  12. new file mode 100644
  13. index 0000000..aa0c854
  14. --- /dev/null
  15. +++ b/src/third_party_libs/cryptopp/dirtyHackForGcc49.h
  16. @@ -0,0 +1,88 @@
  17. +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ > 8) // only if gcc 4.9 or higher
  18. +#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE
  19. +
  20. +#ifndef EXCLUDE_FIRST_HALF // This ones are redefined in rijndael.cpp if not excluded
  21. +#if !defined(__GNUC__) || defined(__SSSE3__) || defined(__INTEL_COMPILER)
  22. +#include <tmmintrin.h>
  23. +#else
  24. +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  25. +_mm_shuffle_epi8 (__m128i a, __m128i b)
  26. +{
  27. +   asm ("pshufb %1, %0" : "+x"(a) : "xm"(b));
  28. +   return a;
  29. +}
  30. +#endif
  31. +#if !defined(__GNUC__) || (defined(__AES__) && defined(__PCLMUL__)) || defined(__INTEL_COMPILER)
  32. +#include <wmmintrin.h>
  33. +#else
  34. +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  35. +_mm_clmulepi64_si128 (__m128i a, __m128i b, const int i)
  36. +{
  37. +   asm ("pclmulqdq %2, %1, %0" : "+x"(a) : "xm"(b), "i"(i));
  38. +   return a;
  39. +}
  40. +#endif
  41. +#endif // EXCLUDE_FIRST_HALF
  42. +
  43. +#if !defined(__GNUC__) || defined(__SSE4_1__) || defined(__INTEL_COMPILER)
  44. +#include <smmintrin.h>
  45. +#else
  46. +__inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  47. +_mm_extract_epi32 (__m128i a, const int i)
  48. +{
  49. +   int r;
  50. +   asm ("pextrd %2, %1, %0" : "=rm"(r) : "x"(a), "i"(i));
  51. +   return r;
  52. +}
  53. +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  54. +_mm_insert_epi32 (__m128i a, int b, const int i)
  55. +{
  56. +   asm ("pinsrd %2, %1, %0" : "+x"(a) : "rm"(b), "i"(i));
  57. +   return a;
  58. +}
  59. +#endif
  60. +#if !defined(__GNUC__) || (defined(__AES__) && defined(__PCLMUL__)) || defined(__INTEL_COMPILER)
  61. +#include <wmmintrin.h>
  62. +#else
  63. +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  64. +_mm_aeskeygenassist_si128 (__m128i a, const int i)
  65. +{
  66. +   __m128i r;
  67. +   asm ("aeskeygenassist %2, %1, %0" : "=x"(r) : "xm"(a), "i"(i));
  68. +   return r;
  69. +}
  70. +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  71. +_mm_aesimc_si128 (__m128i a)
  72. +{
  73. +   __m128i r;
  74. +   asm ("aesimc %1, %0" : "=x"(r) : "xm"(a));
  75. +   return r;
  76. +}
  77. +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  78. +_mm_aesenc_si128 (__m128i a, __m128i b)
  79. +{
  80. +   asm ("aesenc %1, %0" : "+x"(a) : "xm"(b));
  81. +   return a;
  82. +}
  83. +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  84. +_mm_aesenclast_si128 (__m128i a, __m128i b)
  85. +{
  86. +   asm ("aesenclast %1, %0" : "+x"(a) : "xm"(b));
  87. +   return a;
  88. +}
  89. +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  90. +_mm_aesdec_si128 (__m128i a, __m128i b)
  91. +{
  92. +   asm ("aesdec %1, %0" : "+x"(a) : "xm"(b));
  93. +   return a;
  94. +}
  95. +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  96. +_mm_aesdeclast_si128 (__m128i a, __m128i b)
  97. +{
  98. +   asm ("aesdeclast %1, %0" : "+x"(a) : "xm"(b));
  99. +   return a;
  100. +}
  101. +#endif
  102. +
  103. +#endif// CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE
  104. +#endif// gcc 4.9
  105. diff --git a/src/third_party_libs/cryptopp/gcm.cpp b/src/third_party_libs/cryptopp/gcm.cpp
  106. index 237325d..0969939 100644
  107. --- a/src/third_party_libs/cryptopp/gcm.cpp
  108. +++ b/src/third_party_libs/cryptopp/gcm.cpp
  109. @@ -85,6 +85,8 @@ static CRYPTOPP_ALIGN_DATA(16) const word64 s_clmulConstants64[] = {
  110.  static const __m128i *s_clmulConstants = (const __m128i *)s_clmulConstants64;
  111.  static const unsigned int s_clmulTableSizeInBlocks = 8;
  112.  
  113. +#include "dirtyHackForGcc49.h"
  114. +
  115.  inline __m128i CLMUL_Reduce(__m128i c0, __m128i c1, __m128i c2, const __m128i &r)
  116.  {
  117.     /*
  118. diff --git a/src/third_party_libs/cryptopp/rijndael.cpp b/src/third_party_libs/cryptopp/rijndael.cpp
  119. index c185032..20dc461 100644
  120. --- a/src/third_party_libs/cryptopp/rijndael.cpp
  121. +++ b/src/third_party_libs/cryptopp/rijndael.cpp
  122. @@ -195,6 +195,9 @@ void Rijndael::Base::FillDecTable()
  123.     s_TdFilled = true;
  124.  }
  125.  
  126. +#define EXCLUDE_FIRST_HALF
  127. +#include "dirtyHackForGcc49.h"
  128. +
  129.  void Rijndael::Base::UncheckedSetKey(const byte *userKey, unsigned int keylen, const NameValuePairs &)
  130.  {
  131.     AssertValidKeyLength(keylen);
  132.  
  133. commit dbaa3decd029cc8107fc8dbcc34f41792b9df98e
  134. Author: Pierre Chevalier <pierrechevalier83@hotmail.fr>
  135. Date:   Wed May 28 22:09:43 2014 +0100
  136.  
  137.     Fix crypto++ library for GCC 4.9 - part 1
  138.    
  139.     This part is as recommended by the gcc guys.
  140.     See http://sourceforge.net/apps/trac/cryptopp/ticket/33
  141.  
  142. diff --git a/src/third_party_libs/cryptopp/cpu.h b/src/third_party_libs/cryptopp/cpu.h
  143. index 65029d3..c890da9 100644
  144. --- a/src/third_party_libs/cryptopp/cpu.h
  145. +++ b/src/third_party_libs/cryptopp/cpu.h
  146. @@ -17,7 +17,7 @@
  147.  #endif
  148.  
  149.  #if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE
  150. -#if !defined(__GNUC__) || defined(__SSSE3__) || defined(__INTEL_COMPILER)
  151. +#if !defined(__GNUC__) || defined(__SSSE3__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ > 8) || defined(__INTEL_COMPILER)
  152.  #include <tmmintrin.h>
  153.  #else
  154.  __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  155. @@ -27,7 +27,7 @@ _mm_shuffle_epi8 (__m128i a, __m128i b)
  156.     return a;
  157.  }
  158.  #endif
  159. -#if !defined(__GNUC__) || defined(__SSE4_1__) || defined(__INTEL_COMPILER)
  160. +#if !defined(__GNUC__) || defined(__SSE4_1__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ > 8) || defined(__INTEL_COMPILER)
  161.  #include <smmintrin.h>
  162.  #else
  163.  __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  164. @@ -44,7 +44,7 @@ _mm_insert_epi32 (__m128i a, int b, const int i)
  165.     return a;
  166.  }
  167.  #endif
  168. -#if !defined(__GNUC__) || (defined(__AES__) && defined(__PCLMUL__)) || defined(__INTEL_COMPILER)
  169. +#if !defined(__GNUC__) || (defined(__AES__) && defined(__PCLMUL__)) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ > 8) || defined(__INTEL_COMPILER)
  170.  #include <wmmintrin.h>
  171.  #else
  172.  __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement