config_int.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // config_int.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_int.h
  5. /// \brief Library configuration file
  6. /// \details <tt>config_int.h</tt> provides defines and typedefs for fixed
  7. /// size integers. The library's choices for fixed size integers predates other
  8. /// standard-based integers by about 5 years. After fixed sizes were
  9. /// made standard, the library continued to use its own definitions for
  10. /// compatibility with previous versions of the library.
  11. /// \details <tt>config.h</tt> was split into components in May 2019 to better
  12. /// integrate with Autoconf and its feature tests. The splitting occurred so
  13. /// users could continue to include <tt>config.h</tt> while allowing Autoconf
  14. /// to write new <tt>config_asm.h</tt> and new <tt>config_cxx.h</tt> using
  15. /// its feature tests.
  16. /// \note You should include <tt>config.h</tt> rather than <tt>config_int.h</tt>
  17. /// directly.
  18. /// \sa <A HREF="https://github.com/weidai11/cryptopp/issues/835">Issue 835,
  19. /// Make config.h more autoconf friendly</A>,
  20. /// <A HREF="https://www.cryptopp.com/wiki/Configure.sh">Configure.sh script</A>
  21. /// on the Crypto++ wiki
  22. /// \since Crypto++ 8.3
  23. #ifndef CRYPTOPP_CONFIG_INT_H
  24. #define CRYPTOPP_CONFIG_INT_H
  25. #include "config_ns.h"
  26. #include "config_ver.h"
  27. /// \brief Library byte guard
  28. /// \details CRYPTOPP_NO_GLOBAL_BYTE indicates <tt>byte</tt> is in the Crypto++
  29. /// namespace.
  30. /// \details The Crypto++ <tt>byte</tt> was originally in global namespace to avoid
  31. /// ambiguity with other byte typedefs. <tt>byte</tt> was moved to CryptoPP namespace
  32. /// at Crypto++ 6.0 due to C++17, <tt>std::byte</tt> and potential compile problems.
  33. /// \sa <A HREF="http://github.com/weidai11/cryptopp/issues/442">Issue 442</A>,
  34. /// <A HREF="https://www.cryptopp.com/wiki/Configure.sh">std::byte</A> on the
  35. /// Crypto++ wiki
  36. /// \since Crypto++ 6.0
  37. #define CRYPTOPP_NO_GLOBAL_BYTE 1
  38. NAMESPACE_BEGIN(CryptoPP)
  39. // Signed words added at Issue 609 for early versions of and Visual Studio and
  40. // the NaCl gear. Also see https://github.com/weidai11/cryptopp/issues/609.
  41. /// \brief 8-bit unsigned datatype
  42. /// \details The Crypto++ <tt>byte</tt> was originally in global namespace to avoid
  43. /// ambiguity with other byte typedefs. <tt>byte</tt> was moved to CryptoPP namespace
  44. /// at Crypto++ 6.0 due to C++17, <tt>std::byte</tt> and potential compile problems.
  45. /// \sa CRYPTOPP_NO_GLOBAL_BYTE, <A HREF="http://github.com/weidai11/cryptopp/issues/442">Issue 442</A>,
  46. /// <A HREF="https://www.cryptopp.com/wiki/Configure.sh">std::byte</A> on the
  47. /// Crypto++ wiki
  48. /// \since Crypto++ 1.0, CryptoPP namespace since Crypto++ 6.0
  49. typedef unsigned char byte;
  50. /// \brief 16-bit unsigned datatype
  51. /// \since Crypto++ 1.0
  52. typedef unsigned short word16;
  53. /// \brief 32-bit unsigned datatype
  54. /// \since Crypto++ 1.0
  55. typedef unsigned int word32;
  56. /// \brief 8-bit signed datatype
  57. /// \details The 8-bit signed datatype was added to support constant time
  58. /// implementations for curve25519, X25519 key agreement and ed25519
  59. /// signatures.
  60. /// \since Crypto++ 8.0
  61. typedef signed char sbyte;
  62. /// \brief 16-bit signed datatype
  63. /// \details The 32-bit signed datatype was added to support constant time
  64. /// implementations for curve25519, X25519 key agreement and ed25519
  65. /// signatures.
  66. /// \since Crypto++ 8.0
  67. typedef signed short sword16;
  68. /// \brief 32-bit signed datatype
  69. /// \details The 32-bit signed datatype was added to support constant time
  70. /// implementations for curve25519, X25519 key agreement and ed25519
  71. /// signatures.
  72. /// \since Crypto++ 8.0
  73. typedef signed int sword32;
  74. #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
  75. /// \brief 64-bit unsigned datatype
  76. /// \details The typedef for <tt>word64</tt> varies depending on the platform.
  77. /// On Microsoft platforms it is <tt>unsigned __int64</tt>. On Unix &amp; Linux
  78. /// with LP64 data model it is <tt>unsigned long</tt>. On Unix &amp; Linux with ILP32
  79. /// data model it is <tt>unsigned long long</tt>.
  80. /// \since Crypto++ 1.0
  81. typedef unsigned long long word64;
  82. /// \brief 64-bit signed datatype
  83. /// \details The typedef for <tt>sword64</tt> varies depending on the platform.
  84. /// On Microsoft platforms it is <tt>signed __int64</tt>. On Unix &amp; Linux
  85. /// with LP64 data model it is <tt>signed long</tt>. On Unix &amp; Linux with ILP32
  86. /// data model it is <tt>signed long long</tt>.
  87. /// \since Crypto++ 8.0
  88. typedef signed long long sword64;
  89. /// \brief 128-bit unsigned datatype
  90. /// \details The typedef for <tt>word128</tt> varies depending on the platform.
  91. /// <tt>word128</tt> is only available on 64-bit machines when
  92. /// <tt>CRYPTOPP_WORD128_AVAILABLE</tt> is defined.
  93. /// On Unix &amp; Linux with LP64 data model it is <tt>__uint128_t</tt>.
  94. /// Microsoft platforms do not provide a 128-bit integer type. 32-bit platforms
  95. /// do not provide a 128-bit integer type.
  96. /// \since Crypto++ 5.6
  97. typedef __uint128_t word128;
  98. /// \brief Declare an unsigned word64
  99. /// \details W64LIT is used to portability declare or assign 64-bit literal values.
  100. /// W64LIT will append the proper suffix to ensure the compiler accepts the literal.
  101. /// \details Use the macro like shown below.
  102. /// <pre>
  103. /// word64 x = W64LIT(0xffffffffffffffff);
  104. /// </pre>
  105. /// \since Crypto++ 1.0
  106. #define W64LIT(x) ...
  107. /// \brief Declare a signed word64
  108. /// \details SW64LIT is used to portability declare or assign 64-bit literal values.
  109. /// SW64LIT will append the proper suffix to ensure the compiler accepts the literal.
  110. /// \details Use the macro like shown below.
  111. /// <pre>
  112. /// sword64 x = SW64LIT(0xffffffffffffffff);
  113. /// </pre>
  114. /// \since Crypto++ 8.0
  115. #define SW64LIT(x) ...
  116. /// \brief Declare ops on word64 are slow
  117. /// \details CRYPTOPP_BOOL_SLOW_WORD64 is typically defined to 1 on platforms
  118. /// that have a machine word smaller than 64-bits. That is, the define
  119. /// is present on 32-bit platforms. The define is also present on platforms
  120. /// where the cpu is slow even with a 64-bit cpu.
  121. #define CRYPTOPP_BOOL_SLOW_WORD64 ...
  122. #elif defined(_MSC_VER) || defined(__BORLANDC__)
  123. typedef signed __int64 sword64;
  124. typedef unsigned __int64 word64;
  125. #define SW64LIT(x) x##i64
  126. #define W64LIT(x) x##ui64
  127. #elif (_LP64 || __LP64__)
  128. typedef signed long sword64;
  129. typedef unsigned long word64;
  130. #define SW64LIT(x) x##L
  131. #define W64LIT(x) x##UL
  132. #else
  133. typedef signed long long sword64;
  134. typedef unsigned long long word64;
  135. #define SW64LIT(x) x##LL
  136. #define W64LIT(x) x##ULL
  137. #endif
  138. /// \brief Large word type
  139. /// \details lword is a typedef for large word types. It is used for file
  140. /// offsets and such.
  141. typedef word64 lword;
  142. /// \brief Large word type max value
  143. /// \details LWORD_MAX is the maximum value for large word types.
  144. /// Since an <tt>lword</tt> is an unsigned type, the value is
  145. /// <tt>0xffffffffffffffff</tt>. W64LIT will append the proper suffix.
  146. const lword LWORD_MAX = W64LIT(0xffffffffffffffff);
  147. #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
  148. /// \brief Half word used for multiprecision integer arithmetic
  149. /// \details hword is used for multiprecision integer arithmetic.
  150. /// The typedef for <tt>hword</tt> varies depending on the platform.
  151. /// On 32-bit platforms it is usually <tt>word16</tt>. On 64-bit platforms
  152. /// it is usually <tt>word32</tt>.
  153. /// \details Library users typically use byte, word16, word32 and word64.
  154. /// \since Crypto++ 2.0
  155. typedef word32 hword;
  156. /// \brief Full word used for multiprecision integer arithmetic
  157. /// \details word is used for multiprecision integer arithmetic.
  158. /// The typedef for <tt>word</tt> varies depending on the platform.
  159. /// On 32-bit platforms it is usually <tt>word32</tt>. On 64-bit platforms
  160. /// it is usually <tt>word64</tt>.
  161. /// \details Library users typically use byte, word16, word32 and word64.
  162. /// \since Crypto++ 2.0
  163. typedef word64 word;
  164. /// \brief Double word used for multiprecision integer arithmetic
  165. /// \details dword is used for multiprecision integer arithmetic.
  166. /// The typedef for <tt>dword</tt> varies depending on the platform.
  167. /// On 32-bit platforms it is usually <tt>word64</tt>. On 64-bit Unix &amp;
  168. /// Linux platforms it is usually <tt>word128</tt>. <tt>word128</tt> is
  169. /// not available on Microsoft platforms. <tt>word128</tt> is only available
  170. /// when <tt>CRYPTOPP_WORD128_AVAILABLE</tt> is defined.
  171. /// \details Library users typically use byte, word16, word32 and word64.
  172. /// \sa CRYPTOPP_WORD128_AVAILABLE
  173. /// \since Crypto++ 2.0
  174. typedef word128 dword;
  175. /// \brief 128-bit word availability
  176. /// \details CRYPTOPP_WORD128_AVAILABLE indicates a 128-bit word is
  177. /// available from the platform. 128-bit words are usually available on
  178. /// 64-bit platforms, but not available 32-bit platforms.
  179. /// \details If CRYPTOPP_WORD128_AVAILABLE is not defined, then 128-bit
  180. /// words are not available.
  181. /// \details GCC and compatible compilers signal 128-bit word availability
  182. /// with the preporcessor macro <tt>__SIZEOF_INT128__ >= 16</tt>.
  183. /// \since Crypto++ 2.0
  184. #define CRYPTOPP_WORD128_AVAILABLE ...
  185. #else
  186. // define hword, word, and dword. these are used for multiprecision integer arithmetic
  187. // Intel compiler won't have _umul128 until version 10.0. See http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30231625.aspx
  188. #if (defined(_MSC_VER) && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1000) && (defined(_M_X64) || defined(_M_IA64))) || (defined(__DECCXX) && defined(__alpha__)) || (defined(__INTEL_COMPILER) && defined(__x86_64__)) || (defined(__SUNPRO_CC) && defined(__x86_64__))
  189. typedef word32 hword;
  190. typedef word64 word;
  191. #else
  192. #define CRYPTOPP_NATIVE_DWORD_AVAILABLE 1
  193. #if defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || defined(__x86_64__) || defined(__mips64) || defined(__sparc64__) || defined(__aarch64__)
  194. #if ((CRYPTOPP_GCC_VERSION >= 30400) || (CRYPTOPP_LLVM_CLANG_VERSION >= 30000) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40300)) && (__SIZEOF_INT128__ >= 16)
  195. // GCC 4.0.1 on MacOS X is missing __umodti3 and __udivti3
  196. // GCC 4.8.3 and bad uint128_t ops on PPC64/POWER7 (Issue 421)
  197. // mode(TI) division broken on amd64 with GCC earlier than GCC 3.4
  198. typedef word32 hword;
  199. typedef word64 word;
  200. typedef __uint128_t dword;
  201. typedef __uint128_t word128;
  202. #define CRYPTOPP_WORD128_AVAILABLE 1
  203. #else
  204. // if we're here, it means we're on a 64-bit CPU but we don't have a way to obtain 128-bit multiplication results
  205. typedef word16 hword;
  206. typedef word32 word;
  207. typedef word64 dword;
  208. #endif
  209. #else
  210. // being here means the native register size is probably 32 bits or less
  211. #define CRYPTOPP_BOOL_SLOW_WORD64 1
  212. typedef word16 hword;
  213. typedef word32 word;
  214. typedef word64 dword;
  215. #endif
  216. #endif
  217. #endif
  218. #ifndef CRYPTOPP_BOOL_SLOW_WORD64
  219. # define CRYPTOPP_BOOL_SLOW_WORD64 0
  220. #endif
  221. /// \brief Size of a platform word in bytes
  222. /// \details The size of a platform word, in bytes
  223. const unsigned int WORD_SIZE = sizeof(word);
  224. /// \brief Size of a platform word in bits
  225. /// \details The size of a platform word, in bits
  226. const unsigned int WORD_BITS = WORD_SIZE * 8;
  227. NAMESPACE_END
  228. #endif // CRYPTOPP_CONFIG_INT_H