17#if !defined(CRYPTOPP_DOXYGEN_PROCESSING)
19#if (CRYPTOPP_MSC_VERSION)
21# pragma warning(disable: 4146 4514)
22# if (CRYPTOPP_MSC_VERSION >= 1400)
23# pragma warning(disable: 6326)
28#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
29# pragma GCC diagnostic push
30# pragma GCC diagnostic ignored "-Wconversion"
31# pragma GCC diagnostic ignored "-Wsign-conversion"
32# pragma GCC diagnostic ignored "-Wunused-function"
35#ifdef CRYPTOPP_MSC_VERSION
36 #if CRYPTOPP_MSC_VERSION >= 1400
38 #define _interlockedbittestandset CRYPTOPP_DISABLED_INTRINSIC_1
39 #define _interlockedbittestandreset CRYPTOPP_DISABLED_INTRINSIC_2
40 #define _interlockedbittestandset64 CRYPTOPP_DISABLED_INTRINSIC_3
41 #define _interlockedbittestandreset64 CRYPTOPP_DISABLED_INTRINSIC_4
43 #undef _interlockedbittestandset
44 #undef _interlockedbittestandreset
45 #undef _interlockedbittestandset64
46 #undef _interlockedbittestandreset64
47 #define CRYPTOPP_FAST_ROTATE(x) 1
48 #elif CRYPTOPP_MSC_VERSION >= 1300
49 #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32 | (x) == 64)
51 #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32)
53#elif (defined(__MWERKS__) && TARGET_CPU_PPC) || \
54 (defined(__GNUC__) && (defined(_ARCH_PWR2) || defined(_ARCH_PWR) || defined(_ARCH_PPC) || defined(_ARCH_PPC64) || defined(_ARCH_COM)))
55 #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32)
56#elif defined(__GNUC__) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86)
57 #define CRYPTOPP_FAST_ROTATE(x) 1
59 #define CRYPTOPP_FAST_ROTATE(x) 0
67#if (defined(__GNUC__) || defined(__clang__)) && defined(__linux__)
68#define CRYPTOPP_BYTESWAP_AVAILABLE 1
73#if defined(__arm__) && (defined(__GNUC__) || defined(__clang__)) && (__ARM_ARCH >= 6)
74#define CRYPTOPP_ARM_BYTEREV_AVAILABLE 1
78#if defined(__arm__) && (defined(__GNUC__) || defined(__clang__)) && (__ARM_ARCH >= 7)
79#define CRYPTOPP_ARM_BITREV_AVAILABLE 1
83# if defined(CRYPTOPP_GCC_COMPATIBLE)
84# include <x86intrin.h>
86# include <immintrin.h>
93# define _blsr_u32 __blsr_u32
96# define _blsr_u64 __blsr_u64
99# define _tzcnt_u32 __tzcnt_u32
102# define _tzcnt_u64 __tzcnt_u64
108#if CRYPTOPP_DOXYGEN_PROCESSING
126# if defined(__SIZE_MAX__)
127# define SIZE_MAX __SIZE_MAX__
128# elif defined(SIZE_T_MAX)
129# define SIZE_MAX SIZE_T_MAX
130# elif defined(__SIZE_TYPE__)
131# define SIZE_MAX (~(__SIZE_TYPE__)0)
133# define SIZE_MAX ((std::numeric_limits<size_t>::max)())
146#if CRYPTOPP_DOXYGEN_PROCESSING
153# define CRYPTOPP_COMPILE_ASSERT(expr) { ... }
154#elif defined(CRYPTOPP_CXX17_STATIC_ASSERT)
155# define CRYPTOPP_COMPILE_ASSERT(expr) static_assert(expr)
160 static char dummy[2*b-1];
163#define CRYPTOPP_COMPILE_ASSERT(assertion) CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, __LINE__)
164#define CRYPTOPP_ASSERT_JOIN(X, Y) CRYPTOPP_DO_ASSERT_JOIN(X, Y)
165#define CRYPTOPP_DO_ASSERT_JOIN(X, Y) X##Y
167#if defined(CRYPTOPP_EXPORTS) || defined(CRYPTOPP_IMPORTS)
168# define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance)
170# if defined(__GNUC__) || defined(__clang__)
171# define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance) \
172 static CompileAssert<(assertion)> \
173 CRYPTOPP_ASSERT_JOIN(cryptopp_CRYPTOPP_ASSERT_, instance) __attribute__ ((unused))
175# define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance) \
176 static CompileAssert<(assertion)> \
177 CRYPTOPP_ASSERT_JOIN(cryptopp_CRYPTOPP_ASSERT_, instance)
185#if CRYPTOPP_DOXYGEN_PROCESSING
197# if defined(CRYPTOPP_MSC_VERSION) && (CRYPTOPP_MSC_VERSION >= 1400)
198# define COUNTOF(x) _countof(x)
200# define COUNTOF(x) (sizeof(x)/sizeof(x[0]))
213#if !defined(CRYPTOPP_DOXYGEN_PROCESSING)
214template <
class BASE1,
class BASE2>
215class CRYPTOPP_NO_VTABLE TwoBases :
public BASE1,
public BASE2
219template <
class BASE1,
class BASE2,
class BASE3>
220class CRYPTOPP_NO_VTABLE ThreeBases :
public BASE1,
public BASE2,
public BASE3
244#if CRYPTOPP_CXX11_DELETED_FUNCTIONS
260 T* operator()()
const {
return new T;}
263#if CRYPTOPP_DOXYGEN_PROCESSING
272#define MEMORY_BARRIER ...
274#if defined(CRYPTOPP_CXX11_ATOMIC)
275# define MEMORY_BARRIER() std::atomic_thread_fence(std::memory_order_acq_rel)
276#elif (CRYPTOPP_MSC_VERSION >= 1400)
277# pragma intrinsic(_ReadWriteBarrier)
278# define MEMORY_BARRIER() _ReadWriteBarrier()
279#elif defined(__INTEL_COMPILER)
280# define MEMORY_BARRIER() __memory_barrier()
281#elif defined(__GNUC__) || defined(__clang__)
282# define MEMORY_BARRIER() __asm__ __volatile__ ("" ::: "memory")
284# define MEMORY_BARRIER()
307template <
class T,
class F = NewObject<T>,
int instance=0>
311 Singleton(F objectFactory = F()) : m_objectFactory(objectFactory) {}
314 CRYPTOPP_NOINLINE
const T &
Ref(CRYPTOPP_NOINLINE_DOTDOTDOT)
const;
328template <
class T,
class F,
int instance>
331#if defined(CRYPTOPP_CXX11_ATOMIC) && defined(CRYPTOPP_CXX11_SYNCHRONIZATION) && defined(CRYPTOPP_CXX11_STATIC_INIT)
332 static std::mutex s_mutex;
333 static std::atomic<T*> s_pObject;
335 T *p = s_pObject.load(std::memory_order_relaxed);
336 std::atomic_thread_fence(std::memory_order_acquire);
341 std::lock_guard<std::mutex> lock(s_mutex);
342 p = s_pObject.load(std::memory_order_relaxed);
343 std::atomic_thread_fence(std::memory_order_acquire);
348 T *newObject = m_objectFactory();
349 std::atomic_thread_fence(std::memory_order_release);
350 s_pObject.store(newObject, std::memory_order_relaxed);
355 T *p = s_pObject.m_p;
361 T *newObject = m_objectFactory();
371 s_pObject.m_p = newObject;
387template <
typename PTR,
typename OFF>
388inline PTR
PtrAdd(PTR pointer, OFF offset)
390 return pointer+
static_cast<ptrdiff_t
>(offset);
400template <
typename PTR,
typename OFF>
401inline PTR
PtrSub(PTR pointer, OFF offset)
403 return pointer-
static_cast<ptrdiff_t
>(offset);
415template <
typename PTR>
416inline ptrdiff_t
PtrDiff(
const PTR pointer1,
const PTR pointer2)
418 return pointer1 - pointer2;
430template <
typename PTR>
433 return (
size_t)(
reinterpret_cast<uintptr_t
>(pointer1) -
reinterpret_cast<uintptr_t
>(pointer2));
448 return reinterpret_cast<byte*
>(&str[0]);
467 return reinterpret_cast<const byte*
>(&str[0]);
498#if (CRYPTOPP_CXX11_CONSTEXPR)
501 return static_cast<int>(v);
504# define EnumToInt(v) static_cast<int>(v)
507#if (!__STDC_WANT_SECURE_LIB__ && !defined(_MEMORY_S_DEFINED)) || defined(CRYPTOPP_WANT_SECURE_LIB)
527inline void memcpy_s(
void *dest,
size_t sizeInBytes,
const void *src,
size_t count)
538 if (count > sizeInBytes)
541#if CRYPTOPP_MSC_VERSION
542# pragma warning(push)
543# pragma warning(disable: 4996)
544# if (CRYPTOPP_MSC_VERSION >= 1400)
545# pragma warning(disable: 6386)
548 if (src != NULLPTR && dest != NULLPTR)
549 std::memcpy(dest, src, count);
550#if CRYPTOPP_MSC_VERSION
573inline void memmove_s(
void *dest,
size_t sizeInBytes,
const void *src,
size_t count)
582 if (count > sizeInBytes)
585#if CRYPTOPP_MSC_VERSION
586# pragma warning(push)
587# pragma warning(disable: 4996)
588# if (CRYPTOPP_MSC_VERSION >= 1400)
589# pragma warning(disable: 6386)
592 if (src != NULLPTR && dest != NULLPTR)
593 std::memmove(dest, src, count);
594#if CRYPTOPP_MSC_VERSION
599#if __BORLANDC__ >= 0x620
602# define memcpy_s CryptoPP::memcpy_s
603# define memmove_s CryptoPP::memmove_s
623#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5120)
640inline void *
memset_z(
void *ptr,
int val,
size_t num)
643#if CRYPTOPP_GCC_VERSION >= 30001 || CRYPTOPP_LLVM_CLANG_VERSION >= 20800 || \
644 CRYPTOPP_APPLE_CLANG_VERSION >= 30000
645 if (__builtin_constant_p(num) && num==0)
648 return std::memset(ptr, val, num);
657template <
class T>
inline const T&
STDMIN(
const T& a,
const T& b)
659 return b < a ? b : a;
668template <
class T>
inline const T&
STDMAX(
const T& a,
const T& b)
670 return a < b ? b : a;
673#if CRYPTOPP_MSC_VERSION
674# pragma warning(push)
675# pragma warning(disable: 4389)
678#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
679# pragma GCC diagnostic push
680# pragma GCC diagnostic ignored "-Wstrict-overflow"
681# if (CRYPTOPP_LLVM_CLANG_VERSION >= 20800) || (CRYPTOPP_APPLE_CLANG_VERSION >= 30000)
682# pragma GCC diagnostic ignored "-Wtautological-compare"
683# elif (CRYPTOPP_GCC_VERSION >= 40300)
684# pragma GCC diagnostic ignored "-Wtype-limits"
695template <
class T1,
class T2>
inline const T1
UnsignedMin(
const T1& a,
const T2& b)
701 if (
sizeof(T1)<=
sizeof(T2))
702 return b < (T2)a ? (T1)b : a;
704 return (T1)b < a ? (T1)b : a;
717template <
class T1,
class T2>
720 to =
static_cast<T2
>(from);
721 if (from != to || (from > 0) != (to > 0))
745 to =
static_cast<word64>(from);
759 to =
static_cast<word64>(from);
775 to =
static_cast<word64>(from);
789 if (from >
static_cast<word64>((std::numeric_limits<sword64>::max)()))
791 to =
static_cast<sword64>(from);
805 to =
static_cast<sword64>(from);
819 to =
static_cast<sword64>(from);
833 if (from >
static_cast<word64>((std::numeric_limits<word32>::max)()))
835 to =
static_cast<word32>(from);
851 else if (from >
static_cast<sword64>((std::numeric_limits<word32>::max)()))
853 to =
static_cast<word32>(from);
869 to =
static_cast<word32>(from);
883 if (from >
static_cast<word64>((std::numeric_limits<sword32>::max)()))
885 to =
static_cast<sword32>(from);
899 if (from >
static_cast<sword64>((std::numeric_limits<sword32>::max)()))
901 else if (from <
static_cast<sword64>((std::numeric_limits<sword32>::min)()))
903 to =
static_cast<sword32>(from);
917 if (from >
static_cast<word32>((std::numeric_limits<sword32>::max)()))
919 to =
static_cast<sword32>(from);
932 const unsigned int HIGH_BIT = (1U << 31);
933 const char CH = !!(base & HIGH_BIT) ?
'A' :
'a';
949 T digit = value % base;
950 result = char((digit < 10 ?
'0' : (CH - 10)) + digit) + result;
954 result =
"-" + result;
964template <> CRYPTOPP_DLL
986template <> CRYPTOPP_DLL
989#if CRYPTOPP_MSC_VERSION
993#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
994# pragma GCC diagnostic pop
997#define RETURN_IF_NONZERO(x) size_t returnedValue = x; if (returnedValue) return returnedValue
1000#define GETBYTE(x, y) (unsigned int)byte((x)>>(8*(y)))
1005#define CRYPTOPP_GET_BYTE_AS_BYTE(x, y) byte((x)>>(8*(y)))
1014 for (
unsigned int i=8*
sizeof(value)/2; i>0; i/=2)
1015 value ^= value >> i;
1016 return (
unsigned int)value&1;
1029 unsigned int l=0, h=8*
sizeof(value);
1032 unsigned int t = (l+h)/2;
1052 unsigned int l=0, h=8*
sizeof(value);
1056 unsigned int t = (l+h)/2;
1079 return (
unsigned int)_tzcnt_u32(v);
1080#elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400)
1081 return (
unsigned int)__builtin_ctz(v);
1082#elif defined(CRYPTOPP_MSC_VERSION) && (CRYPTOPP_MSC_VERSION >= 1400)
1083 unsigned long result;
1084 _BitScanForward(&result, v);
1085 return static_cast<unsigned int>(result);
1088 static const int MultiplyDeBruijnBitPosition[32] =
1090 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
1091 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
1093 return MultiplyDeBruijnBitPosition[((
word32)((v & -v) * 0x077CB531U)) >> 27];
1109#if defined(__BMI__) && defined(__x86_64__)
1110 return (
unsigned int)_tzcnt_u64(v);
1111#elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400)
1112 return (
unsigned int)__builtin_ctzll(v);
1113#elif defined(CRYPTOPP_MSC_VERSION) && (CRYPTOPP_MSC_VERSION >= 1400) && (defined(_M_X64) || defined(_M_IA64))
1114 unsigned long result;
1115 _BitScanForward64(&result, v);
1116 return static_cast<unsigned int>(result);
1133 if (bits < 8*
sizeof(value))
1134 return T(value & ((T(1) << bits) - 1));
1145 return ((bitCount+7)/(8));
1217 return value > 0 && (value & (value-1)) == 0;
1222inline bool IsPowerOf2<word32>(
const word32 &value)
1224 return value > 0 && _blsr_u32(value) == 0;
1227# if defined(__x86_64__)
1229inline bool IsPowerOf2<word64>(
const word64 &value)
1231 return value > 0 && _blsr_u64(value) == 0;
1251 return (std::numeric_limits<T>::min)();
1269 return (std::numeric_limits<T>::max)();
1274#if defined(CRYPTOPP_WORD128_AVAILABLE)
1283#if defined(CRYPTOPP_APPLE_CLANG_VERSION)
1286 return (std::numeric_limits<word128>::max)();
1301template <
class T1,
class T2>
1305 return T1((a > b) ? (a - b) : 0);
1318template <
class T1,
class T2>
1322 return T1((a > b) ? (a - b) : 1);
1333template <
class T1,
class T2>
1353template <
class T1,
class T2>
1357#if !defined(CRYPTOPP_APPLE_CLANG_VERSION) || (CRYPTOPP_APPLE_CLANG_VERSION >= 80000)
1383template <
class T1,
class T2>
1387#if !defined(CRYPTOPP_APPLE_CLANG_VERSION) || (CRYPTOPP_APPLE_CLANG_VERSION >= 80000)
1395 if (NumericLimitsMax<T1>() - m + 1 < n)
1411#if defined(CRYPTOPP_CXX11_ALIGNOF)
1413#elif (CRYPTOPP_MSC_VERSION >= 1300)
1414 return __alignof(T);
1415#elif defined(__GNUC__)
1416 return __alignof__(T);
1417#elif defined(__SUNPRO_CC)
1418 return __alignof__(T);
1419#elif defined(__IBM_ALIGNOF__)
1420 return __alignof__(T);
1421#elif CRYPTOPP_BOOL_SLOW_WORD64
1438 const uintptr_t x =
reinterpret_cast<uintptr_t
>(ptr);
1439 return alignment==1 || (
IsPowerOf2(alignment) ?
ModPowerOf2(x, alignment) == 0 : x % alignment == 0);
1455#if (CRYPTOPP_LITTLE_ENDIAN)
1457#elif (CRYPTOPP_BIG_ENDIAN)
1460# error "Unable to determine endianness"
1475 return NativeByteOrder::ToEnum();
1512 unsigned int carry=1;
1513 while (carry && size != 0)
1516 carry = ! ++inout[size-1];
1533 unsigned int carry=1;
1534 while (carry && size != 0)
1537 carry = ! (output[size-1] = input[size-1] + 1);
1543 output[size-1] = input[size-1];
1569 ptrdiff_t t = size_t(c) * (a - b);
1588 volatile T *p = buf+n;
1593#if !defined(CRYPTOPP_DISABLE_ASM) && \
1594 (CRYPTOPP_MSC_VERSION >= 1400 || defined(__GNUC__)) && \
1595 (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86)
1604 volatile byte *p = buf;
1606 asm volatile(
"rep stosb" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1608 __stosb(
reinterpret_cast<byte *
>(
reinterpret_cast<size_t>(p)), 0, n);
1619 volatile word16 *p = buf;
1621 asm volatile(
"rep stosw" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1623 __stosw(
reinterpret_cast<word16 *
>(
reinterpret_cast<size_t>(p)), 0, n);
1634 volatile word32 *p = buf;
1636 asm volatile(
"rep stosl" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1638 __stosd(
reinterpret_cast<unsigned long *
>(
reinterpret_cast<size_t>(p)), 0, n);
1649#if CRYPTOPP_BOOL_X64
1650 volatile word64 *p = buf;
1652 asm volatile(
"rep stosq" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1654 __stosq(
const_cast<word64 *
>(p), 0, n);
1663#if !defined(CRYPTOPP_DISABLE_ASM) && (CRYPTOPP_MSC_VERSION >= 1700) && defined(_M_ARM)
1666 char *p =
reinterpret_cast<char*
>(buf+n);
1668 __iso_volatile_store8(--p, 0);
1673 short *p =
reinterpret_cast<short*
>(buf+n);
1675 __iso_volatile_store16(--p, 0);
1680 int *p =
reinterpret_cast<int*
>(buf+n);
1682 __iso_volatile_store32(--p, 0);
1687 __int64 *p =
reinterpret_cast<__int64*
>(buf+n);
1689 __iso_volatile_store64(--p, 0);
1702 if (
sizeof(T) % 8 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word64>() == 0)
1704 else if (
sizeof(T) % 4 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word32>() == 0)
1706 else if (
sizeof(T) % 2 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word16>() == 0)
1709 SecureWipeBuffer(
reinterpret_cast<byte *
>(
static_cast<void *
>(buf)), n *
sizeof(T));
1763 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1764 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1766 return T((x<<R)|(x>>(-R&MASK)));
1789 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1790 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1792 return T((x >> R)|(x<<(-R&MASK)));
1814 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1815 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1817 return T((x<<y)|(x>>(-y&MASK)));
1839 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1840 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1842 return T((x >> y)|(x<<(-y&MASK)));
1859 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1860 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1862 return T((x<<y)|(x>>(-y&MASK)));
1879 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1880 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1882 return T((x>>y)|(x<<(-y&MASK)));
1894template <
class T>
inline T
rotlMod(T x,
unsigned int y)
1896 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1897 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1898 return T((x<<(y&MASK))|(x>>(-y&MASK)));
1910template <
class T>
inline T
rotrMod(T x,
unsigned int y)
1912 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1913 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1914 return T((x>>(y&MASK))|(x<<(-y&MASK)));
1917#ifdef CRYPTOPP_MSC_VERSION
1928template<>
inline word32 rotlFixed<word32>(
word32 x,
unsigned int y)
1932 return y ? _lrotl(x,
static_cast<byte>(y)) : x;
1944template<>
inline word32 rotrFixed<word32>(
word32 x,
unsigned int y)
1948 return y ? _lrotr(x,
static_cast<byte>(y)) : x;
1960template<>
inline word32 rotlVariable<word32>(
word32 x,
unsigned int y)
1963 return _lrotl(x,
static_cast<byte>(y));
1975template<>
inline word32 rotrVariable<word32>(
word32 x,
unsigned int y)
1978 return _lrotr(x,
static_cast<byte>(y));
1989template<>
inline word32 rotlMod<word32>(
word32 x,
unsigned int y)
1992 return _lrotl(x,
static_cast<byte>(y));
2003template<>
inline word32 rotrMod<word32>(
word32 x,
unsigned int y)
2006 return _lrotr(x,
static_cast<byte>(y));
2011#if (CRYPTOPP_MSC_VERSION >= 1400) || (defined(CRYPTOPP_MSC_VERSION) && !defined(_DLL))
2023template<>
inline word64 rotlFixed<word64>(
word64 x,
unsigned int y)
2027 return y ? _rotl64(x,
static_cast<byte>(y)) : x;
2039template<>
inline word64 rotrFixed<word64>(
word64 x,
unsigned int y)
2043 return y ? _rotr64(x,
static_cast<byte>(y)) : x;
2055template<>
inline word64 rotlVariable<word64>(
word64 x,
unsigned int y)
2058 return _rotl64(x,
static_cast<byte>(y));
2070template<>
inline word64 rotrVariable<word64>(
word64 x,
unsigned int y)
2073 return y ? _rotr64(x,
static_cast<byte>(y)) : x;
2084template<>
inline word64 rotlMod<word64>(
word64 x,
unsigned int y)
2087 return y ? _rotl64(x,
static_cast<byte>(y)) : x;
2098template<>
inline word64 rotrMod<word64>(
word64 x,
unsigned int y)
2101 return y ? _rotr64(x,
static_cast<byte>(y)) : x;
2106#if CRYPTOPP_MSC_VERSION >= 1400 && !defined(__INTEL_COMPILER)
2108template<>
inline word16 rotlFixed<word16>(
word16 x,
unsigned int y)
2111 return _rotl16(x,
static_cast<byte>(y));
2114template<>
inline word16 rotrFixed<word16>(
word16 x,
unsigned int y)
2117 return _rotr16(x,
static_cast<byte>(y));
2120template<>
inline word16 rotlVariable<word16>(
word16 x,
unsigned int y)
2122 return _rotl16(x,
static_cast<byte>(y));
2125template<>
inline word16 rotrVariable<word16>(
word16 x,
unsigned int y)
2127 return _rotr16(x,
static_cast<byte>(y));
2130template<>
inline word16 rotlMod<word16>(
word16 x,
unsigned int y)
2132 return _rotl16(x,
static_cast<byte>(y));
2135template<>
inline word16 rotrMod<word16>(
word16 x,
unsigned int y)
2137 return _rotr16(x,
static_cast<byte>(y));
2140template<>
inline byte rotlFixed<byte>(
byte x,
unsigned int y)
2143 return _rotl8(x,
static_cast<byte>(y));
2146template<>
inline byte rotrFixed<byte>(
byte x,
unsigned int y)
2149 return _rotr8(x,
static_cast<byte>(y));
2152template<>
inline byte rotlVariable<byte>(
byte x,
unsigned int y)
2154 return _rotl8(x,
static_cast<byte>(y));
2157template<>
inline byte rotrVariable<byte>(
byte x,
unsigned int y)
2159 return _rotr8(x,
static_cast<byte>(y));
2162template<>
inline byte rotlMod<byte>(
byte x,
unsigned int y)
2164 return _rotl8(x,
static_cast<byte>(y));
2167template<>
inline byte rotrMod<byte>(
byte x,
unsigned int y)
2169 return _rotr8(x,
static_cast<byte>(y));
2174#if (defined(__MWERKS__) && TARGET_CPU_PPC)
2176template<>
inline word32 rotlFixed<word32>(
word32 x,
unsigned int y)
2179 return y ? __rlwinm(x,y,0,31) : x;
2182template<>
inline word32 rotrFixed<word32>(
word32 x,
unsigned int y)
2185 return y ? __rlwinm(x,32-y,0,31) : x;
2188template<>
inline word32 rotlVariable<word32>(
word32 x,
unsigned int y)
2191 return (__rlwnm(x,y,0,31));
2194template<>
inline word32 rotrVariable<word32>(
word32 x,
unsigned int y)
2197 return (__rlwnm(x,32-y,0,31));
2200template<>
inline word32 rotlMod<word32>(
word32 x,
unsigned int y)
2202 return (__rlwnm(x,y,0,31));
2205template<>
inline word32 rotrMod<word32>(
word32 x,
unsigned int y)
2207 return (__rlwnm(x,32-y,0,31));
2222 return GETBYTE(value, index);
2224 return GETBYTE(value,
sizeof(T)-index-1);
2242#if defined(CRYPTOPP_BYTESWAP_AVAILABLE)
2243 return bswap_16(value);
2244#elif (CRYPTOPP_MSC_VERSION >= 1400) || (defined(CRYPTOPP_MSC_VERSION) && !defined(_DLL))
2245 return _byteswap_ushort(value);
2257#if defined(CRYPTOPP_BYTESWAP_AVAILABLE)
2258 return bswap_32(value);
2259#elif defined(CRYPTOPP_ARM_BYTEREV_AVAILABLE)
2261 __asm__ (
"rev %0, %1" :
"=r" (rvalue) :
"r" (value));
2263#elif defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE)
2264 __asm__ (
"bswap %0" :
"=r" (value) :
"0" (value));
2266#elif defined(__MWERKS__) && TARGET_CPU_PPC
2267 return (
word32)__lwbrx(&value,0);
2268#elif (CRYPTOPP_MSC_VERSION >= 1400) || (defined(CRYPTOPP_MSC_VERSION) && !defined(_DLL))
2269 return _byteswap_ulong(value);
2270#elif CRYPTOPP_FAST_ROTATE(32) && !defined(__xlC__)
2275 value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
2286#if defined(CRYPTOPP_BYTESWAP_AVAILABLE)
2287 return bswap_64(value);
2288#elif defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(__x86_64__)
2289 __asm__ (
"bswap %0" :
"=r" (value) :
"0" (value));
2291#elif (CRYPTOPP_MSC_VERSION >= 1400) || (defined(CRYPTOPP_MSC_VERSION) && !defined(_DLL))
2292 return _byteswap_uint64(value);
2293#elif CRYPTOPP_BOOL_SLOW_WORD64
2296 value = ((value &
W64LIT(0xFF00FF00FF00FF00)) >> 8) | ((value &
W64LIT(0x00FF00FF00FF00FF)) << 8);
2297 value = ((value &
W64LIT(0xFFFF0000FFFF0000)) >> 16) | ((value &
W64LIT(0x0000FFFF0000FFFF)) << 16);
2302#if defined(CRYPTOPP_WORD128_AVAILABLE)
2321 value =
byte((value & 0xAA) >> 1) |
byte((value & 0x55) << 1);
2322 value =
byte((value & 0xCC) >> 2) |
byte((value & 0x33) << 2);
2331#if defined(CRYPTOPP_ARM_BITREV_AVAILABLE)
2334 __asm__ (
"rbit %0, %1" :
"=r" (rvalue) :
"r" (value));
2335 return word16(rvalue >> 16);
2338 value =
word16((value & 0xAAAA) >> 1) |
word16((value & 0x5555) << 1);
2339 value =
word16((value & 0xCCCC) >> 2) |
word16((value & 0x3333) << 2);
2340 value =
word16((value & 0xF0F0) >> 4) |
word16((value & 0x0F0F) << 4);
2350#if defined(CRYPTOPP_ARM_BITREV_AVAILABLE)
2353 __asm__ (
"rbit %0, %1" :
"=r" (rvalue) :
"r" (value));
2357 value =
word32((value & 0xAAAAAAAA) >> 1) |
word32((value & 0x55555555) << 1);
2358 value =
word32((value & 0xCCCCCCCC) >> 2) |
word32((value & 0x33333333) << 2);
2359 value =
word32((value & 0xF0F0F0F0) >> 4) |
word32((value & 0x0F0F0F0F) << 4);
2369#if CRYPTOPP_BOOL_SLOW_WORD64
2392 else if (
sizeof(T) == 2)
2394 else if (
sizeof(T) == 4)
2396 else if (
sizeof(T) == 8)
2398#if defined(CRYPTOPP_WORD128_AVAILABLE)
2399 else if (
sizeof(T) == 16)
2465 size_t count = byteCount/
sizeof(T);
2466 for (
size_t i=0; i<count; i++)
2489 memcpy_s(out, byteCount, in, byteCount);
2502 const size_t U =
sizeof(T);
2504 memcpy_s(out, outlen*U, in, inlen);
2505 memset_z((
byte *)out+inlen, 0, outlen*U-inlen);
2518 CRYPTOPP_UNUSED(order); CRYPTOPP_UNUSED(unused);
2531 CRYPTOPP_UNUSED(unused);
2533 ? block[1] | (block[0] << 8)
2534 : block[0] | (block[1] << 8);
2546 CRYPTOPP_UNUSED(unused);
2561 CRYPTOPP_UNUSED(unused);
2565 (
word64(block[6]) << 8) |
2566 (
word64(block[5]) << 16) |
2567 (
word64(block[4]) << 24) |
2568 (
word64(block[3]) << 32) |
2569 (
word64(block[2]) << 40) |
2570 (
word64(block[1]) << 48) |
2571 (
word64(block[0]) << 56))
2574 (
word64(block[1]) << 8) |
2575 (
word64(block[2]) << 16) |
2576 (
word64(block[3]) << 24) |
2577 (
word64(block[4]) << 32) |
2578 (
word64(block[5]) << 40) |
2579 (
word64(block[6]) << 48) |
2580 (
word64(block[7]) << 56));
2583#if defined(CRYPTOPP_WORD128_AVAILABLE)
2594 CRYPTOPP_UNUSED(unused);
2642 CRYPTOPP_UNUSED(order);
2643 block[0] =
static_cast<byte>(xorBlock ? (value ^ xorBlock[0]) : value);
2659 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2660 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2664 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2665 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2672 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2673 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2677 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2678 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2696 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2697 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2698 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2699 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2703 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2704 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2705 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2706 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2713 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2714 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2715 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2716 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2720 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2721 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2722 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2723 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2741 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2742 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2743 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2744 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2745 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2746 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2747 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2748 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2752 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2753 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2754 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2755 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2756 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2757 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2758 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2759 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2766 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2767 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2768 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2769 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2770 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2771 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2772 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2773 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2777 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2778 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2779 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2780 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2781 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2782 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2783 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2784 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2789#if defined(CRYPTOPP_WORD128_AVAILABLE)
2804 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 15);
2805 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 14);
2806 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 13);
2807 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 12);
2808 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 11);
2809 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 10);
2810 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 9);
2811 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 8);
2813 block[ 8] = xorBlock[ 8] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2814 block[ 9] = xorBlock[ 9] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2815 block[10] = xorBlock[10] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2816 block[11] = xorBlock[11] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2817 block[12] = xorBlock[12] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2818 block[13] = xorBlock[13] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2819 block[14] = xorBlock[14] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2820 block[15] = xorBlock[15] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2824 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 15);
2825 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 14);
2826 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 13);
2827 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 12);
2828 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 11);
2829 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 10);
2830 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 9);
2831 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 8);
2833 block[ 8] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2834 block[ 9] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2835 block[10] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2836 block[11] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2837 block[12] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2838 block[13] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2839 block[14] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2840 block[15] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2847 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2848 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2849 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2850 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2851 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2852 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2853 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2854 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2856 block[ 8] = xorBlock[ 8] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 8);
2857 block[ 9] = xorBlock[ 9] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 9);
2858 block[10] = xorBlock[10] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 10);
2859 block[11] = xorBlock[11] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 11);
2860 block[12] = xorBlock[12] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 12);
2861 block[13] = xorBlock[13] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 13);
2862 block[14] = xorBlock[14] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 14);
2863 block[15] = xorBlock[15] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 15);
2867 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2868 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2869 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2870 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2871 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2872 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2873 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2874 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2876 block[ 8] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 8);
2877 block[ 9] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 9);
2878 block[10] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 10);
2879 block[11] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 11);
2880 block[12] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 12);
2881 block[13] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 13);
2882 block[14] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 14);
2883 block[15] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 15);
2908 CRYPTOPP_UNUSED(assumeAligned);
2911 if (block != NULLPTR) {std::memcpy(&temp, block,
sizeof(T));}
2934 result = GetWord<T>(assumeAligned, order, block);
2948inline void PutWord(
bool assumeAligned,
ByteOrder order,
byte *block, T value,
const byte *xorBlock = NULLPTR)
2950 CRYPTOPP_UNUSED(assumeAligned);
2954 if (xorBlock != NULLPTR) {std::memcpy(&t2, xorBlock,
sizeof(T)); t1 ^= t2;}
2955 if (block != NULLPTR) {std::memcpy(block, &t1,
sizeof(T));}
2973template <
class T,
class B,
bool A=false>
2980 : m_block((const
byte *)block) {}
2990 x = GetWord<T>(A, B::ToEnum(), m_block);
2991 m_block +=
sizeof(T);
2996 const byte *m_block;
3014template <
class T,
class B,
bool A=false>
3022 : m_xorBlock((const
byte *)xorBlock), m_block((
byte *)block) {}
3031 PutWord(A, B::ToEnum(), m_block, (T)x, m_xorBlock);
3032 m_block +=
sizeof(T);
3034 m_xorBlock +=
sizeof(T);
3039 const byte *m_xorBlock;
3051template <
class T,
class B,
bool GA=false,
bool PA=false>
3070 return std::string((
char *)&value,
sizeof(value));
3109 CRYPTOPP_UNUSED(value); CRYPTOPP_UNUSED(bits);
3121 CRYPTOPP_UNUSED(value); CRYPTOPP_UNUSED(bits);
3139 return value >> bits;
3150 return value << bits;
3162template <
unsigned int bits,
class T>
3165 return SafeShifter<(bits>=(8*
sizeof(T)))>::RightShift(value, bits);
3176template <
unsigned int bits,
class T>
3179 return SafeShifter<(bits>=(8*
sizeof(T)))>::LeftShift(value, bits);
3189template<
typename InputIt,
typename T>
3190inline InputIt
FindIfNot(InputIt first, InputIt last,
const T &value) {
3191#ifdef CRYPTOPP_CXX11_LAMBDA
3192 return std::find_if(first, last, [&value](
const T &o) {
3196 return std::find_if(first, last, std::bind2nd(std::not_equal_to<T>(), value));
3202#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);}
3203#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);}
3204#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);}
3205#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);}
3206#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);}
3207#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);}
3208#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);}
3209#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);}
3210#define CRYPTOPP_BLOCKS_END(i) size_t SST() {return SS##i();} void AllocateBlocks() {m_aggregate.New(SST());} AlignedSecByteBlock m_aggregate;
3214#if (CRYPTOPP_MSC_VERSION)
3215# pragma warning(pop)
3218#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
3219# pragma GCC diagnostic pop
Access a block of memory.
GetBlock< T, B, A > & operator()(U &x)
Access a block of memory.
GetBlock(const void *block)
Construct a GetBlock.
Multiple precision integer with arithmetic operations.
An invalid argument was detected.
Ensures an object is not copyable.
Uses encapsulation to hide an object in derived classes.
Access a block of memory.
PutBlock< T, B, A > & operator()(U x)
Access a block of memory.
PutBlock(const void *xorBlock, void *block)
Construct a PutBlock.
Restricts the instantiation of a class to one static object without locks.
const T & Ref(...) const
Return a reference to the inner Singleton object.
Manages resources for a single object.
Library configuration file.
#define CRYPTOPP_API
Win32 calling convention.
signed long long sword64
64-bit signed datatype
unsigned char byte
8-bit unsigned datatype
#define W64LIT(x)
Declare an unsigned word64.
const lword LWORD_MAX
Large word type max value.
signed int sword32
32-bit signed datatype
__uint128_t word128
128-bit unsigned datatype
const unsigned int WORD_BITS
Size of a platform word in bits.
unsigned int word32
32-bit unsigned datatype
unsigned short word16
16-bit unsigned datatype
unsigned long long word64
64-bit unsigned datatype
const unsigned int WORD_SIZE
Size of a platform word in bytes.
Abstract base classes that provide a uniform interface to this library.
CipherDir
Specifies a direction for a cipher to operate.
@ ENCRYPTION
the cipher is performing encryption
@ DECRYPTION
the cipher is performing decryption
ByteOrder
Provides the byte ordering.
@ LITTLE_ENDIAN_ORDER
byte order is little-endian
@ BIG_ENDIAN_ORDER
byte order is big-endian
T rotlConstant(T x)
Performs a left rotate.
T rotlVariable(T x, unsigned int y)
Performs a left rotate.
byte BitReverse(byte value)
Reverses bits in a 8-bit value.
std::string WordToString(T value, ByteOrder order=BIG_ENDIAN_ORDER)
Convert a word to a string.
CRYPTOPP_DLL std::string IntToString< Integer >(Integer value, unsigned int base)
Converts an Integer to a string.
byte ByteReverse(byte value)
Reverses bytes in a 8-bit value.
T StringToWord(const std::string &str, ByteOrder order=BIG_ENDIAN_ORDER)
Convert a string to a word.
T GetWord(bool assumeAligned, ByteOrder order, const byte *block)
Access a block of memory.
size_t BytePtrSize(const std::string &str)
Size of a string.
T1 SaturatingSubtract(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 0.
void * memset_z(void *ptr, int val, size_t num)
Memory block initializer.
const T & STDMAX(const T &a, const T &b)
Replacement function for std::max.
unsigned int BitPrecision(const T &value)
Returns the number of bits required for a value.
unsigned int BytePrecision(const T &value)
Returns the number of 8-bit bytes or octets required for a value.
void IncrementCounterByOne(byte *inout, unsigned int size)
Performs an addition with carry on a block of bytes.
size_t BitsToWords(size_t bitCount)
Returns the number of words required for the specified number of bits.
T SafeLeftShift(T value)
Safely left shift values when undefined behavior could occur.
unsigned int TrailingZeros(word32 v)
Determines the number of trailing 0-bits in a value.
void SecureWipeArray(T *buf, size_t n)
Sets each element of an array to 0.
void ConditionalSwapPointers(bool c, T &a, T &b)
Performs a branch-less swap of pointers a and b if condition c is true.
T1 RoundUpToMultipleOf(const T1 &n, const T2 &m)
Rounds a value up to a multiple of a second value.
PTR PtrSub(PTR pointer, OFF offset)
Create a pointer with an offset.
void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
Bounds checking replacement for memcpy()
T Crop(T value, size_t bits)
Truncates the value to the specified number of bits.
T2 ModPowerOf2(const T1 &a, const T2 &b)
Reduces a value to a power of 2.
bool IsPowerOf2(const T &value)
Tests whether a value is a power of 2.
void SecureWipeBuffer(T *buf, size_t n)
Sets each element of an array to 0.
T NumericLimitsMin()
Provide the minimum value for a type.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
#define CRYPTOPP_COMPILE_ASSERT(expr)
Compile time assertion.
bool NativeByteOrderIs(ByteOrder order)
Determines whether order follows native byte ordering.
unsigned int Parity(T value)
Returns the parity of a value.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
bool IsAlignedOn(const void *ptr, unsigned int alignment)
Determines whether ptr is aligned to a minimum value.
size_t BitsToDwords(size_t bitCount)
Returns the number of double words required for the specified number of bits.
size_t BitsToBytes(size_t bitCount)
Returns the number of 8-bit bytes or octets required for the specified number of bits.
T rotrConstant(T x)
Performs a right rotate.
const byte * ConstBytePtr(const std::string &str)
Const pointer to the first element of a string.
#define MEMORY_BARRIER
A memory barrier.
void vec_swap(T &a, T &b)
Swaps two variables which are arrays.
void UnalignedbyteNonTemplate(ByteOrder order, byte *block, byte value, const byte *xorBlock)
Write a byte to an unaligned buffer.
size_t BytesToWords(size_t byteCount)
Returns the number of words required for the specified number of bytes.
bool SafeConvert(T1 from, T2 &to)
Perform a conversion from from to to.
bool IsAligned(const void *ptr)
Determines whether ptr is minimally aligned.
T ConditionalByteReverse(ByteOrder order, T value)
Reverses bytes in a value depending upon endianness.
void GetUserKey(ByteOrder order, T *out, size_t outlen, const byte *in, size_t inlen)
Copy bytes in a buffer to an array of elements in big-endian order.
unsigned int GetByte(ByteOrder order, T value, unsigned int index)
Gets a byte from a value.
ptrdiff_t PtrDiff(const PTR pointer1, const PTR pointer2)
Determine pointer difference.
T1 RoundDownToMultipleOf(const T1 &n, const T2 &m)
Rounds a value down to a multiple of a second value.
CRYPTOPP_DLL std::string IntToString< word64 >(word64 value, unsigned int base)
Converts an unsigned value to a string.
T rotlFixed(T x, unsigned int y)
Performs a left rotate.
InputIt FindIfNot(InputIt first, InputIt last, const T &value)
Finds first element not in a range.
byte UnalignedGetWordNonTemplate(ByteOrder order, const byte *block, const byte *unused)
Retrieve a byte from an unaligned buffer.
unsigned int GetAlignmentOf()
Returns the minimum alignment requirements of a type.
std::string StringNarrow(const wchar_t *str, bool throwOnError=true)
Converts a wide character C-string to a multibyte string.
T rotrVariable(T x, unsigned int y)
Performs a right rotate.
T SafeRightShift(T value)
Safely right shift values when undefined behavior could occur.
PTR PtrAdd(PTR pointer, OFF offset)
Create a pointer with an offset.
T rotrFixed(T x, unsigned int y)
Performs a right rotate.
const T1 UnsignedMin(const T1 &a, const T2 &b)
Safe comparison of values that could be negative and incorrectly promoted.
std::wstring StringWiden(const char *str, bool throwOnError=true)
Converts a multibyte C-string to a wide character string.
size_t PtrByteDiff(const PTR pointer1, const PTR pointer2)
Determine pointer difference.
#define EnumToInt(v)
Integer value.
T rotlMod(T x, unsigned int y)
Performs a left rotate.
byte * BytePtr(std::string &str)
Pointer to the first element of a string.
void memmove_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
Bounds checking replacement for memmove()
CipherDir GetCipherDir(const T &obj)
Returns the direction the cipher is being operated.
void ConditionalSwap(bool c, T &a, T &b)
Performs a branch-less swap of values a and b if condition c is true.
T rotrMod(T x, unsigned int y)
Performs a right rotate.
ByteOrder GetNativeByteOrder()
Returns NativeByteOrder as an enumerated ByteOrder value.
void PutWord(bool assumeAligned, ByteOrder order, byte *block, T value, const byte *xorBlock=NULL)
Access a block of memory.
T NumericLimitsMax()
Provide the maximum value for a type.
CRYPTOPP_DLL bool VerifyBufsEqual(const byte *buf1, const byte *buf2, size_t count)
Performs a near constant-time comparison of two equally sized buffers.
T1 SaturatingSubtract1(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 1.
CRYPTOPP_DLL void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
Crypto++ library namespace.
Forward declarations for SecBlock.
Classes for automatic resource management.
Access a block of memory.
Converts an enumeration to a type suitable for use as a template parameter.
An object factory function.
static T RightShift(T value, unsigned int bits)
Right shifts a value that does not overflow.
static T LeftShift(T value, unsigned int bits)
Left shifts a value that does not overflow.
static T RightShift(T value, unsigned int bits)
Right shifts a value that overflows.
static T LeftShift(T value, unsigned int bits)
Left shifts a value that overflows.
Safely shift values when undefined behavior could occur.
Debugging and diagnostic assertions.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.