7 #ifndef CRYPTOPP_MISC_H
8 #define CRYPTOPP_MISC_H
12 #if !CRYPTOPP_DOXYGEN_PROCESSING
14 #if CRYPTOPP_MSC_VERSION
15 # pragma warning(push)
16 # pragma warning(disable: 4146 4514)
17 # if (CRYPTOPP_MSC_VERSION >= 1400)
18 # pragma warning(disable: 6326)
29 #define _interlockedbittestandset CRYPTOPP_DISABLED_INTRINSIC_1
30 #define _interlockedbittestandreset CRYPTOPP_DISABLED_INTRINSIC_2
31 #define _interlockedbittestandset64 CRYPTOPP_DISABLED_INTRINSIC_3
32 #define _interlockedbittestandreset64 CRYPTOPP_DISABLED_INTRINSIC_4
34 #undef _interlockedbittestandset
35 #undef _interlockedbittestandreset
36 #undef _interlockedbittestandset64
37 #undef _interlockedbittestandreset64
38 #define CRYPTOPP_FAST_ROTATE(x) 1
39 #elif _MSC_VER >= 1300
40 #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32 | (x) == 64)
42 #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32)
44 #elif (defined(__MWERKS__) && TARGET_CPU_PPC) || \
45 (defined(__GNUC__) && (defined(_ARCH_PWR2) || defined(_ARCH_PWR) || defined(_ARCH_PPC) || defined(_ARCH_PPC64) || defined(_ARCH_COM)))
46 #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32)
47 #elif defined(__GNUC__) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86) // depend on GCC's peephole optimization to generate rotate instructions
48 #define CRYPTOPP_FAST_ROTATE(x) 1
50 #define CRYPTOPP_FAST_ROTATE(x) 0
58 #if defined(__GNUC__) && defined(__linux__)
59 #define CRYPTOPP_BYTESWAP_AVAILABLE
63 #if defined(__GNUC__) && defined(__BMI__)
64 # include <immintrin.h>
65 # if defined(__clang__)
67 # define _tzcnt_u32(x) __tzcnt_u32(x)
70 # define _blsr_u32(x) __blsr_u32(x)
74 # define _tzcnt_u64(x) __tzcnt_u64(x)
77 # define _blsr_u64(x) __blsr_u64(x)
81 #endif // GNUC and BMI
83 #endif // CRYPTOPP_DOXYGEN_PROCESSING
85 #if CRYPTOPP_DOXYGEN_PROCESSING
101 # if defined(__SIZE_MAX__) && (__SIZE_MAX__ > 0)
102 # define SIZE_MAX __SIZE_MAX__
103 # elif defined(SIZE_T_MAX) && (SIZE_T_MAX > 0)
104 # define SIZE_MAX SIZE_T_MAX
106 # define SIZE_MAX ((std::numeric_limits<size_t>::max)())
110 #endif // CRYPTOPP_DOXYGEN_PROCESSING
112 NAMESPACE_BEGIN(CryptoPP)
119 #if CRYPTOPP_DOXYGEN_PROCESSING
123 #define CRYPTOPP_COMPILE_ASSERT(expr) { ... }
124 #else // CRYPTOPP_DOXYGEN_PROCESSING
128 static char dummy[2*b-1];
132 #define CRYPTOPP_COMPILE_ASSERT(assertion) CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, __LINE__)
133 #if defined(CRYPTOPP_EXPORTS) || defined(CRYPTOPP_IMPORTS)
134 #define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance)
136 # if defined(__GNUC__)
137 # define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance) \
138 static CompileAssert<(assertion)> \
139 CRYPTOPP_ASSERT_JOIN(cryptopp_CRYPTOPP_ASSERT_, instance) __attribute__ ((unused))
141 # define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance) \
142 static CompileAssert<(assertion)> \
143 CRYPTOPP_ASSERT_JOIN(cryptopp_CRYPTOPP_ASSERT_, instance)
146 #define CRYPTOPP_ASSERT_JOIN(X, Y) CRYPTOPP_DO_ASSERT_JOIN(X, Y)
147 #define CRYPTOPP_DO_ASSERT_JOIN(X, Y) X##Y
149 #endif // CRYPTOPP_DOXYGEN_PROCESSING
153 #if CRYPTOPP_DOXYGEN_PROCESSING
161 # define COUNTOF(arr)
165 # if defined(_MSC_VER) && (_MSC_VER >= 1400)
166 # define COUNTOF(x) _countof(x)
168 # define COUNTOF(x) (sizeof(x)/sizeof(x[0]))
171 #endif // CRYPTOPP_DOXYGEN_PROCESSING
181 #if !CRYPTOPP_DOXYGEN_PROCESSING
182 template <
class BASE1,
class BASE2>
183 class CRYPTOPP_NO_VTABLE TwoBases :
public BASE1,
public BASE2
187 template <
class BASE1,
class BASE2,
class BASE3>
188 class CRYPTOPP_NO_VTABLE ThreeBases :
public BASE1,
public BASE2,
public BASE3
191 #endif // CRYPTOPP_DOXYGEN_PROCESSING
225 T* operator()()
const {
return new T;}
228 #if CRYPTOPP_DOXYGEN_PROCESSING
237 #define MEMORY_BARRIER ...
239 #if defined(CRYPTOPP_CXX11_ATOMICS)
240 # define MEMORY_BARRIER() std::atomic_thread_fence(std::memory_order_acq_rel)
241 #elif (_MSC_VER >= 1400)
242 # pragma intrinsic(_ReadWriteBarrier)
243 # define MEMORY_BARRIER() _ReadWriteBarrier()
244 #elif defined(__INTEL_COMPILER)
245 # define MEMORY_BARRIER() __memory_barrier()
246 #elif defined(__GNUC__) || defined(__clang__)
247 # define MEMORY_BARRIER() __asm__ __volatile__ ("" ::: "memory")
249 # define MEMORY_BARRIER()
251 #endif // CRYPTOPP_DOXYGEN_PROCESSING
266 template <
class T,
class F = NewObject<T>,
int instance=0>
270 Singleton(F objectFactory = F()) : m_objectFactory(objectFactory) {}
273 CRYPTOPP_NOINLINE
const T &
Ref(CRYPTOPP_NOINLINE_DOTDOTDOT)
const;
283 #if defined(CRYPTOPP_CXX11_ATOMICS) && defined(CRYPTOPP_CXX11_SYNCHRONIZATION)
284 template <
class T,
class F,
int instance>
287 static std::mutex s_mutex;
288 static std::atomic<T*> s_pObject;
290 T *p = s_pObject.load(std::memory_order_relaxed);
291 std::atomic_thread_fence(std::memory_order_acquire);
296 std::lock_guard<std::mutex> lock(s_mutex);
297 p = s_pObject.load(std::memory_order_relaxed);
298 std::atomic_thread_fence(std::memory_order_acquire);
303 T *newObject = m_objectFactory();
304 s_pObject.store(newObject, std::memory_order_relaxed);
305 std::atomic_thread_fence(std::memory_order_release);
310 template <
class T,
class F,
int instance>
314 T *p = s_pObject.m_p;
320 T *newObject = m_objectFactory();
330 s_pObject.m_p = newObject;
339 #if (!__STDC_WANT_SECURE_LIB__ && !defined(_MEMORY_S_DEFINED)) || defined(CRYPTOPP_WANT_SECURE_LIB)
359 inline void memcpy_s(
void *dest,
size_t sizeInBytes,
const void *src,
size_t count)
367 if (count > sizeInBytes)
370 #if CRYPTOPP_MSC_VERSION
371 # pragma warning(push)
372 # pragma warning(disable: 4996)
373 # if (CRYPTOPP_MSC_VERSION >= 1400)
374 # pragma warning(disable: 6386)
377 memcpy(dest, src, count);
378 #if CRYPTOPP_MSC_VERSION
379 # pragma warning(pop)
401 inline void memmove_s(
void *dest,
size_t sizeInBytes,
const void *src,
size_t count)
409 if (count > sizeInBytes)
412 #if CRYPTOPP_MSC_VERSION
413 # pragma warning(push)
414 # pragma warning(disable: 4996)
415 # if (CRYPTOPP_MSC_VERSION >= 1400)
416 # pragma warning(disable: 6386)
419 memmove(dest, src, count);
420 #if CRYPTOPP_MSC_VERSION
421 # pragma warning(pop)
425 #if __BORLANDC__ >= 0x620
427 # define memcpy_s CryptoPP::memcpy_s
428 # define memmove_s CryptoPP::memmove_s
431 #endif // __STDC_WANT_SECURE_LIB__
454 inline void *
memset_z(
void *ptr,
int value,
size_t num)
457 #if CRYPTOPP_GCC_VERSION >= 30001
458 if (__builtin_constant_p(num) && num==0)
461 volatile void* x = memset(ptr, value, num);
462 return const_cast<void*
>(x);
470 template <
class T>
inline const T&
STDMIN(
const T& a,
const T& b)
472 return b < a ? b : a;
480 template <
class T>
inline const T&
STDMAX(
const T& a,
const T& b)
483 return a < b ? b : a;
486 #if CRYPTOPP_MSC_VERSION
487 # pragma warning(push)
488 # pragma warning(disable: 4389)
491 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
492 # pragma GCC diagnostic push
493 # pragma GCC diagnostic ignored "-Wsign-compare"
494 # if (CRYPTOPP_LLVM_CLANG_VERSION >= 20800) || (CRYPTOPP_APPLE_CLANG_VERSION >= 30000)
495 # pragma GCC diagnostic ignored "-Wtautological-compare"
496 # elif (CRYPTOPP_GCC_VERSION >= 40300)
497 # pragma GCC diagnostic ignored "-Wtype-limits"
506 template <
class T1,
class T2>
inline const T1
UnsignedMin(
const T1& a,
const T2& b)
509 if (
sizeof(T1)<=
sizeof(T2))
510 return b < (T2)a ? (T1)b : a;
512 return (T1)b < a ? (T1)b : a;
519 template <
class T1,
class T2>
523 if (from != to || (from > 0) != (to > 0))
536 static const unsigned int HIGH_BIT = (1U << 31);
537 const char CH = !!(base & HIGH_BIT) ?
'A' :
'a';
553 T digit = value % base;
554 result = char((digit < 10 ?
'0' : (CH - 10)) + digit) + result;
558 result =
"-" + result;
568 template <> CRYPTOPP_DLL
590 template <> CRYPTOPP_DLL
593 #if CRYPTOPP_MSC_VERSION
594 # pragma warning(pop)
597 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
598 # pragma GCC diagnostic pop
601 #define RETURN_IF_NONZERO(x) size_t returnedValue = x; if (returnedValue) return returnedValue
604 #define GETBYTE(x, y) (unsigned int)byte((x)>>(8*(y)))
609 #define CRYPTOPP_GET_BYTE_AS_BYTE(x, y) byte((x)>>(8*(y)))
617 for (
unsigned int i=8*
sizeof(value)/2; i>0; i/=2)
619 return (
unsigned int)value&1;
631 unsigned int l=0, h=8*
sizeof(value);
634 unsigned int t = (l+h)/2;
653 unsigned int l=0, h=8*
sizeof(value);
657 unsigned int t = (l+h)/2;
679 #if defined(__GNUC__) && defined(__BMI__)
680 return (
unsigned int)_tzcnt_u32(v);
681 #elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400)
682 return (
unsigned int)__builtin_ctz(v);
683 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
684 unsigned long result;
685 _BitScanForward(&result, v);
686 return (
unsigned int)result;
689 static const int MultiplyDeBruijnBitPosition[32] =
691 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
692 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
694 return MultiplyDeBruijnBitPosition[((word32)((v & -v) * 0x077CB531U)) >> 27];
710 #if defined(__GNUC__) && defined(__BMI__) && defined(__x86_64__)
711 return (
unsigned int)_tzcnt_u64(v);
712 #elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400)
713 return (
unsigned int)__builtin_ctzll(v);
714 #elif defined(_MSC_VER) && (_MSC_VER >= 1400) && (defined(_M_X64) || defined(_M_IA64))
715 unsigned long result;
716 _BitScanForward64(&result, v);
717 return (
unsigned int)result;
731 inline T
Crop(T value,
size_t bits)
733 if (bits < 8*
sizeof(value))
734 return T(value & ((T(1) << bits) - 1));
745 return ((bitCount+7)/(8));
755 return ((byteCount+WORD_SIZE-1)/WORD_SIZE);
765 return ((bitCount+WORD_BITS-1)/(WORD_BITS));
775 return ((bitCount+2*WORD_BITS-1)/(2*WORD_BITS));
784 CRYPTOPP_DLL
void CRYPTOPP_API
xorbuf(byte *buf,
const byte *mask,
size_t count);
793 CRYPTOPP_DLL
void CRYPTOPP_API
xorbuf(byte *output,
const byte *input,
const byte *mask,
size_t count);
804 CRYPTOPP_DLL
bool CRYPTOPP_API
VerifyBufsEqual(
const byte *buf1,
const byte *buf2,
size_t count);
814 return value > 0 && (value & (value-1)) == 0;
817 #if defined(__GNUC__) && defined(__BMI__)
819 inline bool IsPowerOf2<word32>(
const word32 &value)
821 return value > 0 && _blsr_u32(value) == 0;
824 # if defined(__x86_64__)
826 inline bool IsPowerOf2<word64>(
const word64 &value)
828 return value > 0 && _blsr_u64(value) == 0;
840 template <
class T1,
class T2>
844 return T1((a > b) ? (a - b) : 0);
855 template <
class T1,
class T2>
859 return T1((a > b) ? (a - b) : 1);
868 template <
class T1,
class T2>
882 template <
class T1,
class T2>
898 template <
class T1,
class T2>
920 #if defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS)
924 CRYPTOPP_UNUSED(dummy);
925 #if defined(CRYPTOPP_CXX11_ALIGNOF)
927 #elif (_MSC_VER >= 1300)
929 #elif defined(__GNUC__)
930 return __alignof__(T);
931 #elif CRYPTOPP_BOOL_SLOW_WORD64
934 # if __BIGGEST_ALIGNMENT__
935 if (__BIGGEST_ALIGNMENT__ <
sizeof(T))
936 return __BIGGEST_ALIGNMENT__;
951 return alignment==1 || (
IsPowerOf2(alignment) ?
ModPowerOf2((
size_t)ptr, alignment) == 0 : (size_t)ptr % alignment == 0);
962 CRYPTOPP_UNUSED(dummy);
966 #if defined(IS_LITTLE_ENDIAN)
968 #elif defined(IS_BIG_ENDIAN)
971 # error "Unable to determine endian-ness"
984 return NativeByteOrder::ToEnum();
1029 for (
int i=
int(size-1), carry=1; i>=0 && carry; i--)
1030 carry = !++inout[i];
1045 for (i=
int(size-1), carry=1; i>=0 && carry; i--)
1046 carry = ((output[i] = input[i]+1) == 0);
1047 memcpy_s(output, size, input,
size_t(i)+1);
1069 ptrdiff_t t = size_t(c) * (a - b);
1085 volatile T *p = buf+n;
1087 *((
volatile T*)(--p)) = 0;
1090 #if (_MSC_VER >= 1400 || defined(__GNUC__)) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86)
1098 volatile byte *p = buf;
1100 asm volatile(
"rep stosb" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1102 __stosb((byte *)(
size_t)p, 0, n);
1112 volatile word16 *p = buf;
1114 asm volatile(
"rep stosw" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1116 __stosw((word16 *)(
size_t)p, 0, n);
1126 volatile word32 *p = buf;
1128 asm volatile(
"rep stosl" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1130 __stosd((
unsigned long *)(
size_t)p, 0, n);
1140 #if CRYPTOPP_BOOL_X64
1141 volatile word64 *p = buf;
1143 asm volatile(
"rep stosq" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1145 __stosq((word64 *)(
size_t)p, 0, n);
1152 #endif // #if (_MSC_VER >= 1400 || defined(__GNUC__)) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86)
1154 #if (_MSC_VER >= 1700) && defined(_M_ARM)
1157 char *p =
reinterpret_cast<char*
>(buf+n);
1159 __iso_volatile_store8(--p, 0);
1164 short *p =
reinterpret_cast<short*
>(buf+n);
1166 __iso_volatile_store16(--p, 0);
1171 int *p =
reinterpret_cast<int*
>(buf+n);
1173 __iso_volatile_store32(--p, 0);
1178 __int64 *p =
reinterpret_cast<__int64*
>(buf+n);
1180 __iso_volatile_store64(--p, 0);
1191 if (
sizeof(T) % 8 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word64>() == 0)
1193 else if (
sizeof(T) % 4 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word32>() == 0)
1195 else if (
sizeof(T) % 2 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word16>() == 0)
1213 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
1214 std::string StringNarrow(
const wchar_t *str,
bool throwOnError =
true);
1216 static std::string StringNarrow(
const wchar_t *str,
bool throwOnError =
true)
1222 #if (CRYPTOPP_MSC_VERSION >= 1400)
1223 size_t len=0, size=0;
1228 len = wcslen(str)+1;
1230 err = wcstombs_s(&size, NULL, 0, str, len*
sizeof(
wchar_t));
1232 if (err != 0) {
goto CONVERSION_ERROR;}
1234 result.resize(size);
1235 err = wcstombs_s(&size, &result[0], size, str, len*
sizeof(
wchar_t));
1244 return std::string();
1248 if (!result.empty() && result[size - 1] ==
'\0')
1249 result.erase(size - 1);
1251 size_t size = wcstombs(NULL, str, 0);
1253 if (size == (
size_t)-1) {
goto CONVERSION_ERROR;}
1255 result.resize(size);
1256 size = wcstombs(&result[0], str, size);
1259 if (size == (
size_t)-1)
1265 return std::string();
1271 #endif // StringNarrow and CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
1273 #ifdef CRYPTOPP_DOXYGEN_PROCESSING
1291 #endif // CRYPTOPP_DOXYGEN_PROCESSING
1293 #if CRYPTOPP_BOOL_ALIGN16
1296 #endif // CRYPTOPP_BOOL_ALIGN16
1324 static const unsigned int THIS_SIZE =
sizeof(T)*8;
1325 static const unsigned int MASK = THIS_SIZE-1;
1327 return T((x<<y)|(x>>(-y&MASK)));
1346 static const unsigned int THIS_SIZE =
sizeof(T)*8;
1347 static const unsigned int MASK = THIS_SIZE-1;
1349 return T((x >> y)|(x<<(-y&MASK)));
1364 static const unsigned int THIS_SIZE =
sizeof(T)*8;
1365 static const unsigned int MASK = THIS_SIZE-1;
1367 return T((x<<y)|(x>>(-y&MASK)));
1382 static const unsigned int THIS_SIZE =
sizeof(T)*8;
1383 static const unsigned int MASK = THIS_SIZE-1;
1385 return T((x>>y)|(x<<(-y&MASK)));
1395 template <
class T>
inline T
rotlMod(T x,
unsigned int y)
1397 static const unsigned int THIS_SIZE =
sizeof(T)*8;
1398 static const unsigned int MASK = THIS_SIZE-1;
1399 return T((x<<(y&MASK))|(x>>(-y&MASK)));
1409 template <
class T>
inline T
rotrMod(T x,
unsigned int y)
1411 static const unsigned int THIS_SIZE =
sizeof(T)*8;
1412 static const unsigned int MASK = THIS_SIZE-1;
1413 return T((x>>(y&MASK))|(x<<(-y&MASK)));
1426 template<>
inline word32 rotlFixed<word32>(word32 x,
unsigned int y)
1430 return y ? _lrotl(x, static_cast<byte>(y)) : x;
1441 template<>
inline word32 rotrFixed<word32>(word32 x,
unsigned int y)
1445 return y ? _lrotr(x, static_cast<byte>(y)) : x;
1456 template<>
inline word32 rotlVariable<word32>(word32 x,
unsigned int y)
1459 return _lrotl(x, static_cast<byte>(y));
1470 template<>
inline word32 rotrVariable<word32>(word32 x,
unsigned int y)
1473 return _lrotr(x, static_cast<byte>(y));
1483 template<>
inline word32 rotlMod<word32>(word32 x,
unsigned int y)
1486 return _lrotl(x, static_cast<byte>(y));
1496 template<>
inline word32 rotrMod<word32>(word32 x,
unsigned int y)
1499 return _lrotr(x, static_cast<byte>(y));
1502 #endif // #ifdef _MSC_VER
1504 #if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER)
1515 template<>
inline word64 rotlFixed<word64>(word64 x,
unsigned int y)
1519 return y ? _rotl64(x, static_cast<byte>(y)) : x;
1530 template<>
inline word64 rotrFixed<word64>(word64 x,
unsigned int y)
1534 return y ? _rotr64(x, static_cast<byte>(y)) : x;
1545 template<>
inline word64 rotlVariable<word64>(word64 x,
unsigned int y)
1548 return _rotl64(x, static_cast<byte>(y));
1559 template<>
inline word64 rotrVariable<word64>(word64 x,
unsigned int y)
1562 return y ? _rotr64(x, static_cast<byte>(y)) : x;
1572 template<>
inline word64 rotlMod<word64>(word64 x,
unsigned int y)
1575 return y ? _rotl64(x, static_cast<byte>(y)) : x;
1585 template<>
inline word64 rotrMod<word64>(word64 x,
unsigned int y)
1588 return y ? _rotr64(x, static_cast<byte>(y)) : x;
1591 #endif // #if _MSC_VER >= 1310
1593 #if _MSC_VER >= 1400 && !defined(__INTEL_COMPILER)
1596 template<>
inline word16 rotlFixed<word16>(word16 x,
unsigned int y)
1599 return _rotl16(x, static_cast<byte>(y));
1602 template<>
inline word16 rotrFixed<word16>(word16 x,
unsigned int y)
1605 return _rotr16(x, static_cast<byte>(y));
1608 template<>
inline word16 rotlVariable<word16>(word16 x,
unsigned int y)
1610 return _rotl16(x, static_cast<byte>(y));
1613 template<>
inline word16 rotrVariable<word16>(word16 x,
unsigned int y)
1615 return _rotr16(x, static_cast<byte>(y));
1618 template<>
inline word16 rotlMod<word16>(word16 x,
unsigned int y)
1620 return _rotl16(x, static_cast<byte>(y));
1623 template<>
inline word16 rotrMod<word16>(word16 x,
unsigned int y)
1625 return _rotr16(x, static_cast<byte>(y));
1628 template<>
inline byte rotlFixed<byte>(byte x,
unsigned int y)
1631 return _rotl8(x, static_cast<byte>(y));
1634 template<>
inline byte rotrFixed<byte>(byte x,
unsigned int y)
1637 return _rotr8(x, static_cast<byte>(y));
1640 template<>
inline byte rotlVariable<byte>(byte x,
unsigned int y)
1642 return _rotl8(x, static_cast<byte>(y));
1645 template<>
inline byte rotrVariable<byte>(byte x,
unsigned int y)
1647 return _rotr8(x, static_cast<byte>(y));
1650 template<>
inline byte rotlMod<byte>(byte x,
unsigned int y)
1652 return _rotl8(x, static_cast<byte>(y));
1655 template<>
inline byte rotrMod<byte>(byte x,
unsigned int y)
1657 return _rotr8(x, static_cast<byte>(y));
1660 #endif // #if _MSC_VER >= 1400
1662 #if (defined(__MWERKS__) && TARGET_CPU_PPC)
1664 template<>
inline word32 rotlFixed<word32>(word32 x,
unsigned int y)
1667 return y ? __rlwinm(x,y,0,31) : x;
1670 template<>
inline word32 rotrFixed<word32>(word32 x,
unsigned int y)
1673 return y ? __rlwinm(x,32-y,0,31) : x;
1676 template<>
inline word32 rotlVariable<word32>(word32 x,
unsigned int y)
1679 return (__rlwnm(x,y,0,31));
1682 template<>
inline word32 rotrVariable<word32>(word32 x,
unsigned int y)
1685 return (__rlwnm(x,32-y,0,31));
1688 template<>
inline word32 rotlMod<word32>(word32 x,
unsigned int y)
1690 return (__rlwnm(x,y,0,31));
1693 template<>
inline word32 rotrMod<word32>(word32 x,
unsigned int y)
1695 return (__rlwnm(x,32-y,0,31));
1698 #endif // #if (defined(__MWERKS__) && TARGET_CPU_PPC)
1710 return GETBYTE(value, index);
1712 return GETBYTE(value,
sizeof(T)-index-1);
1729 #ifdef CRYPTOPP_BYTESWAP_AVAILABLE
1730 return bswap_16(value);
1731 #elif defined(_MSC_VER) && _MSC_VER >= 1300
1732 return _byteswap_ushort(value);
1744 #if defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE)
1745 __asm__ (
"bswap %0" :
"=r" (value) :
"0" (value));
1747 #elif defined(CRYPTOPP_BYTESWAP_AVAILABLE)
1748 return bswap_32(value);
1749 #elif defined(__MWERKS__) && TARGET_CPU_PPC
1750 return (word32)__lwbrx(&value,0);
1751 #elif _MSC_VER >= 1400 || (_MSC_VER >= 1300 && !defined(_DLL))
1752 return _byteswap_ulong(value);
1753 #elif CRYPTOPP_FAST_ROTATE(32)
1758 value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
1769 #if defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(__x86_64__)
1770 __asm__ (
"bswap %0" :
"=r" (value) :
"0" (value));
1772 #elif defined(CRYPTOPP_BYTESWAP_AVAILABLE)
1773 return bswap_64(value);
1774 #elif defined(_MSC_VER) && _MSC_VER >= 1300
1775 return _byteswap_uint64(value);
1776 #elif CRYPTOPP_BOOL_SLOW_WORD64
1779 value = ((value & W64LIT(0xFF00FF00FF00FF00)) >> 8) | ((value & W64LIT(0x00FF00FF00FF00FF)) << 8);
1780 value = ((value & W64LIT(0xFFFF0000FFFF0000)) >> 16) | ((value & W64LIT(0x0000FFFF0000FFFF)) << 16);
1790 value = byte((value & 0xAA) >> 1) | byte((value & 0x55) << 1);
1791 value = byte((value & 0xCC) >> 2) | byte((value & 0x33) << 2);
1800 value = word16((value & 0xAAAA) >> 1) | word16((value & 0x5555) << 1);
1801 value = word16((value & 0xCCCC) >> 2) | word16((value & 0x3333) << 2);
1802 value = word16((value & 0xF0F0) >> 4) | word16((value & 0x0F0F) << 4);
1811 value = word32((value & 0xAAAAAAAA) >> 1) | word32((value & 0x55555555) << 1);
1812 value = word32((value & 0xCCCCCCCC) >> 2) | word32((value & 0x33333333) << 2);
1813 value = word32((value & 0xF0F0F0F0) >> 4) | word32((value & 0x0F0F0F0F) << 4);
1822 #if CRYPTOPP_BOOL_SLOW_WORD64
1825 value = word64((value & W64LIT(0xAAAAAAAAAAAAAAAA)) >> 1) | word64((value & W64LIT(0x5555555555555555)) << 1);
1826 value = word64((value & W64LIT(0xCCCCCCCCCCCCCCCC)) >> 2) | word64((value & W64LIT(0x3333333333333333)) << 2);
1827 value = word64((value & W64LIT(0xF0F0F0F0F0F0F0F0)) >> 4) | word64((value & W64LIT(0x0F0F0F0F0F0F0F0F)) << 4);
1843 else if (
sizeof(T) == 2)
1845 else if (
sizeof(T) == 4)
1906 size_t count = byteCount/
sizeof(T);
1907 for (
size_t i=0; i<count; i++)
1930 memcpy_s(out, byteCount, in, byteCount);
1934 inline void GetUserKey(
ByteOrder order, T *out,
size_t outlen,
const byte *in,
size_t inlen)
1936 const size_t U =
sizeof(T);
1938 memcpy_s(out, outlen*U, in, inlen);
1939 memset_z((byte *)out+inlen, 0, outlen*U-inlen);
1943 #ifndef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
1944 inline byte UnalignedGetWordNonTemplate(
ByteOrder order,
const byte *block,
const byte *)
1946 CRYPTOPP_UNUSED(order);
1950 inline word16 UnalignedGetWordNonTemplate(
ByteOrder order,
const byte *block,
const word16 *)
1953 ? block[1] | (block[0] << 8)
1954 : block[0] | (block[1] << 8);
1957 inline word32 UnalignedGetWordNonTemplate(
ByteOrder order,
const byte *block,
const word32 *)
1960 ? word32(block[3]) | (word32(block[2]) << 8) | (word32(block[1]) << 16) | (word32(block[0]) << 24)
1961 : word32(block[0]) | (word32(block[1]) << 8) | (word32(block[2]) << 16) | (word32(block[3]) << 24);
1964 inline word64 UnalignedGetWordNonTemplate(
ByteOrder order,
const byte *block,
const word64 *)
1969 (word64(block[6]) << 8) |
1970 (word64(block[5]) << 16) |
1971 (word64(block[4]) << 24) |
1972 (word64(block[3]) << 32) |
1973 (word64(block[2]) << 40) |
1974 (word64(block[1]) << 48) |
1975 (word64(block[0]) << 56))
1978 (word64(block[1]) << 8) |
1979 (word64(block[2]) << 16) |
1980 (word64(block[3]) << 24) |
1981 (word64(block[4]) << 32) |
1982 (word64(block[5]) << 40) |
1983 (word64(block[6]) << 48) |
1984 (word64(block[7]) << 56));
1987 inline void UnalignedbyteNonTemplate(
ByteOrder order, byte *block, byte value,
const byte *xorBlock)
1989 CRYPTOPP_UNUSED(order);
1990 block[0] = (byte)(xorBlock ? (value ^ xorBlock[0]) : value);
1993 inline void UnalignedbyteNonTemplate(
ByteOrder order, byte *block, word16 value,
const byte *xorBlock)
1999 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2000 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2004 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2005 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2012 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2013 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2017 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2018 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2023 inline void UnalignedbyteNonTemplate(
ByteOrder order, byte *block, word32 value,
const byte *xorBlock)
2029 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2030 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2031 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2032 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2036 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2037 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2038 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2039 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2046 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2047 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2048 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2049 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2053 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2054 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2055 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2056 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2061 inline void UnalignedbyteNonTemplate(
ByteOrder order, byte *block, word64 value,
const byte *xorBlock)
2067 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2068 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2069 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2070 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2071 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2072 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2073 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2074 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2078 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2079 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2080 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2081 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2082 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2083 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2084 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2085 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2092 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2093 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2094 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2095 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2096 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2097 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2098 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2099 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2103 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2104 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2105 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2106 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2107 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2108 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2109 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2110 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2114 #endif // #ifndef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
2117 inline T GetWord(
bool assumeAligned,
ByteOrder order,
const byte *block)
2125 CRYPTOPP_UNUSED(assumeAligned);
2126 #ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
2130 memcpy(&temp, block,
sizeof(T));
2136 inline void GetWord(
bool assumeAligned,
ByteOrder order, T &result,
const byte *block)
2138 result = GetWord<T>(assumeAligned, order, block);
2142 inline void PutWord(
bool assumeAligned,
ByteOrder order, byte *block, T value,
const byte *xorBlock = NULL)
2151 CRYPTOPP_UNUSED(assumeAligned);
2152 #ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
2153 *
reinterpret_cast<T *
>((
void *)block) =
ConditionalByteReverse(order, value) ^ (xorBlock ? *
reinterpret_cast<const T *
>((
const void *)xorBlock) : 0);
2157 if (xorBlock) memcpy(&t2, xorBlock,
sizeof(T));
2158 memmove(block, &(t1 ^= t2),
sizeof(T));
2178 template <
class T,
class B,
bool A=false>
2185 : m_block((const byte *)block) {}
2195 x = GetWord<T>(A, B::ToEnum(), m_block);
2196 m_block +=
sizeof(T);
2201 const byte *m_block;
2220 template <
class T,
class B,
bool A=false>
2228 : m_xorBlock((const byte *)xorBlock), m_block((byte *)block) {}
2237 PutWord(A, B::ToEnum(), m_block, (T)x, m_xorBlock);
2238 m_block +=
sizeof(T);
2240 m_xorBlock +=
sizeof(T);
2245 const byte *m_xorBlock;
2258 template <
class T,
class B,
bool GA=false,
bool PA=false>
2272 return std::string((
char *)&value,
sizeof(value));
2308 CRYPTOPP_UNUSED(value); CRYPTOPP_UNUSED(bits);
2320 CRYPTOPP_UNUSED(value); CRYPTOPP_UNUSED(bits);
2339 return value >> bits;
2350 return value << bits;
2363 template <
unsigned int bits,
class T>
2378 template <
unsigned int bits,
class T>
2386 #define CRYPTOPP_BLOCK_1(n, t, s) t* m_##n() {return (t *)(void *)(m_aggregate+0);} size_t SS1() {return sizeof(t)*(s);} size_t m_##n##Size() {return (s);}
2387 #define CRYPTOPP_BLOCK_2(n, t, s) t* m_##n() {return (t *)(void *)(m_aggregate+SS1());} size_t SS2() {return SS1()+sizeof(t)*(s);} size_t m_##n##Size() {return (s);}
2388 #define CRYPTOPP_BLOCK_3(n, t, s) t* m_##n() {return (t *)(void *)(m_aggregate+SS2());} size_t SS3() {return SS2()+sizeof(t)*(s);} size_t m_##n##Size() {return (s);}
2389 #define CRYPTOPP_BLOCK_4(n, t, s) t* m_##n() {return (t *)(void *)(m_aggregate+SS3());} size_t SS4() {return SS3()+sizeof(t)*(s);} size_t m_##n##Size() {return (s);}
2390 #define CRYPTOPP_BLOCK_5(n, t, s) t* m_##n() {return (t *)(void *)(m_aggregate+SS4());} size_t SS5() {return SS4()+sizeof(t)*(s);} size_t m_##n##Size() {return (s);}
2391 #define CRYPTOPP_BLOCK_6(n, t, s) t* m_##n() {return (t *)(void *)(m_aggregate+SS5());} size_t SS6() {return SS5()+sizeof(t)*(s);} size_t m_##n##Size() {return (s);}
2392 #define CRYPTOPP_BLOCK_7(n, t, s) t* m_##n() {return (t *)(void *)(m_aggregate+SS6());} size_t SS7() {return SS6()+sizeof(t)*(s);} size_t m_##n##Size() {return (s);}
2393 #define CRYPTOPP_BLOCK_8(n, t, s) t* m_##n() {return (t *)(void *)(m_aggregate+SS7());} size_t SS8() {return SS7()+sizeof(t)*(s);} size_t m_##n##Size() {return (s);}
2394 #define CRYPTOPP_BLOCKS_END(i) size_t SST() {return SS##i();} void AllocateBlocks() {m_aggregate.New(SST());} AlignedSecByteBlock m_aggregate;
2398 #if CRYPTOPP_MSC_VERSION
2399 # pragma warning(pop)
void SecureWipeBuffer(T *buf, size_t n)
Sets each element of an array to 0.
the cipher is performing decryption
An invalid argument was detected.
bool NativeByteOrderIs(ByteOrder order)
Determines whether order follows native byte ordering.
void memmove_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
Bounds checking replacement for memmove()
bool SafeConvert(T1 from, T2 &to)
Tests whether a conversion from -> to is safe to perform.
unsigned int GetAlignmentOf(T *dummy=NULL)
Returns the minimum alignment requirements of a type.
ByteOrder
Provides the byte ordering.
void AlignedDeallocate(void *ptr)
Frees a buffer allocated with AlignedAllocate.
Restricts the instantiation of a class to one static object without locks.
void IncrementCounterByOne(byte *inout, unsigned int size)
Performs an addition with carry on a block of bytes.
T2 ModPowerOf2(const T1 &a, const T2 &b)
Reduces a value to a power of 2.
size_t BitsToBytes(size_t bitCount)
Returns the number of 8-bit bytes or octets required for the specified number of bits.
T rotlFixed(T x, unsigned int y)
Performs a left rotate.
size_t BitsToWords(size_t bitCount)
Returns the number of words required for the specified number of bits.
unsigned int BytePrecision(const T &value)
Returns the number of 8-bit bytes or octets required for a value.
PutBlock(const void *xorBlock, void *block)
Construct a PutBlock.
Converts a typename to an enumerated value.
CipherDir
Specifies a direction for a cipher to operate.
Abstract base classes that provide a uniform interface to this library.
void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
Bounds checking replacement for memcpy()
static T LeftShift(T value, unsigned int bits)
Left shifts a value that does not overflow.
An object factory function.
Classes for automatic resource management.
Library configuration file.
bool IsAligned(const void *ptr, T *dummy=NULL)
Determines whether ptr is minimally aligned.
size_t BytesToWords(size_t byteCount)
Returns the number of words required for the specified number of bytes.
std::string IntToString< word64 >(word64 value, unsigned int base)
Converts an unsigned value to a string.
T rotlVariable(T x, unsigned int y)
Performs a left rotate.
Access a block of memory.
byte BitReverse(byte value)
Reverses bits in a 8-bit value.
byte order is little-endian
the cipher is performing encryption
void SecureWipeArray(T *buf, size_t n)
Sets each element of an array to 0.
bool IsAlignedOn(const void *ptr, unsigned int alignment)
Determines whether ptr is aligned to a minimum value.
Uses encapsulation to hide an object in derived classes.
void * UnalignedAllocate(size_t size)
Allocates a buffer.
Manages resources for a single object.
unsigned int TrailingZeros(word32 v)
Determines the number of trailing 0-bits in a value.
void CallNewHandler()
Attempts to reclaim unused memory.
#define CRYPTOPP_COMPILE_ASSERT(expr)
Compile time assertion.
T Crop(T value, size_t bits)
Truncates the value to the specified number of bits.
T ConditionalByteReverse(ByteOrder order, T value)
Reverses bytes in a value depending upon endianess.
void ConditionalSwapPointers(bool c, T &a, T &b)
Performs a branchless swap of pointers a and b if condition c is true.
Multiple precision integer with arithmetic operations.
T1 SaturatingSubtract(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 0.
CipherDir GetCipherDir(const T &obj)
Returns the direction the cipher is being operated.
const T1 UnsignedMin(const T1 &a, const T2 &b)
Safe comparison of values that could be neagtive and incorrectly promoted.
bool IsPowerOf2(const T &value)
Tests whether a value is a power of 2.
static T RightShift(T value, unsigned int bits)
Right shifts a value that does not overflow.
#define MEMORY_BARRIER
A memory barrier.
void * memset_z(void *ptr, int value, size_t num)
Memory block initializer and eraser that attempts to survive optimizations.
unsigned int Parity(T value)
Returns the parity of a value.
Safely right shift values when undefined behavior could occur.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
PutBlock< T, B, A > & operator()(U x)
Access a block of memory.
void ConditionalSwap(bool c, T &a, T &b)
Performs a branchless swap of values a and b if condition c is true.
T1 SaturatingSubtract1(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 1.
GetBlock(const void *block)
Construct a GetBlock.
static T RightShift(T value, unsigned int bits)
Right shifts a value that overflows.
void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
Access a block of memory.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
GetBlock< T, B, A > & operator()(U &x)
Access a block of memory.
bool VerifyBufsEqual(const byte *buf1, const byte *buf2, size_t count)
Performs a near constant-time comparison of two equally sized buffers.
ByteOrder GetNativeByteOrder()
Returns NativeByteOrder as an enumerated ByteOrder value.
Safely left shift values when undefined behavior could occur.
T1 RoundUpToMultipleOf(const T1 &n, const T2 &m)
Rounds a value up to a multiple of a second value.
Safely shift values when undefined behavior could occur.
const T & STDMAX(const T &a, const T &b)
Replacement function for std::max.
Access a block of memory.
std::string IntToString< Integer >(Integer value, unsigned int base)
Converts an Integer to a string.
T rotrVariable(T x, unsigned int y)
Performs a right rotate.
T rotlMod(T x, unsigned int y)
Performs a left rotate.
unsigned int GetByte(ByteOrder order, T value, unsigned int index)
Gets a byte from a value.
T rotrMod(T x, unsigned int y)
Performs a right rotate.
const T & Ref(...) const
Return a reference to the inner Singleton object.
T rotrFixed(T x, unsigned int y)
Performs a right rotate.
Ensures an object is not copyable.
byte ByteReverse(byte value)
Reverses bytes in a 8-bit value.
void UnalignedDeallocate(void *ptr)
Frees a buffer allocated with UnalignedAllocate.
unsigned int BitPrecision(const T &value)
Returns the number of bits required for a value.
size_t BitsToDwords(size_t bitCount)
Returns the number of double words required for the specified number of bits.
static T LeftShift(T value, unsigned int bits)
Left shifts a value that overflows.
T1 RoundDownToMultipleOf(const T1 &n, const T2 &m)
Rounds a value down to a multiple of a second value.
void * AlignedAllocate(size_t size)
Allocates a buffer on 16-byte boundary.
#define SIZE_MAX
The maximum value of a machine word.
void vec_swap(T &a, T &b)
Swaps two variables which are arrays.