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