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"
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 _MSC_VER >= 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# include <x86intrin.h>
84# include <immintrin.h>
91# define _blsr_u32 __blsr_u32
94# define _blsr_u64 __blsr_u64
97# define _tzcnt_u32 __tzcnt_u32
100# define _tzcnt_u64 __tzcnt_u64
106#if CRYPTOPP_DOXYGEN_PROCESSING
124# if defined(__SIZE_MAX__)
125# define SIZE_MAX __SIZE_MAX__
126# elif defined(SIZE_T_MAX)
127# define SIZE_MAX SIZE_T_MAX
128# elif defined(__SIZE_TYPE__)
129# define SIZE_MAX (~(__SIZE_TYPE__)0)
131# define SIZE_MAX ((std::numeric_limits<size_t>::max)())
144#if CRYPTOPP_DOXYGEN_PROCESSING
151# define CRYPTOPP_COMPILE_ASSERT(expr) { ... }
152#elif defined(CRYPTOPP_CXX17_STATIC_ASSERT)
153# define CRYPTOPP_COMPILE_ASSERT(expr) static_assert(expr)
158 static char dummy[2*b-1];
161#define CRYPTOPP_COMPILE_ASSERT(assertion) CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, __LINE__)
162#define CRYPTOPP_ASSERT_JOIN(X, Y) CRYPTOPP_DO_ASSERT_JOIN(X, Y)
163#define CRYPTOPP_DO_ASSERT_JOIN(X, Y) X##Y
165#if defined(CRYPTOPP_EXPORTS) || defined(CRYPTOPP_IMPORTS)
166# define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance)
168# if defined(__GNUC__) || defined(__clang__)
169# define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance) \
170 static CompileAssert<(assertion)> \
171 CRYPTOPP_ASSERT_JOIN(cryptopp_CRYPTOPP_ASSERT_, instance) __attribute__ ((unused))
173# define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance) \
174 static CompileAssert<(assertion)> \
175 CRYPTOPP_ASSERT_JOIN(cryptopp_CRYPTOPP_ASSERT_, instance)
183#if CRYPTOPP_DOXYGEN_PROCESSING
195# if defined(_MSC_VER) && (_MSC_VER >= 1400)
196# define COUNTOF(x) _countof(x)
198# define COUNTOF(x) (sizeof(x)/sizeof(x[0]))
211#if !defined(CRYPTOPP_DOXYGEN_PROCESSING)
212template <
class BASE1,
class BASE2>
213class CRYPTOPP_NO_VTABLE TwoBases :
public BASE1,
public BASE2
217template <
class BASE1,
class BASE2,
class BASE3>
218class CRYPTOPP_NO_VTABLE ThreeBases :
public BASE1,
public BASE2,
public BASE3
242#if CRYPTOPP_CXX11_DELETED_FUNCTIONS
258 T* operator()()
const {
return new T;}
261#if CRYPTOPP_DOXYGEN_PROCESSING
270#define MEMORY_BARRIER ...
272#if defined(CRYPTOPP_CXX11_ATOMIC)
273# define MEMORY_BARRIER() std::atomic_thread_fence(std::memory_order_acq_rel)
274#elif (_MSC_VER >= 1400)
275# pragma intrinsic(_ReadWriteBarrier)
276# define MEMORY_BARRIER() _ReadWriteBarrier()
277#elif defined(__INTEL_COMPILER)
278# define MEMORY_BARRIER() __memory_barrier()
279#elif defined(__GNUC__) || defined(__clang__)
280# define MEMORY_BARRIER() __asm__ __volatile__ ("" ::: "memory")
282# define MEMORY_BARRIER()
305template <
class T,
class F = NewObject<T>,
int instance=0>
309 Singleton(F objectFactory = F()) : m_objectFactory(objectFactory) {}
312 CRYPTOPP_NOINLINE
const T &
Ref(CRYPTOPP_NOINLINE_DOTDOTDOT)
const;
326template <
class T,
class F,
int instance>
329#if defined(CRYPTOPP_CXX11_ATOMIC) && defined(CRYPTOPP_CXX11_SYNCHRONIZATION) && defined(CRYPTOPP_CXX11_STATIC_INIT)
330 static std::mutex s_mutex;
331 static std::atomic<T*> s_pObject;
333 T *p = s_pObject.load(std::memory_order_relaxed);
334 std::atomic_thread_fence(std::memory_order_acquire);
339 std::lock_guard<std::mutex> lock(s_mutex);
340 p = s_pObject.load(std::memory_order_relaxed);
341 std::atomic_thread_fence(std::memory_order_acquire);
346 T *newObject = m_objectFactory();
347 s_pObject.store(newObject, std::memory_order_relaxed);
348 std::atomic_thread_fence(std::memory_order_release);
353 T *p = s_pObject.m_p;
359 T *newObject = m_objectFactory();
369 s_pObject.m_p = newObject;
385template <
typename PTR,
typename OFF>
386inline PTR
PtrAdd(PTR pointer, OFF offset)
388 return pointer+
static_cast<ptrdiff_t
>(offset);
398template <
typename PTR,
typename OFF>
399inline PTR
PtrSub(PTR pointer, OFF offset)
401 return pointer-
static_cast<ptrdiff_t
>(offset);
413template <
typename PTR>
414inline ptrdiff_t
PtrDiff(
const PTR pointer1,
const PTR pointer2)
416 return pointer1 - pointer2;
428template <
typename PTR>
431 return (
size_t)(
reinterpret_cast<uintptr_t
>(pointer1) -
reinterpret_cast<uintptr_t
>(pointer2));
446 return reinterpret_cast<byte*
>(&str[0]);
465 return reinterpret_cast<const byte*
>(&str[0]);
496#if (CRYPTOPP_CXX11_CONSTEXPR)
499 return static_cast<int>(v);
502# define EnumToInt(v) static_cast<int>(v)
505#if (!__STDC_WANT_SECURE_LIB__ && !defined(_MEMORY_S_DEFINED)) || defined(CRYPTOPP_WANT_SECURE_LIB)
525inline void memcpy_s(
void *dest,
size_t sizeInBytes,
const void *src,
size_t count)
536 if (count > sizeInBytes)
539#if CRYPTOPP_MSC_VERSION
540# pragma warning(push)
541# pragma warning(disable: 4996)
542# if (CRYPTOPP_MSC_VERSION >= 1400)
543# pragma warning(disable: 6386)
546 if (src != NULLPTR && dest != NULLPTR)
547 std::memcpy(dest, src, count);
548#if CRYPTOPP_MSC_VERSION
571inline void memmove_s(
void *dest,
size_t sizeInBytes,
const void *src,
size_t count)
580 if (count > sizeInBytes)
583#if CRYPTOPP_MSC_VERSION
584# pragma warning(push)
585# pragma warning(disable: 4996)
586# if (CRYPTOPP_MSC_VERSION >= 1400)
587# pragma warning(disable: 6386)
590 if (src != NULLPTR && dest != NULLPTR)
591 std::memmove(dest, src, count);
592#if CRYPTOPP_MSC_VERSION
597#if __BORLANDC__ >= 0x620
600# define memcpy_s CryptoPP::memcpy_s
601# define memmove_s CryptoPP::memmove_s
621#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5120)
638inline void *
memset_z(
void *ptr,
int val,
size_t num)
641#if CRYPTOPP_GCC_VERSION >= 30001 || CRYPTOPP_LLVM_CLANG_VERSION >= 20800 || \
642 CRYPTOPP_APPLE_CLANG_VERSION >= 30000
643 if (__builtin_constant_p(num) && num==0)
646 return std::memset(ptr, val, num);
655template <
class T>
inline const T&
STDMIN(
const T& a,
const T& b)
657 return b < a ? b : a;
666template <
class T>
inline const T&
STDMAX(
const T& a,
const T& b)
668 return a < b ? b : a;
671#if CRYPTOPP_MSC_VERSION
672# pragma warning(push)
673# pragma warning(disable: 4389)
676#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
677# pragma GCC diagnostic push
678# pragma GCC diagnostic ignored "-Wsign-compare"
679# pragma GCC diagnostic ignored "-Wstrict-overflow"
680# if (CRYPTOPP_LLVM_CLANG_VERSION >= 20800) || (CRYPTOPP_APPLE_CLANG_VERSION >= 30000)
681# pragma GCC diagnostic ignored "-Wtautological-compare"
682# elif (CRYPTOPP_GCC_VERSION >= 40300)
683# pragma GCC diagnostic ignored "-Wtype-limits"
694template <
class T1,
class T2>
inline const T1
UnsignedMin(
const T1& a,
const T2& b)
697 if (
sizeof(T1)<=
sizeof(T2))
698 return b < (T2)a ? (T1)b : a;
700 return (T1)b < a ? (T1)b : a;
709template <
class T1,
class T2>
712 to =
static_cast<T2
>(from);
713 if (from != to || (from > 0) != (to > 0))
727 const unsigned int HIGH_BIT = (1U << 31);
728 const char CH = !!(base & HIGH_BIT) ?
'A' :
'a';
744 T digit = value % base;
745 result = char((digit < 10 ?
'0' : (CH - 10)) + digit) + result;
749 result =
"-" + result;
759template <> CRYPTOPP_DLL
781template <> CRYPTOPP_DLL
784#if CRYPTOPP_MSC_VERSION
788#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
789# pragma GCC diagnostic pop
792#define RETURN_IF_NONZERO(x) size_t returnedValue = x; if (returnedValue) return returnedValue
795#define GETBYTE(x, y) (unsigned int)byte((x)>>(8*(y)))
800#define CRYPTOPP_GET_BYTE_AS_BYTE(x, y) byte((x)>>(8*(y)))
809 for (
unsigned int i=8*
sizeof(value)/2; i>0; i/=2)
811 return (
unsigned int)value&1;
824 unsigned int l=0, h=8*
sizeof(value);
827 unsigned int t = (l+h)/2;
847 unsigned int l=0, h=8*
sizeof(value);
851 unsigned int t = (l+h)/2;
874 return (
unsigned int)_tzcnt_u32(v);
875#elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400)
876 return (
unsigned int)__builtin_ctz(v);
877#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
878 unsigned long result;
879 _BitScanForward(&result, v);
880 return static_cast<unsigned int>(result);
883 static const int MultiplyDeBruijnBitPosition[32] =
885 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
886 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
888 return MultiplyDeBruijnBitPosition[((
word32)((v & -v) * 0x077CB531U)) >> 27];
904#if defined(__BMI__) && defined(__x86_64__)
905 return (
unsigned int)_tzcnt_u64(v);
906#elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400)
907 return (
unsigned int)__builtin_ctzll(v);
908#elif defined(_MSC_VER) && (_MSC_VER >= 1400) && (defined(_M_X64) || defined(_M_IA64))
909 unsigned long result;
910 _BitScanForward64(&result, v);
911 return static_cast<unsigned int>(result);
926inline T
Crop(T value,
size_t bits)
928 if (bits < 8*
sizeof(value))
929 return T(value & ((T(1) << bits) - 1));
940 return ((bitCount+7)/(8));
988CRYPTOPP_DLL
void CRYPTOPP_API xorbuf(
byte *output,
const byte *input,
const byte *mask,
size_t count);
1012 return value > 0 && (value & (value-1)) == 0;
1017inline bool IsPowerOf2<word32>(
const word32 &value)
1019 return value > 0 && _blsr_u32(value) == 0;
1022# if defined(__x86_64__)
1024inline bool IsPowerOf2<word64>(
const word64 &value)
1026 return value > 0 && _blsr_u64(value) == 0;
1046 return (std::numeric_limits<T>::min)();
1064 return (std::numeric_limits<T>::max)();
1069#if defined(CRYPTOPP_WORD128_AVAILABLE)
1092template <
class T1,
class T2>
1096 return T1((a > b) ? (a - b) : 0);
1109template <
class T1,
class T2>
1113 return T1((a > b) ? (a - b) : 1);
1124template <
class T1,
class T2>
1144template <
class T1,
class T2>
1148#if !defined(CRYPTOPP_APPLE_CLANG_VERSION) || (CRYPTOPP_APPLE_CLANG_VERSION >= 80000)
1174template <
class T1,
class T2>
1178#if !defined(CRYPTOPP_APPLE_CLANG_VERSION) || (CRYPTOPP_APPLE_CLANG_VERSION >= 80000)
1186 if (NumericLimitsMax<T1>() - m + 1 < n)
1202#if defined(CRYPTOPP_CXX11_ALIGNOF)
1204#elif (_MSC_VER >= 1300)
1205 return __alignof(T);
1206#elif defined(__GNUC__)
1207 return __alignof__(T);
1208#elif defined(__SUNPRO_CC)
1209 return __alignof__(T);
1210#elif defined(__IBM_ALIGNOF__)
1211 return __alignof__(T);
1212#elif CRYPTOPP_BOOL_SLOW_WORD64
1229 const uintptr_t x =
reinterpret_cast<uintptr_t
>(ptr);
1230 return alignment==1 || (
IsPowerOf2(alignment) ?
ModPowerOf2(x, alignment) == 0 : x % alignment == 0);
1246#if (CRYPTOPP_LITTLE_ENDIAN)
1248#elif (CRYPTOPP_BIG_ENDIAN)
1251# error "Unable to determine endianness"
1266 return NativeByteOrder::ToEnum();
1303 unsigned int carry=1;
1304 while (carry && size != 0)
1307 carry = ! ++inout[size-1];
1324 unsigned int carry=1;
1325 while (carry && size != 0)
1328 carry = ! (output[size-1] = input[size-1] + 1);
1334 output[size-1] = input[size-1];
1360 ptrdiff_t t = size_t(c) * (a - b);
1379 volatile T *p = buf+n;
1384#if !defined(CRYPTOPP_DISABLE_ASM) && \
1385 (_MSC_VER >= 1400 || defined(__GNUC__)) && \
1386 (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86)
1395 volatile byte *p = buf;
1397 asm volatile(
"rep stosb" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1399 __stosb(
reinterpret_cast<byte *
>(
reinterpret_cast<size_t>(p)), 0, n);
1410 volatile word16 *p = buf;
1412 asm volatile(
"rep stosw" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1414 __stosw(
reinterpret_cast<word16 *
>(
reinterpret_cast<size_t>(p)), 0, n);
1425 volatile word32 *p = buf;
1427 asm volatile(
"rep stosl" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1429 __stosd(
reinterpret_cast<unsigned long *
>(
reinterpret_cast<size_t>(p)), 0, n);
1440#if CRYPTOPP_BOOL_X64
1441 volatile word64 *p = buf;
1443 asm volatile(
"rep stosq" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1445 __stosq(
const_cast<word64 *
>(p), 0, n);
1454#if !defined(CRYPTOPP_DISABLE_ASM) && (_MSC_VER >= 1700) && defined(_M_ARM)
1457 char *p =
reinterpret_cast<char*
>(buf+n);
1459 __iso_volatile_store8(--p, 0);
1464 short *p =
reinterpret_cast<short*
>(buf+n);
1466 __iso_volatile_store16(--p, 0);
1471 int *p =
reinterpret_cast<int*
>(buf+n);
1473 __iso_volatile_store32(--p, 0);
1478 __int64 *p =
reinterpret_cast<__int64*
>(buf+n);
1480 __iso_volatile_store64(--p, 0);
1493 if (
sizeof(T) % 8 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word64>() == 0)
1495 else if (
sizeof(T) % 4 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word32>() == 0)
1497 else if (
sizeof(T) % 2 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word16>() == 0)
1500 SecureWipeBuffer(
reinterpret_cast<byte *
>(
static_cast<void *
>(buf)), n *
sizeof(T));
1554 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1555 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1557 return T((x<<R)|(x>>(-R&MASK)));
1580 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1581 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1583 return T((x >> R)|(x<<(-R&MASK)));
1605 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1606 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1608 return T((x<<y)|(x>>(-y&MASK)));
1630 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1631 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1633 return T((x >> y)|(x<<(-y&MASK)));
1650 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1651 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1653 return T((x<<y)|(x>>(-y&MASK)));
1670 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1671 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1673 return T((x>>y)|(x<<(-y&MASK)));
1685template <
class T>
inline T
rotlMod(T x,
unsigned int y)
1687 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1688 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1689 return T((x<<(y&MASK))|(x>>(-y&MASK)));
1701template <
class T>
inline T
rotrMod(T x,
unsigned int y)
1703 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1704 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1705 return T((x>>(y&MASK))|(x<<(-y&MASK)));
1719template<>
inline word32 rotlFixed<word32>(
word32 x,
unsigned int y)
1723 return y ? _lrotl(x,
static_cast<byte>(y)) : x;
1735template<>
inline word32 rotrFixed<word32>(
word32 x,
unsigned int y)
1739 return y ? _lrotr(x,
static_cast<byte>(y)) : x;
1751template<>
inline word32 rotlVariable<word32>(
word32 x,
unsigned int y)
1754 return _lrotl(x,
static_cast<byte>(y));
1766template<>
inline word32 rotrVariable<word32>(
word32 x,
unsigned int y)
1769 return _lrotr(x,
static_cast<byte>(y));
1780template<>
inline word32 rotlMod<word32>(
word32 x,
unsigned int y)
1783 return _lrotl(x,
static_cast<byte>(y));
1794template<>
inline word32 rotrMod<word32>(
word32 x,
unsigned int y)
1797 return _lrotr(x,
static_cast<byte>(y));
1802#if (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL))
1814template<>
inline word64 rotlFixed<word64>(
word64 x,
unsigned int y)
1818 return y ? _rotl64(x,
static_cast<byte>(y)) : x;
1830template<>
inline word64 rotrFixed<word64>(
word64 x,
unsigned int y)
1834 return y ? _rotr64(x,
static_cast<byte>(y)) : x;
1846template<>
inline word64 rotlVariable<word64>(
word64 x,
unsigned int y)
1849 return _rotl64(x,
static_cast<byte>(y));
1861template<>
inline word64 rotrVariable<word64>(
word64 x,
unsigned int y)
1864 return y ? _rotr64(x,
static_cast<byte>(y)) : x;
1875template<>
inline word64 rotlMod<word64>(
word64 x,
unsigned int y)
1878 return y ? _rotl64(x,
static_cast<byte>(y)) : x;
1889template<>
inline word64 rotrMod<word64>(
word64 x,
unsigned int y)
1892 return y ? _rotr64(x,
static_cast<byte>(y)) : x;
1897#if _MSC_VER >= 1400 && !defined(__INTEL_COMPILER)
1899template<>
inline word16 rotlFixed<word16>(
word16 x,
unsigned int y)
1902 return _rotl16(x,
static_cast<byte>(y));
1905template<>
inline word16 rotrFixed<word16>(
word16 x,
unsigned int y)
1908 return _rotr16(x,
static_cast<byte>(y));
1911template<>
inline word16 rotlVariable<word16>(
word16 x,
unsigned int y)
1913 return _rotl16(x,
static_cast<byte>(y));
1916template<>
inline word16 rotrVariable<word16>(
word16 x,
unsigned int y)
1918 return _rotr16(x,
static_cast<byte>(y));
1921template<>
inline word16 rotlMod<word16>(
word16 x,
unsigned int y)
1923 return _rotl16(x,
static_cast<byte>(y));
1926template<>
inline word16 rotrMod<word16>(
word16 x,
unsigned int y)
1928 return _rotr16(x,
static_cast<byte>(y));
1931template<>
inline byte rotlFixed<byte>(
byte x,
unsigned int y)
1934 return _rotl8(x,
static_cast<byte>(y));
1937template<>
inline byte rotrFixed<byte>(
byte x,
unsigned int y)
1940 return _rotr8(x,
static_cast<byte>(y));
1943template<>
inline byte rotlVariable<byte>(
byte x,
unsigned int y)
1945 return _rotl8(x,
static_cast<byte>(y));
1948template<>
inline byte rotrVariable<byte>(
byte x,
unsigned int y)
1950 return _rotr8(x,
static_cast<byte>(y));
1953template<>
inline byte rotlMod<byte>(
byte x,
unsigned int y)
1955 return _rotl8(x,
static_cast<byte>(y));
1958template<>
inline byte rotrMod<byte>(
byte x,
unsigned int y)
1960 return _rotr8(x,
static_cast<byte>(y));
1965#if (defined(__MWERKS__) && TARGET_CPU_PPC)
1967template<>
inline word32 rotlFixed<word32>(
word32 x,
unsigned int y)
1970 return y ? __rlwinm(x,y,0,31) : x;
1973template<>
inline word32 rotrFixed<word32>(
word32 x,
unsigned int y)
1976 return y ? __rlwinm(x,32-y,0,31) : x;
1979template<>
inline word32 rotlVariable<word32>(
word32 x,
unsigned int y)
1982 return (__rlwnm(x,y,0,31));
1985template<>
inline word32 rotrVariable<word32>(
word32 x,
unsigned int y)
1988 return (__rlwnm(x,32-y,0,31));
1991template<>
inline word32 rotlMod<word32>(
word32 x,
unsigned int y)
1993 return (__rlwnm(x,y,0,31));
1996template<>
inline word32 rotrMod<word32>(
word32 x,
unsigned int y)
1998 return (__rlwnm(x,32-y,0,31));
2013 return GETBYTE(value, index);
2015 return GETBYTE(value,
sizeof(T)-index-1);
2033#if defined(CRYPTOPP_BYTESWAP_AVAILABLE)
2034 return bswap_16(value);
2035#elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL))
2036 return _byteswap_ushort(value);
2048#if defined(CRYPTOPP_BYTESWAP_AVAILABLE)
2049 return bswap_32(value);
2050#elif defined(CRYPTOPP_ARM_BYTEREV_AVAILABLE)
2052 __asm__ (
"rev %0, %1" :
"=r" (rvalue) :
"r" (value));
2054#elif defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE)
2055 __asm__ (
"bswap %0" :
"=r" (value) :
"0" (value));
2057#elif defined(__MWERKS__) && TARGET_CPU_PPC
2058 return (
word32)__lwbrx(&value,0);
2059#elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL))
2060 return _byteswap_ulong(value);
2061#elif CRYPTOPP_FAST_ROTATE(32) && !defined(__xlC__)
2066 value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
2077#if defined(CRYPTOPP_BYTESWAP_AVAILABLE)
2078 return bswap_64(value);
2079#elif defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(__x86_64__)
2080 __asm__ (
"bswap %0" :
"=r" (value) :
"0" (value));
2082#elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL))
2083 return _byteswap_uint64(value);
2084#elif CRYPTOPP_BOOL_SLOW_WORD64
2087 value = ((value &
W64LIT(0xFF00FF00FF00FF00)) >> 8) | ((value &
W64LIT(0x00FF00FF00FF00FF)) << 8);
2088 value = ((value &
W64LIT(0xFFFF0000FFFF0000)) >> 16) | ((value &
W64LIT(0x0000FFFF0000FFFF)) << 16);
2093#if defined(CRYPTOPP_WORD128_AVAILABLE)
2112 value =
byte((value & 0xAA) >> 1) |
byte((value & 0x55) << 1);
2113 value =
byte((value & 0xCC) >> 2) |
byte((value & 0x33) << 2);
2122#if defined(CRYPTOPP_ARM_BITREV_AVAILABLE)
2125 __asm__ (
"rbit %0, %1" :
"=r" (rvalue) :
"r" (value));
2126 return word16(rvalue >> 16);
2129 value =
word16((value & 0xAAAA) >> 1) |
word16((value & 0x5555) << 1);
2130 value =
word16((value & 0xCCCC) >> 2) |
word16((value & 0x3333) << 2);
2131 value =
word16((value & 0xF0F0) >> 4) |
word16((value & 0x0F0F) << 4);
2141#if defined(CRYPTOPP_ARM_BITREV_AVAILABLE)
2144 __asm__ (
"rbit %0, %1" :
"=r" (rvalue) :
"r" (value));
2148 value =
word32((value & 0xAAAAAAAA) >> 1) |
word32((value & 0x55555555) << 1);
2149 value =
word32((value & 0xCCCCCCCC) >> 2) |
word32((value & 0x33333333) << 2);
2150 value =
word32((value & 0xF0F0F0F0) >> 4) |
word32((value & 0x0F0F0F0F) << 4);
2160#if CRYPTOPP_BOOL_SLOW_WORD64
2183 else if (
sizeof(T) == 2)
2185 else if (
sizeof(T) == 4)
2187 else if (
sizeof(T) == 8)
2189#if defined(CRYPTOPP_WORD128_AVAILABLE)
2190 else if (
sizeof(T) == 16)
2256 size_t count = byteCount/
sizeof(T);
2257 for (
size_t i=0; i<count; i++)
2280 memcpy_s(out, byteCount, in, byteCount);
2293 const size_t U =
sizeof(T);
2295 memcpy_s(out, outlen*U, in, inlen);
2296 memset_z((
byte *)out+inlen, 0, outlen*U-inlen);
2309 CRYPTOPP_UNUSED(order); CRYPTOPP_UNUSED(unused);
2322 CRYPTOPP_UNUSED(unused);
2324 ? block[1] | (block[0] << 8)
2325 : block[0] | (block[1] << 8);
2337 CRYPTOPP_UNUSED(unused);
2352 CRYPTOPP_UNUSED(unused);
2356 (
word64(block[6]) << 8) |
2357 (
word64(block[5]) << 16) |
2358 (
word64(block[4]) << 24) |
2359 (
word64(block[3]) << 32) |
2360 (
word64(block[2]) << 40) |
2361 (
word64(block[1]) << 48) |
2362 (
word64(block[0]) << 56))
2365 (
word64(block[1]) << 8) |
2366 (
word64(block[2]) << 16) |
2367 (
word64(block[3]) << 24) |
2368 (
word64(block[4]) << 32) |
2369 (
word64(block[5]) << 40) |
2370 (
word64(block[6]) << 48) |
2371 (
word64(block[7]) << 56));
2374#if defined(CRYPTOPP_WORD128_AVAILABLE)
2385 CRYPTOPP_UNUSED(unused);
2433 CRYPTOPP_UNUSED(order);
2434 block[0] =
static_cast<byte>(xorBlock ? (value ^ xorBlock[0]) : value);
2450 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2451 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2455 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2456 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2463 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2464 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2468 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2469 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2487 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2488 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2489 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2490 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2494 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2495 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2496 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2497 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2504 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2505 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2506 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2507 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2511 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2512 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2513 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2514 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2532 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2533 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2534 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2535 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2536 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2537 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2538 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2539 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2543 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2544 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2545 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2546 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2547 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2548 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2549 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2550 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2557 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2558 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2559 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2560 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2561 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2562 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2563 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2564 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2568 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2569 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2570 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2571 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2572 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2573 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2574 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2575 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2580#if defined(CRYPTOPP_WORD128_AVAILABLE)
2595 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 15);
2596 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 14);
2597 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 13);
2598 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 12);
2599 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 11);
2600 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 10);
2601 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 9);
2602 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 8);
2604 block[ 8] = xorBlock[ 8] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2605 block[ 9] = xorBlock[ 9] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2606 block[10] = xorBlock[10] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2607 block[11] = xorBlock[11] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2608 block[12] = xorBlock[12] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2609 block[13] = xorBlock[13] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2610 block[14] = xorBlock[14] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2611 block[15] = xorBlock[15] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2615 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 15);
2616 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 14);
2617 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 13);
2618 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 12);
2619 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 11);
2620 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 10);
2621 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 9);
2622 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 8);
2624 block[ 8] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2625 block[ 9] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2626 block[10] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2627 block[11] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2628 block[12] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2629 block[13] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2630 block[14] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2631 block[15] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2638 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2639 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2640 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2641 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2642 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2643 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2644 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2645 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2647 block[ 8] = xorBlock[ 8] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 8);
2648 block[ 9] = xorBlock[ 9] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 9);
2649 block[10] = xorBlock[10] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 10);
2650 block[11] = xorBlock[11] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 11);
2651 block[12] = xorBlock[12] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 12);
2652 block[13] = xorBlock[13] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 13);
2653 block[14] = xorBlock[14] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 14);
2654 block[15] = xorBlock[15] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 15);
2658 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2659 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2660 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2661 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2662 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2663 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2664 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2665 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2667 block[ 8] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 8);
2668 block[ 9] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 9);
2669 block[10] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 10);
2670 block[11] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 11);
2671 block[12] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 12);
2672 block[13] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 13);
2673 block[14] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 14);
2674 block[15] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 15);
2699 CRYPTOPP_UNUSED(assumeAligned);
2702 if (block != NULLPTR) {std::memcpy(&temp, block,
sizeof(T));}
2725 result = GetWord<T>(assumeAligned, order, block);
2739inline void PutWord(
bool assumeAligned,
ByteOrder order,
byte *block, T value,
const byte *xorBlock = NULLPTR)
2741 CRYPTOPP_UNUSED(assumeAligned);
2745 if (xorBlock != NULLPTR) {std::memcpy(&t2, xorBlock,
sizeof(T)); t1 ^= t2;}
2746 if (block != NULLPTR) {std::memcpy(block, &t1,
sizeof(T));}
2764template <
class T,
class B,
bool A=false>
2771 : m_block((const
byte *)block) {}
2781 x = GetWord<T>(A, B::ToEnum(), m_block);
2782 m_block +=
sizeof(T);
2787 const byte *m_block;
2805template <
class T,
class B,
bool A=false>
2813 : m_xorBlock((const
byte *)xorBlock), m_block((
byte *)block) {}
2822 PutWord(A, B::ToEnum(), m_block, (T)x, m_xorBlock);
2823 m_block +=
sizeof(T);
2825 m_xorBlock +=
sizeof(T);
2830 const byte *m_xorBlock;
2842template <
class T,
class B,
bool GA=false,
bool PA=false>
2861 return std::string((
char *)&value,
sizeof(value));
2900 CRYPTOPP_UNUSED(value); CRYPTOPP_UNUSED(bits);
2912 CRYPTOPP_UNUSED(value); CRYPTOPP_UNUSED(bits);
2930 return value >> bits;
2941 return value << bits;
2953template <
unsigned int bits,
class T>
2956 return SafeShifter<(bits>=(8*
sizeof(T)))>::RightShift(value, bits);
2967template <
unsigned int bits,
class T>
2970 return SafeShifter<(bits>=(8*
sizeof(T)))>::LeftShift(value, bits);
2980template<
typename InputIt,
typename T>
2981inline InputIt
FindIfNot(InputIt first, InputIt last,
const T &value) {
2982#ifdef CRYPTOPP_CXX11_LAMBDA
2983 return std::find_if(first, last, [&value](
const T &o) {
2987 return std::find_if(first, last, std::bind2nd(std::not_equal_to<T>(), value));
2993#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);}
2994#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);}
2995#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);}
2996#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);}
2997#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);}
2998#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);}
2999#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);}
3000#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);}
3001#define CRYPTOPP_BLOCKS_END(i) size_t SST() {return SS##i();} void AllocateBlocks() {m_aggregate.New(SST());} AlignedSecByteBlock m_aggregate;
3005#if (CRYPTOPP_MSC_VERSION)
3006# pragma warning(pop)
3009#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
3010# 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.
unsigned char byte
8-bit unsigned datatype
#define W64LIT(x)
Declare an unsigned word64.
const lword LWORD_MAX
Large word type max value.
__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)
Tests whether a conversion from -> to is safe to perform.
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.
void swap(::SecBlock< T, A > &a, ::SecBlock< T, A > &b)
Swap two SecBlocks.
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.