config_asm.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. // config_asm.h - written and placed in public domain by Jeffrey Walton
  2. // the bits that make up this source file are from the
  3. // library's monolithic config.h.
  4. /// \file config_asm.h
  5. /// \brief Library configuration file
  6. /// \details <tt>config_asm.h</tt> provides defines for instruction set
  7. /// architectures
  8. /// and inline assembly.
  9. /// \details <tt>config.h</tt> was split into components in May 2019 to better
  10. /// integrate with Autoconf and its feature tests. The splitting occurred so
  11. /// users could continue to include <tt>config.h</tt> while allowing Autoconf
  12. /// to write new <tt>config_asm.h</tt> and new <tt>config_cxx.h</tt> using
  13. /// its feature tests.
  14. /// \note You should include <tt>config.h</tt> rather than <tt>config_asm.h</tt>
  15. /// directly.
  16. /// \sa <A HREF="https://github.com/weidai11/cryptopp/issues/835">Issue 835,
  17. /// Make config.h more autoconf friendly</A>,
  18. /// <A HREF="https://www.cryptopp.com/wiki/Configure.sh">Configure.sh script</A>
  19. /// on the Crypto++ wiki
  20. /// \since Crypto++ 8.3
  21. #ifndef CRYPTOPP_CONFIG_ASM_H
  22. #define CRYPTOPP_CONFIG_ASM_H
  23. #include "config_os.h"
  24. #include "config_cpu.h"
  25. #include "config_ver.h"
  26. // Define this to disable ASM, intrinsics and built-ins. The library will be
  27. // compiled using C++ only. The library code will not include SSE2 (and
  28. // above), NEON, Aarch32, Aarch64, or Altivec (and above). Note the compiler
  29. // may use higher ISAs depending on compiler options, but the library will not
  30. // explicitly use the ISAs. When disabling ASM, it is best to do it from
  31. // config.h to ensure the library and all programs share the setting.
  32. // #define CRYPTOPP_DISABLE_ASM 1
  33. // https://github.com/weidai11/cryptopp/issues/719
  34. #if defined(__native_client__)
  35. # undef CRYPTOPP_DISABLE_ASM
  36. # define CRYPTOPP_DISABLE_ASM 1
  37. #endif
  38. // Some Clang and SunCC cannot handle mixed asm with positional arguments,
  39. // where the body is Intel style with no prefix and the templates are
  40. // AT&T style. Define this if the Makefile misdetects the configuration.
  41. // Also see https://bugs.llvm.org/show_bug.cgi?id=39895 .
  42. // #define CRYPTOPP_DISABLE_MIXED_ASM 1
  43. #if defined(__clang__) || (defined(__APPLE__) && defined(__GNUC__)) || defined(__SUNPRO_CC)
  44. # undef CRYPTOPP_DISABLE_MIXED_ASM
  45. # define CRYPTOPP_DISABLE_MIXED_ASM 1
  46. #endif
  47. // Define this if you need to disable Android advanced ISAs.
  48. // The problem is, Android-mk does not allow us to specify an
  49. // ISA option, like -maes or -march=armv8-a+crypto for AES.
  50. // Lack of an option results in a compile failure. To avoid
  51. // the compile failure, set this define. Also see
  52. // https://github.com/weidai11/cryptopp/issues/1015
  53. // CRYPTOPP_DISABLE_ANDROID_ADVANCED_ISA 1
  54. // ***************** IA32 CPU features ********************
  55. #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
  56. // Apple Clang prior to 5.0 cannot handle SSE2
  57. #if defined(CRYPTOPP_APPLE_CLANG_VERSION) && (CRYPTOPP_APPLE_CLANG_VERSION < 50000)
  58. # define CRYPTOPP_DISABLE_ASM 1
  59. #endif
  60. // Sun Studio 12.1 provides GCC inline assembly
  61. // http://blogs.oracle.com/x86be/entry/gcc_style_asm_inlining_support
  62. #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5100)
  63. # define CRYPTOPP_DISABLE_ASM 1
  64. #endif
  65. // Guard everything in CRYPTOPP_DISABLE_ASM
  66. #if !defined(CRYPTOPP_DISABLE_ASM)
  67. #if (defined(_MSC_VER) && defined(_M_IX86)) || ((defined(__GNUC__) && (defined(__i386__)) || defined(__x86_64__)))
  68. // C++Builder 2010 does not allow "call label" where label is defined within inline assembly
  69. #define CRYPTOPP_X86_ASM_AVAILABLE 1
  70. #if !defined(CRYPTOPP_DISABLE_SSE2) && (defined(_MSC_VER) || CRYPTOPP_GCC_VERSION >= 30300 || defined(__SSE2__))
  71. #define CRYPTOPP_SSE2_ASM_AVAILABLE 1
  72. #endif
  73. #if !defined(CRYPTOPP_DISABLE_SSSE3) && (_MSC_VER >= 1500 || CRYPTOPP_GCC_VERSION >= 40300 || defined(__SSSE3__))
  74. #define CRYPTOPP_SSSE3_ASM_AVAILABLE 1
  75. #endif
  76. #endif
  77. #if defined(_MSC_VER) && defined(_M_X64)
  78. #define CRYPTOPP_X64_MASM_AVAILABLE 1
  79. #endif
  80. #if defined(__GNUC__) && defined(__x86_64__)
  81. #define CRYPTOPP_X64_ASM_AVAILABLE 1
  82. #endif
  83. // 32-bit SunCC does not enable SSE2 by default.
  84. #if !defined(CRYPTOPP_DISABLE_SSE2) && (defined(_MSC_VER) || CRYPTOPP_GCC_VERSION >= 30300 || defined(__SSE2__) || (__SUNPRO_CC >= 0x5100))
  85. #define CRYPTOPP_SSE2_INTRIN_AVAILABLE 1
  86. #endif
  87. #if !defined(CRYPTOPP_DISABLE_SSSE3)
  88. # if defined(__SSSE3__) || (_MSC_VER >= 1500) || \
  89. (CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1000) || (__SUNPRO_CC >= 0x5110) || \
  90. (CRYPTOPP_LLVM_CLANG_VERSION >= 20300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40000)
  91. #define CRYPTOPP_SSSE3_AVAILABLE 1
  92. # endif
  93. #endif
  94. // Intrinsics available in GCC 4.3 (http://gcc.gnu.org/gcc-4.3/changes.html) and
  95. // MSVC 2008 (http://msdn.microsoft.com/en-us/library/bb892950%28v=vs.90%29.aspx)
  96. // SunCC could generate SSE4 at 12.1, but the intrinsics are missing until 12.4.
  97. #if !defined(CRYPTOPP_DISABLE_SSE4) && defined(CRYPTOPP_SSSE3_AVAILABLE) && \
  98. (defined(__SSE4_1__) || (CRYPTOPP_MSC_VERSION >= 1500) || \
  99. (CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1000) || (__SUNPRO_CC >= 0x5110) || \
  100. (CRYPTOPP_LLVM_CLANG_VERSION >= 20300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40000))
  101. #define CRYPTOPP_SSE41_AVAILABLE 1
  102. #endif
  103. #if !defined(CRYPTOPP_DISABLE_SSE4) && defined(CRYPTOPP_SSSE3_AVAILABLE) && \
  104. (defined(__SSE4_2__) || (CRYPTOPP_MSC_VERSION >= 1500) || (__SUNPRO_CC >= 0x5110) || \
  105. (CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1000) || \
  106. (CRYPTOPP_LLVM_CLANG_VERSION >= 20300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40000))
  107. #define CRYPTOPP_SSE42_AVAILABLE 1
  108. #endif
  109. // Couple to CRYPTOPP_DISABLE_AESNI, but use CRYPTOPP_CLMUL_AVAILABLE so we can selectively
  110. // disable for misbehaving platforms and compilers, like Solaris or some Clang.
  111. #if defined(CRYPTOPP_DISABLE_AESNI)
  112. #define CRYPTOPP_DISABLE_CLMUL 1
  113. #endif
  114. // Requires Sun Studio 12.3 (SunCC 0x5120) in theory.
  115. #if !defined(CRYPTOPP_DISABLE_CLMUL) && defined(CRYPTOPP_SSE42_AVAILABLE) && \
  116. (defined(__PCLMUL__) || (_MSC_FULL_VER >= 150030729) || (__SUNPRO_CC >= 0x5120) || \
  117. (CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1110) || \
  118. (CRYPTOPP_LLVM_CLANG_VERSION >= 30200) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40300))
  119. #define CRYPTOPP_CLMUL_AVAILABLE 1
  120. #endif
  121. // Requires Sun Studio 12.3 (SunCC 0x5120)
  122. #if !defined(CRYPTOPP_DISABLE_AESNI) && defined(CRYPTOPP_SSE42_AVAILABLE) && \
  123. (defined(__AES__) || (_MSC_FULL_VER >= 150030729) || (__SUNPRO_CC >= 0x5120) || \
  124. (CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1110) || \
  125. (CRYPTOPP_LLVM_CLANG_VERSION >= 30200) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40300))
  126. #define CRYPTOPP_AESNI_AVAILABLE 1
  127. #endif
  128. // Requires Binutils 2.24
  129. #if !defined(CRYPTOPP_DISABLE_AVX) && defined(CRYPTOPP_SSE42_AVAILABLE) && \
  130. (defined(__AVX2__) || (CRYPTOPP_MSC_VERSION >= 1800) || (__SUNPRO_CC >= 0x5130) || \
  131. (CRYPTOPP_GCC_VERSION >= 40700) || (__INTEL_COMPILER >= 1400) || \
  132. (CRYPTOPP_LLVM_CLANG_VERSION >= 30100) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40600))
  133. #define CRYPTOPP_AVX_AVAILABLE 1
  134. #endif
  135. // Requires Binutils 2.24
  136. #if !defined(CRYPTOPP_DISABLE_AVX2) && defined(CRYPTOPP_AVX_AVAILABLE) && \
  137. (defined(__AVX2__) || (CRYPTOPP_MSC_VERSION >= 1800) || (__SUNPRO_CC >= 0x5130) || \
  138. (CRYPTOPP_GCC_VERSION >= 40900) || (__INTEL_COMPILER >= 1400) || \
  139. (CRYPTOPP_LLVM_CLANG_VERSION >= 30100) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40600))
  140. #define CRYPTOPP_AVX2_AVAILABLE 1
  141. #endif
  142. // Guessing at SHA for SunCC. Its not in Sun Studio 12.6. Also see
  143. // http://stackoverflow.com/questions/45872180/which-xarch-for-sha-extensions-on-solaris
  144. // Guessing for Intel ICPC. A slide deck says SHA support is in version 16.0-beta
  145. // https://www.alcf.anl.gov/files/ken_intel_compiler_optimization.pdf
  146. #if !defined(CRYPTOPP_DISABLE_SHANI) && defined(CRYPTOPP_SSE42_AVAILABLE) && \
  147. (defined(__SHA__) || (CRYPTOPP_MSC_VERSION >= 1900) || (__SUNPRO_CC >= 0x5160) || \
  148. (CRYPTOPP_GCC_VERSION >= 40900) || (__INTEL_COMPILER >= 1600) || \
  149. (CRYPTOPP_LLVM_CLANG_VERSION >= 30400) || (CRYPTOPP_APPLE_CLANG_VERSION >= 50100))
  150. #define CRYPTOPP_SHANI_AVAILABLE 1
  151. #endif
  152. // RDRAND uses byte codes. All we need is x86 ASM for it.
  153. // However tie it to AES-NI since SecureKey was available with it.
  154. #if !defined(CRYPTOPP_DISABLE_RDRAND) && defined(CRYPTOPP_AESNI_AVAILABLE)
  155. #define CRYPTOPP_RDRAND_AVAILABLE 1
  156. #endif
  157. // RDSEED uses byte codes. All we need is x86 ASM for it.
  158. // However tie it to AES-NI since SecureKey was available with it.
  159. #if !defined(CRYPTOPP_DISABLE_RDSEED) && defined(CRYPTOPP_AESNI_AVAILABLE)
  160. #define CRYPTOPP_RDSEED_AVAILABLE 1
  161. #endif
  162. // PadlockRNG uses byte codes. All we need is x86 ASM for it.
  163. #if !defined(CRYPTOPP_DISABLE_PADLOCK) && \
  164. !(defined(__ANDROID__) || defined(ANDROID) || defined(__APPLE__)) && \
  165. defined(CRYPTOPP_X86_ASM_AVAILABLE)
  166. #define CRYPTOPP_PADLOCK_AVAILABLE 1
  167. #define CRYPTOPP_PADLOCK_RNG_AVAILABLE 1
  168. #define CRYPTOPP_PADLOCK_ACE_AVAILABLE 1
  169. #define CRYPTOPP_PADLOCK_ACE2_AVAILABLE 1
  170. #define CRYPTOPP_PADLOCK_PHE_AVAILABLE 1
  171. #define CRYPTOPP_PADLOCK_PMM_AVAILABLE 1
  172. #endif
  173. // Fixup for SunCC 12.1-12.4. Bad code generation in AES_Encrypt and friends.
  174. #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5130)
  175. # undef CRYPTOPP_AESNI_AVAILABLE
  176. #endif
  177. // Fixup for SunCC 12.1-12.6. Compiler crash on GCM_Reduce_CLMUL.
  178. // http://github.com/weidai11/cryptopp/issues/226
  179. #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5150)
  180. # undef CRYPTOPP_CLMUL_AVAILABLE
  181. #endif
  182. // Clang intrinsic casts, http://bugs.llvm.org/show_bug.cgi?id=20670
  183. #define M128_CAST(x) ((__m128i *)(void *)(x))
  184. #define CONST_M128_CAST(x) ((const __m128i *)(const void *)(x))
  185. #define M256_CAST(x) ((__m256i *)(void *)(x))
  186. #define CONST_M256_CAST(x) ((const __m256i *)(const void *)(x))
  187. #endif // CRYPTOPP_DISABLE_ASM
  188. #endif // X86, X32, X64
  189. // ***************** ARM CPU features ********************
  190. #if (CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARMV8)
  191. // We don't have an ARM big endian test rig. Disable
  192. // ARM-BE ASM and instrinsics until we can test it.
  193. #if (CRYPTOPP_BIG_ENDIAN)
  194. # define CRYPTOPP_DISABLE_ASM 1
  195. #endif
  196. // Guard everything in CRYPTOPP_DISABLE_ASM
  197. #if !defined(CRYPTOPP_DISABLE_ASM)
  198. // Requires ACLE 1.0. -mfpu=neon or above must be present
  199. // Requires GCC 4.3, Clang 2.8 or Visual Studio 2012
  200. // Do not use APPLE_CLANG_VERSION; use __ARM_FEATURE_XXX instead.
  201. #if !defined(CRYPTOPP_ARM_NEON_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_NEON)
  202. # if defined(__arm__) || defined(__ARM_NEON) || defined(__ARM_FEATURE_NEON) || defined(_M_ARM)
  203. # if (CRYPTOPP_GCC_VERSION >= 40300) || (CRYPTOPP_LLVM_CLANG_VERSION >= 20800) || \
  204. (CRYPTOPP_APPLE_CLANG_VERSION >= 30200) || (CRYPTOPP_MSC_VERSION >= 1700)
  205. # define CRYPTOPP_ARM_NEON_AVAILABLE 1
  206. # endif // Compilers
  207. # endif // Platforms
  208. #endif
  209. // ARMv8 and ASIMD. -march=armv8-a or above must be present
  210. // Requires GCC 4.8, Clang 3.3 or Visual Studio 2017
  211. // Do not use APPLE_CLANG_VERSION; use __ARM_FEATURE_XXX instead.
  212. #if !defined(CRYPTOPP_ARM_ASIMD_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_ASIMD)
  213. # if defined(__aarch32__) || defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
  214. # if defined(__ARM_NEON) || defined(__ARM_ASIMD) || defined(__ARM_FEATURE_NEON) || defined(__ARM_FEATURE_ASIMD) || \
  215. (CRYPTOPP_GCC_VERSION >= 40800) || (CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || \
  216. (CRYPTOPP_APPLE_CLANG_VERSION >= 40000) || (CRYPTOPP_MSC_VERSION >= 1916)
  217. # define CRYPTOPP_ARM_NEON_AVAILABLE 1
  218. # define CRYPTOPP_ARM_ASIMD_AVAILABLE 1
  219. # endif // Compilers
  220. # endif // Platforms
  221. #endif
  222. // ARMv8 and ASIMD. -march=armv8-a+crc or above must be present
  223. // Requires GCC 4.8, Clang 3.3 or Visual Studio 2017
  224. #if !defined(CRYPTOPP_ARM_CRC32_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_CRC32)
  225. # if defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
  226. # if defined(__ARM_FEATURE_CRC32) || (CRYPTOPP_GCC_VERSION >= 40800) || \
  227. (CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40300) || \
  228. (CRYPTOPP_MSC_VERSION >= 1916)
  229. # define CRYPTOPP_ARM_CRC32_AVAILABLE 1
  230. # endif // Compilers
  231. # endif // Platforms
  232. #endif
  233. // ARMv8 and AES. -march=armv8-a+crypto or above must be present
  234. // Requires GCC 4.8, Clang 3.3 or Visual Studio 2017
  235. #if !defined(CRYPTOPP_ARM_AES_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_AES)
  236. # if defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
  237. # if defined(__ARM_FEATURE_CRYPTO) || (CRYPTOPP_GCC_VERSION >= 40800) || \
  238. (CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40300) || \
  239. (CRYPTOPP_MSC_VERSION >= 1916)
  240. # define CRYPTOPP_ARM_AES_AVAILABLE 1
  241. # endif // Compilers
  242. # endif // Platforms
  243. #endif
  244. // ARMv8 and PMULL. -march=armv8-a+crypto or above must be present
  245. // Requires GCC 4.8, Clang 3.3 or Visual Studio 2017
  246. #if !defined(CRYPTOPP_ARM_PMULL_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_PMULL)
  247. # if defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
  248. # if defined(__ARM_FEATURE_CRYPTO) || (CRYPTOPP_GCC_VERSION >= 40800) || \
  249. (CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40300) || \
  250. (CRYPTOPP_MSC_VERSION >= 1916)
  251. # define CRYPTOPP_ARM_PMULL_AVAILABLE 1
  252. # endif // Compilers
  253. # endif // Platforms
  254. #endif
  255. // ARMv8 and SHA-1, SHA-256. -march=armv8-a+crypto or above must be present
  256. // Requires GCC 4.8, Clang 3.3 or Visual Studio 2017
  257. #if !defined(CRYPTOPP_ARM_SHA_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_SHA)
  258. # if defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
  259. # if defined(__ARM_FEATURE_CRYPTO) || (CRYPTOPP_GCC_VERSION >= 40800) || \
  260. (CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40300) || \
  261. (CRYPTOPP_MSC_VERSION >= 1916)
  262. # define CRYPTOPP_ARM_SHA1_AVAILABLE 1
  263. # define CRYPTOPP_ARM_SHA2_AVAILABLE 1
  264. # endif // Compilers
  265. # endif // Platforms
  266. #endif
  267. // Buggy Microsoft compiler, https://github.com/weidai11/cryptopp/issues/1096
  268. #if defined(_MSC_VER)
  269. # undef CRYPTOPP_ARM_SHA1_AVAILABLE
  270. # undef CRYPTOPP_ARM_SHA2_AVAILABLE
  271. #endif
  272. // ARMv8 and SHA-512, SHA-3. -march=armv8.2-a+crypto or above must be present
  273. // Requires GCC 8.0, Clang 11.0, Apple Clang 12.0 or Visual Studio 20??
  274. #if !defined(CRYPTOPP_ARM_SHA3_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_SHA)
  275. # if defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
  276. # if defined(__ARM_FEATURE_SHA3) || (CRYPTOPP_GCC_VERSION >= 80000) || \
  277. (CRYPTOPP_APPLE_CLANG_VERSION >= 120000) || (CRYPTOPP_LLVM_CLANG_VERSION >= 110000)
  278. # define CRYPTOPP_ARM_SHA512_AVAILABLE 1
  279. # define CRYPTOPP_ARM_SHA3_AVAILABLE 1
  280. # endif // Compilers
  281. # endif // Platforms
  282. #endif
  283. // ARMv8 and SM3, SM4. -march=armv8.2-a+crypto or above must be present
  284. // Requires GCC 8.0, Clang ??? or Visual Studio 20??
  285. // Do not use APPLE_CLANG_VERSION; use __ARM_FEATURE_XXX instead.
  286. #if !defined(CRYPTOPP_ARM_SM3_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_SM3)
  287. # if defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
  288. # if defined(__ARM_FEATURE_SM3) || (CRYPTOPP_GCC_VERSION >= 80000)
  289. # define CRYPTOPP_ARM_SM3_AVAILABLE 1
  290. # define CRYPTOPP_ARM_SM4_AVAILABLE 1
  291. # endif // Compilers
  292. # endif // Platforms
  293. #endif
  294. // Limit the <arm_neon.h> include.
  295. #if !defined(CRYPTOPP_ARM_NEON_HEADER)
  296. # if defined(CRYPTOPP_ARM_NEON_AVAILABLE) || defined (CRYPTOPP_ARM_ASIMD_AVAILABLE)
  297. # if !defined(_M_ARM64)
  298. # define CRYPTOPP_ARM_NEON_HEADER 1
  299. # endif
  300. # endif
  301. #endif
  302. // Limit the <arm_acle.h> include.
  303. #if !defined(CRYPTOPP_ARM_ACLE_HEADER)
  304. # if defined(__aarch32__) || defined(__aarch64__) || (__ARM_ARCH >= 8) || defined(__ARM_ACLE)
  305. # define CRYPTOPP_ARM_ACLE_HEADER 1
  306. # endif
  307. #endif
  308. // Apple M1 hack. Xcode cross-compiles for iOS lack
  309. // arm_acle.h. Apple M1 needs arm_acle.h. The problem
  310. // in practice is, we can't get CRYPTOPP_ARM_ACLE_HEADER
  311. // quite right based on ARM preprocessor macros.
  312. #if defined(__APPLE__) && !defined(__ARM_FEATURE_CRC32)
  313. # undef CRYPTOPP_ARM_ACLE_HEADER
  314. #endif
  315. // Cryptogams offers an ARM asm implementations for AES and SHA. Crypto++ does
  316. // not provide an asm implementation. The Cryptogams AES implementation is
  317. // about 50% faster than C/C++, and SHA implementation is about 30% faster
  318. // than C/C++. Define this to use the Cryptogams AES and SHA implementations
  319. // on GNU Linux systems. When defined, Crypto++ will use aes_armv4.S,
  320. // sha1_armv4.S and sha256_armv4.S. https://www.cryptopp.com/wiki/Cryptogams.
  321. #if !defined(CRYPTOPP_DISABLE_ARM_NEON)
  322. # if defined(__arm__) && defined(__linux__)
  323. # if defined(__GNUC__) || defined(__clang__)
  324. # define CRYPTOGAMS_ARM_AES 1
  325. # define CRYPTOGAMS_ARM_SHA1 1
  326. # define CRYPTOGAMS_ARM_SHA256 1
  327. # define CRYPTOGAMS_ARM_SHA512 1
  328. # endif
  329. # endif
  330. #endif
  331. // Clang intrinsic casts, http://bugs.llvm.org/show_bug.cgi?id=20670
  332. #define UINT64_CAST(x) ((uint64_t *)(void *)(x))
  333. #define CONST_UINT64_CAST(x) ((const uint64_t *)(const void *)(x))
  334. #endif // CRYPTOPP_DISABLE_ASM
  335. #endif // ARM32, ARM64
  336. // ***************** AltiVec and Power8 ********************
  337. #if (CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64)
  338. // Guard everything in CRYPTOPP_DISABLE_ASM
  339. #if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_ALTIVEC)
  340. // An old Apple G5 with GCC 4.01 has AltiVec, but its only Power4 or so.
  341. #if !defined(CRYPTOPP_ALTIVEC_AVAILABLE)
  342. # if defined(_ARCH_PWR4) || defined(__ALTIVEC__) || \
  343. (CRYPTOPP_XLC_VERSION >= 100000) || (CRYPTOPP_GCC_VERSION >= 40001) || \
  344. (CRYPTOPP_LLVM_CLANG_VERSION >= 20900)
  345. # define CRYPTOPP_ALTIVEC_AVAILABLE 1
  346. # endif
  347. #endif
  348. #if defined(CRYPTOPP_ALTIVEC_AVAILABLE)
  349. // We need Power7 for unaligned loads and stores
  350. #if !defined(CRYPTOPP_POWER7_AVAILABLE) && !defined(CRYPTOPP_DISABLE_POWER7)
  351. # if defined(_ARCH_PWR7) || (CRYPTOPP_XLC_VERSION >= 100000) || \
  352. (CRYPTOPP_GCC_VERSION >= 40100) || (CRYPTOPP_LLVM_CLANG_VERSION >= 30100)
  353. # define CRYPTOPP_POWER7_AVAILABLE 1
  354. # endif
  355. #endif
  356. #if defined(CRYPTOPP_POWER7_AVAILABLE)
  357. // We need Power8 for in-core crypto and 64-bit vector types
  358. #if !defined(CRYPTOPP_POWER8_AVAILABLE) && !defined(CRYPTOPP_DISABLE_POWER8)
  359. # if defined(_ARCH_PWR8) || (CRYPTOPP_XLC_VERSION >= 130000) || \
  360. (CRYPTOPP_GCC_VERSION >= 40800) || (CRYPTOPP_LLVM_CLANG_VERSION >= 70000)
  361. # define CRYPTOPP_POWER8_AVAILABLE 1
  362. # endif
  363. #endif
  364. #if !defined(CRYPTOPP_POWER8_AES_AVAILABLE) && !defined(CRYPTOPP_DISABLE_POWER8_AES) && defined(CRYPTOPP_POWER8_AVAILABLE)
  365. # if defined(__CRYPTO__) || defined(_ARCH_PWR8) || (CRYPTOPP_XLC_VERSION >= 130000) || \
  366. (CRYPTOPP_GCC_VERSION >= 40800) || (CRYPTOPP_LLVM_CLANG_VERSION >= 70000)
  367. //# define CRYPTOPP_POWER8_CRC_AVAILABLE 1
  368. # define CRYPTOPP_POWER8_AES_AVAILABLE 1
  369. # define CRYPTOPP_POWER8_VMULL_AVAILABLE 1
  370. # define CRYPTOPP_POWER8_SHA_AVAILABLE 1
  371. # endif
  372. #endif
  373. #if defined(CRYPTOPP_POWER8_AVAILABLE)
  374. // Power9 for random numbers
  375. #if !defined(CRYPTOPP_POWER9_AVAILABLE) && !defined(CRYPTOPP_DISABLE_POWER9)
  376. # if defined(_ARCH_PWR9) || (CRYPTOPP_XLC_VERSION >= 130200) || \
  377. (CRYPTOPP_GCC_VERSION >= 70000) || (CRYPTOPP_LLVM_CLANG_VERSION >= 80000)
  378. # define CRYPTOPP_POWER9_AVAILABLE 1
  379. # endif
  380. #endif
  381. #endif // CRYPTOPP_POWER8_AVAILABLE
  382. #endif // CRYPTOPP_POWER7_AVAILABLE
  383. #endif // CRYPTOPP_ALTIVEC_AVAILABLE
  384. #endif // CRYPTOPP_DISABLE_ASM
  385. #endif // PPC32, PPC64
  386. // https://github.com/weidai11/cryptopp/issues/1015
  387. #if defined(CRYPTOPP_DISABLE_ANDROID_ADVANCED_ISA)
  388. # if defined(__ANDROID__) || defined(ANDROID)
  389. # if (CRYPTOPP_BOOL_X86)
  390. # undef CRYPTOPP_SSE41_AVAILABLE
  391. # undef CRYPTOPP_SSE42_AVAILABLE
  392. # undef CRYPTOPP_CLMUL_AVAILABLE
  393. # undef CRYPTOPP_AESNI_AVAILABLE
  394. # undef CRYPTOPP_SHANI_AVAILABLE
  395. # undef CRYPTOPP_RDRAND_AVAILABLE
  396. # undef CRYPTOPP_RDSEED_AVAILABLE
  397. # undef CRYPTOPP_AVX_AVAILABLE
  398. # undef CRYPTOPP_AVX2_AVAILABLE
  399. # endif
  400. # if (CRYPTOPP_BOOL_X64)
  401. # undef CRYPTOPP_CLMUL_AVAILABLE
  402. # undef CRYPTOPP_AESNI_AVAILABLE
  403. # undef CRYPTOPP_SHANI_AVAILABLE
  404. # undef CRYPTOPP_RDRAND_AVAILABLE
  405. # undef CRYPTOPP_RDSEED_AVAILABLE
  406. # undef CRYPTOPP_AVX_AVAILABLE
  407. # undef CRYPTOPP_AVX2_AVAILABLE
  408. # endif
  409. # if (CRYPTOPP_BOOL_ARMV8)
  410. # undef CRYPTOPP_ARM_CRC32_AVAILABLE
  411. # undef CRYPTOPP_ARM_PMULL_AVAILABLE
  412. # undef CRYPTOPP_ARM_AES_AVAILABLE
  413. # undef CRYPTOPP_ARM_SHA1_AVAILABLE
  414. # undef CRYPTOPP_ARM_SHA2_AVAILABLE
  415. # endif
  416. # endif // ANDROID
  417. #endif // CRYPTOPP_DISABLE_ANDROID_ADVANCED_ISA
  418. #endif // CRYPTOPP_CONFIG_ASM_H