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