config_int.h 12 KB

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