6 #ifndef CRYPTOPP_MISC_H 7 #define CRYPTOPP_MISC_H 11 #if !defined(CRYPTOPP_DOXYGEN_PROCESSING) 13 #if (CRYPTOPP_MSC_VERSION) 14 # pragma warning(push) 15 # pragma warning(disable: 4146 4514) 16 # if (CRYPTOPP_MSC_VERSION >= 1400) 17 # pragma warning(disable: 6326) 22 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 23 # pragma GCC diagnostic push 24 # pragma GCC diagnostic ignored "-Wconversion" 25 # pragma GCC diagnostic ignored "-Wsign-conversion" 35 #define _interlockedbittestandset CRYPTOPP_DISABLED_INTRINSIC_1 36 #define _interlockedbittestandreset CRYPTOPP_DISABLED_INTRINSIC_2 37 #define _interlockedbittestandset64 CRYPTOPP_DISABLED_INTRINSIC_3 38 #define _interlockedbittestandreset64 CRYPTOPP_DISABLED_INTRINSIC_4 40 #undef _interlockedbittestandset 41 #undef _interlockedbittestandreset 42 #undef _interlockedbittestandset64 43 #undef _interlockedbittestandreset64 44 #define CRYPTOPP_FAST_ROTATE(x) 1 45 #elif _MSC_VER >= 1300 46 #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32 | (x) == 64) 48 #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32) 50 #elif (defined(__MWERKS__) && TARGET_CPU_PPC) || \ 51 (defined(__GNUC__) && (defined(_ARCH_PWR2) || defined(_ARCH_PWR) || defined(_ARCH_PPC) || defined(_ARCH_PPC64) || defined(_ARCH_COM))) 52 #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32) 53 #elif defined(__GNUC__) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86) // depend on GCC's peephole optimization to generate rotate instructions 54 #define CRYPTOPP_FAST_ROTATE(x) 1 56 #define CRYPTOPP_FAST_ROTATE(x) 0 64 #if defined(__GNUC__) && defined(__linux__) 65 #define CRYPTOPP_BYTESWAP_AVAILABLE 70 # include <x86intrin.h> 73 #endif // CRYPTOPP_DOXYGEN_PROCESSING 75 #if CRYPTOPP_DOXYGEN_PROCESSING 91 # if defined(__SIZE_MAX__) && (__SIZE_MAX__ > 0) 92 # define SIZE_MAX __SIZE_MAX__ 93 # elif defined(SIZE_T_MAX) && (SIZE_T_MAX > 0) 94 # define SIZE_MAX SIZE_T_MAX 95 # elif defined(__SIZE_TYPE__) 96 # define SIZE_MAX (~(__SIZE_TYPE__)0) 98 # define SIZE_MAX ((std::numeric_limits<size_t>::max)()) 102 #endif // CRYPTOPP_DOXYGEN_PROCESSING 106 ANONYMOUS_NAMESPACE_BEGIN
111 return (std::numeric_limits<T>::min)();
117 return (std::numeric_limits<T>::max)();
119 #if defined(CRYPTOPP_WORD128_AVAILABLE) 121 CryptoPP::word128 NumericLimitsMin()
126 CryptoPP::word128 NumericLimitsMax()
128 return (((CryptoPP::word128)W64LIT(0xffffffffffffffff)) << 64U) | (CryptoPP::word128)W64LIT(0xffffffffffffffff);
131 ANONYMOUS_NAMESPACE_END
140 #if CRYPTOPP_DOXYGEN_PROCESSING 144 #define CRYPTOPP_COMPILE_ASSERT(expr) { ... } 145 #else // CRYPTOPP_DOXYGEN_PROCESSING 149 static char dummy[2*b-1];
152 #define CRYPTOPP_COMPILE_ASSERT(assertion) CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, __LINE__) 153 #if defined(CRYPTOPP_EXPORTS) || defined(CRYPTOPP_IMPORTS) 154 #define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance) 156 # if defined(__GNUC__) 157 # define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance) \ 158 static CompileAssert<(assertion)> \ 159 CRYPTOPP_ASSERT_JOIN(cryptopp_CRYPTOPP_ASSERT_, instance) __attribute__ ((unused)) 161 # define CRYPTOPP_COMPILE_ASSERT_INSTANCE(assertion, instance) \ 162 static CompileAssert<(assertion)> \ 163 CRYPTOPP_ASSERT_JOIN(cryptopp_CRYPTOPP_ASSERT_, instance) 166 #define CRYPTOPP_ASSERT_JOIN(X, Y) CRYPTOPP_DO_ASSERT_JOIN(X, Y) 167 #define CRYPTOPP_DO_ASSERT_JOIN(X, Y) X##Y 169 #endif // CRYPTOPP_DOXYGEN_PROCESSING 173 #if CRYPTOPP_DOXYGEN_PROCESSING 181 # define COUNTOF(arr) 185 # if defined(_MSC_VER) && (_MSC_VER >= 1400) 186 # define COUNTOF(x) _countof(x) 188 # define COUNTOF(x) (sizeof(x)/sizeof(x[0])) 191 #endif // CRYPTOPP_DOXYGEN_PROCESSING 201 #if !defined(CRYPTOPP_DOXYGEN_PROCESSING) 202 template <
class BASE1,
class BASE2>
203 class CRYPTOPP_NO_VTABLE TwoBases :
public BASE1,
public BASE2
207 template <
class BASE1,
class BASE2,
class BASE3>
208 class CRYPTOPP_NO_VTABLE ThreeBases :
public BASE1,
public BASE2,
public BASE3
211 #endif // CRYPTOPP_DOXYGEN_PROCESSING 243 T* operator()()
const {
return new T;}
246 #if CRYPTOPP_DOXYGEN_PROCESSING 255 #define MEMORY_BARRIER ... 257 #if defined(CRYPTOPP_CXX11_ATOMICS) 258 # define MEMORY_BARRIER() std::atomic_thread_fence(std::memory_order_acq_rel) 259 #elif (_MSC_VER >= 1400) 260 # pragma intrinsic(_ReadWriteBarrier) 261 # define MEMORY_BARRIER() _ReadWriteBarrier() 262 #elif defined(__INTEL_COMPILER) 263 # define MEMORY_BARRIER() __memory_barrier() 264 #elif defined(__GNUC__) || defined(__clang__) 265 # define MEMORY_BARRIER() __asm__ __volatile__ ("" ::: "memory") 267 # define MEMORY_BARRIER() 269 #endif // CRYPTOPP_DOXYGEN_PROCESSING 290 template <
class T,
class F = NewObject<T>,
int instance=0>
294 Singleton(F objectFactory = F()) : m_objectFactory(objectFactory) {}
297 CRYPTOPP_NOINLINE
const T &
Ref(CRYPTOPP_NOINLINE_DOTDOTDOT)
const;
311 template <
class T,
class F,
int instance>
314 #if defined(CRYPTOPP_CXX11_ATOMICS) && defined(CRYPTOPP_CXX11_SYNCHRONIZATION) && defined(CRYPTOPP_CXX11_DYNAMIC_INIT) 315 static std::mutex s_mutex;
316 static std::atomic<T*> s_pObject;
318 T *p = s_pObject.load(std::memory_order_relaxed);
319 std::atomic_thread_fence(std::memory_order_acquire);
324 std::lock_guard<std::mutex> lock(s_mutex);
325 p = s_pObject.load(std::memory_order_relaxed);
326 std::atomic_thread_fence(std::memory_order_acquire);
331 T *newObject = m_objectFactory();
332 s_pObject.store(newObject, std::memory_order_relaxed);
333 std::atomic_thread_fence(std::memory_order_release);
338 T *p = s_pObject.m_p;
344 T *newObject = m_objectFactory();
354 s_pObject.m_p = newObject;
363 #if (!__STDC_WANT_SECURE_LIB__ && !defined(_MEMORY_S_DEFINED)) || defined(CRYPTOPP_WANT_SECURE_LIB) 383 inline void memcpy_s(
void *dest,
size_t sizeInBytes,
const void *src,
size_t count)
394 if (count > sizeInBytes)
397 #if CRYPTOPP_MSC_VERSION 398 # pragma warning(push) 399 # pragma warning(disable: 4996) 400 # if (CRYPTOPP_MSC_VERSION >= 1400) 401 # pragma warning(disable: 6386) 404 memcpy(dest, src, count);
405 #if CRYPTOPP_MSC_VERSION 406 # pragma warning(pop) 428 inline void memmove_s(
void *dest,
size_t sizeInBytes,
const void *src,
size_t count)
437 if (count > sizeInBytes)
440 #if CRYPTOPP_MSC_VERSION 441 # pragma warning(push) 442 # pragma warning(disable: 4996) 443 # if (CRYPTOPP_MSC_VERSION >= 1400) 444 # pragma warning(disable: 6386) 447 memmove(dest, src, count);
448 #if CRYPTOPP_MSC_VERSION 449 # pragma warning(pop) 453 #if __BORLANDC__ >= 0x620 455 # define memcpy_s CryptoPP::memcpy_s 456 # define memmove_s CryptoPP::memmove_s 459 #endif // __STDC_WANT_SECURE_LIB__ 476 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5120) 490 inline void *
memset_z(
void *ptr,
int value,
size_t num)
493 #if CRYPTOPP_GCC_VERSION >= 30001 494 if (__builtin_constant_p(num) && num==0)
497 volatile void* x = memset(ptr, value, num);
498 return const_cast<void*>(x);
507 template <
class T>
inline const T&
STDMIN(
const T& a,
const T& b)
509 return b < a ? b : a;
518 template <
class T>
inline const T&
STDMAX(
const T& a,
const T& b)
520 return a < b ? b : a;
523 #if CRYPTOPP_MSC_VERSION 524 # pragma warning(push) 525 # pragma warning(disable: 4389) 528 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 529 # pragma GCC diagnostic push 530 # pragma GCC diagnostic ignored "-Wsign-compare" 531 # pragma GCC diagnostic ignored "-Wstrict-overflow" 532 # if (CRYPTOPP_LLVM_CLANG_VERSION >= 20800) || (CRYPTOPP_APPLE_CLANG_VERSION >= 30000) 533 # pragma GCC diagnostic ignored "-Wtautological-compare" 534 # elif (CRYPTOPP_GCC_VERSION >= 40300) 535 # pragma GCC diagnostic ignored "-Wtype-limits" 546 template <
class T1,
class T2>
inline const T1
UnsignedMin(
const T1& a,
const T2& b)
549 if (
sizeof(T1)<=
sizeof(T2))
550 return b < (T2)a ? (T1)b : a;
552 return (T1)b < a ? (T1)b : a;
561 template <
class T1,
class T2>
565 if (from != to || (from > 0) != (to > 0))
579 static const unsigned int HIGH_BIT = (1U << 31);
580 const char CH = !!(base & HIGH_BIT) ?
'A' :
'a';
596 T digit = value % base;
597 result = char((digit < 10 ?
'0' : (CH - 10)) + digit) + result;
601 result =
"-" + result;
611 template <> CRYPTOPP_DLL
633 template <> CRYPTOPP_DLL
636 #if CRYPTOPP_MSC_VERSION 637 # pragma warning(pop) 640 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 641 # pragma GCC diagnostic pop 644 #define RETURN_IF_NONZERO(x) size_t returnedValue = x; if (returnedValue) return returnedValue 647 #define GETBYTE(x, y) (unsigned int)byte((x)>>(8*(y))) 652 #define CRYPTOPP_GET_BYTE_AS_BYTE(x, y) byte((x)>>(8*(y))) 661 for (
unsigned int i=8*
sizeof(value)/2; i>0; i/=2)
663 return (
unsigned int)value&1;
676 unsigned int l=0, h=8*
sizeof(value);
679 unsigned int t = (l+h)/2;
699 unsigned int l=0, h=8*
sizeof(value);
703 unsigned int t = (l+h)/2;
726 return (
unsigned int)_tzcnt_u32(v);
727 #elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400) 728 return (
unsigned int)__builtin_ctz(v);
729 #elif defined(_MSC_VER) && (_MSC_VER >= 1400) 730 unsigned long result;
731 _BitScanForward(&result, v);
732 return (
unsigned int)result;
735 static const int MultiplyDeBruijnBitPosition[32] =
737 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
738 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
740 return MultiplyDeBruijnBitPosition[((word32)((v & -v) * 0x077CB531U)) >> 27];
756 #if defined(__BMI__) && defined(__x86_64__) 757 return (
unsigned int)_tzcnt_u64(v);
758 #elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400) 759 return (
unsigned int)__builtin_ctzll(v);
760 #elif defined(_MSC_VER) && (_MSC_VER >= 1400) && (defined(_M_X64) || defined(_M_IA64)) 761 unsigned long result;
762 _BitScanForward64(&result, v);
763 return (
unsigned int)result;
778 inline T
Crop(T value,
size_t bits)
780 if (bits < 8*
sizeof(value))
781 return T(value & ((T(1) << bits) - 1));
792 return ((bitCount+7)/(8));
802 return ((byteCount+WORD_SIZE-1)/WORD_SIZE);
812 return ((bitCount+WORD_BITS-1)/(WORD_BITS));
822 return ((bitCount+2*WORD_BITS-1)/(2*WORD_BITS));
831 CRYPTOPP_DLL
void CRYPTOPP_API
xorbuf(
byte *buf,
const byte *mask,
size_t count);
840 CRYPTOPP_DLL
void CRYPTOPP_API
xorbuf(
byte *output,
const byte *input,
const byte *mask,
size_t count);
851 CRYPTOPP_DLL
bool CRYPTOPP_API
VerifyBufsEqual(
const byte *buf1,
const byte *buf2,
size_t count);
861 return value > 0 && (value & (value-1)) == 0;
866 inline bool IsPowerOf2<word32>(
const word32 &value)
868 return value > 0 && _blsr_u32(value) == 0;
871 # if defined(__x86_64__) 873 inline bool IsPowerOf2<word64>(
const word64 &value)
875 return value > 0 && _blsr_u64(value) == 0;
877 # endif // __x86_64__ 889 template <
class T1,
class T2>
893 return T1((a > b) ? (a - b) : 0);
906 template <
class T1,
class T2>
910 return T1((a > b) ? (a - b) : 1);
921 template <
class T1,
class T2>
940 template <
class T1,
class T2>
944 #if !defined(CRYPTOPP_APPLE_CLANG_VERSION) || (CRYPTOPP_APPLE_CLANG_VERSION >= 80000) 970 template <
class T1,
class T2>
974 #if !defined(CRYPTOPP_APPLE_CLANG_VERSION) || (CRYPTOPP_APPLE_CLANG_VERSION >= 80000) 982 if (NumericLimitsMax<T1>() - m + 1 < n)
1001 #if defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS) 1006 #if defined(CRYPTOPP_CXX11_ALIGNOF) 1008 #elif (_MSC_VER >= 1300) 1009 return __alignof(T);
1010 #elif defined(__GNUC__) 1011 return __alignof__(T);
1012 #elif CRYPTOPP_BOOL_SLOW_WORD64 1015 # if __BIGGEST_ALIGNMENT__ 1016 if (__BIGGEST_ALIGNMENT__ <
sizeof(T))
1017 return __BIGGEST_ALIGNMENT__;
1032 return alignment==1 || (
IsPowerOf2(alignment) ?
ModPowerOf2((
size_t)ptr, alignment) == 0 : (size_t)ptr % alignment == 0);
1046 #if defined(CRYPTOPP_LITTLE_ENDIAN) 1048 #elif defined(CRYPTOPP_BIG_ENDIAN) 1051 # error "Unable to determine endian-ness" 1065 return NativeByteOrder::ToEnum();
1111 for (
int i=
int(size-1), carry=1; i>=0 && carry; i--)
1112 carry = !++inout[i];
1127 for (i=
int(size-1), carry=1; i>=0 && carry; i--)
1128 carry = ((output[i] = input[i]+1) == 0);
1129 memcpy_s(output, size, input,
size_t(i)+1);
1153 ptrdiff_t t = size_t(c) * (a - b);
1170 volatile T *p = buf+n;
1175 #if (_MSC_VER >= 1400 || defined(__GNUC__)) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86) 1183 volatile byte *p = buf;
1185 asm volatile(
"rep stosb" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1187 __stosb((
byte *)(
size_t)p, 0, n);
1197 volatile word16 *p = buf;
1199 asm volatile(
"rep stosw" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1201 __stosw((word16 *)(
size_t)p, 0, n);
1211 volatile word32 *p = buf;
1213 asm volatile(
"rep stosl" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1215 __stosd((
unsigned long *)(
size_t)p, 0, n);
1225 #if CRYPTOPP_BOOL_X64 1226 volatile word64 *p = buf;
1228 asm volatile(
"rep stosq" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1230 __stosq((word64 *)(
size_t)p, 0, n);
1237 #endif // #if (_MSC_VER >= 1400 || defined(__GNUC__)) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86) 1239 #if (_MSC_VER >= 1700) && defined(_M_ARM) 1242 char *p = reinterpret_cast<char*>(buf+n);
1244 __iso_volatile_store8(--p, 0);
1249 short *p = reinterpret_cast<short*>(buf+n);
1251 __iso_volatile_store16(--p, 0);
1256 int *p = reinterpret_cast<int*>(buf+n);
1258 __iso_volatile_store32(--p, 0);
1263 __int64 *p = reinterpret_cast<__int64*>(buf+n);
1265 __iso_volatile_store64(--p, 0);
1277 if (
sizeof(T) % 8 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word64>() == 0)
1279 else if (
sizeof(T) % 4 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word32>() == 0)
1281 else if (
sizeof(T) % 2 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word16>() == 0)
1299 std::string
StringNarrow(
const wchar_t *str,
bool throwOnError =
true);
1313 std::wstring
StringWiden(
const char *str,
bool throwOnError =
true);
1315 #ifdef CRYPTOPP_DOXYGEN_PROCESSING 1333 #endif // CRYPTOPP_DOXYGEN_PROCESSING 1335 #if CRYPTOPP_BOOL_ALIGN16 1338 #endif // CRYPTOPP_BOOL_ALIGN16 1371 static const unsigned int THIS_SIZE =
sizeof(T)*8;
1372 static const unsigned int MASK = THIS_SIZE-1;
1374 return T((x<<R)|(x>>(-R&MASK)));
1397 static const unsigned int THIS_SIZE =
sizeof(T)*8;
1398 static const unsigned int MASK = THIS_SIZE-1;
1400 return T((x >> R)|(x<<(-R&MASK)));
1422 static const unsigned int THIS_SIZE =
sizeof(T)*8;
1423 static const unsigned int MASK = THIS_SIZE-1;
1425 return T((x<<y)|(x>>(-y&MASK)));
1447 static const unsigned int THIS_SIZE =
sizeof(T)*8;
1448 static const unsigned int MASK = THIS_SIZE-1;
1450 return T((x >> y)|(x<<(-y&MASK)));
1467 static const unsigned int THIS_SIZE =
sizeof(T)*8;
1468 static const unsigned int MASK = THIS_SIZE-1;
1470 return T((x<<y)|(x>>(-y&MASK)));
1487 static const unsigned int THIS_SIZE =
sizeof(T)*8;
1488 static const unsigned int MASK = THIS_SIZE-1;
1490 return T((x>>y)|(x<<(-y&MASK)));
1502 template <
class T>
inline T
rotlMod(T x,
unsigned int y)
1504 static const unsigned int THIS_SIZE =
sizeof(T)*8;
1505 static const unsigned int MASK = THIS_SIZE-1;
1506 return T((x<<(y&MASK))|(x>>(-y&MASK)));
1518 template <
class T>
inline T
rotrMod(T x,
unsigned int y)
1520 static const unsigned int THIS_SIZE =
sizeof(T)*8;
1521 static const unsigned int MASK = THIS_SIZE-1;
1522 return T((x>>(y&MASK))|(x<<(-y&MASK)));
1536 template<>
inline word32 rotlFixed<word32>(word32 x,
unsigned int y)
1540 return y ? _lrotl(x, static_cast<byte>(y)) : x;
1552 template<>
inline word32 rotrFixed<word32>(word32 x,
unsigned int y)
1556 return y ? _lrotr(x, static_cast<byte>(y)) : x;
1568 template<>
inline word32 rotlVariable<word32>(word32 x,
unsigned int y)
1571 return _lrotl(x, static_cast<byte>(y));
1583 template<>
inline word32 rotrVariable<word32>(word32 x,
unsigned int y)
1586 return _lrotr(x, static_cast<byte>(y));
1597 template<>
inline word32 rotlMod<word32>(word32 x,
unsigned int y)
1600 return _lrotl(x, static_cast<byte>(y));
1611 template<>
inline word32 rotrMod<word32>(word32 x,
unsigned int y)
1614 return _lrotr(x, static_cast<byte>(y));
1617 #endif // #ifdef _MSC_VER 1619 #if (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL)) 1631 template<>
inline word64 rotlFixed<word64>(word64 x,
unsigned int y)
1635 return y ? _rotl64(x, static_cast<byte>(y)) : x;
1647 template<>
inline word64 rotrFixed<word64>(word64 x,
unsigned int y)
1651 return y ? _rotr64(x, static_cast<byte>(y)) : x;
1663 template<>
inline word64 rotlVariable<word64>(word64 x,
unsigned int y)
1666 return _rotl64(x, static_cast<byte>(y));
1678 template<>
inline word64 rotrVariable<word64>(word64 x,
unsigned int y)
1681 return y ? _rotr64(x, static_cast<byte>(y)) : x;
1692 template<>
inline word64 rotlMod<word64>(word64 x,
unsigned int y)
1695 return y ? _rotl64(x, static_cast<byte>(y)) : x;
1706 template<>
inline word64 rotrMod<word64>(word64 x,
unsigned int y)
1709 return y ? _rotr64(x, static_cast<byte>(y)) : x;
1712 #endif // #if _MSC_VER >= 1310 1714 #if _MSC_VER >= 1400 && !defined(__INTEL_COMPILER) 1716 template<>
inline word16 rotlFixed<word16>(word16 x,
unsigned int y)
1719 return _rotl16(x, static_cast<byte>(y));
1722 template<>
inline word16 rotrFixed<word16>(word16 x,
unsigned int y)
1725 return _rotr16(x, static_cast<byte>(y));
1728 template<>
inline word16 rotlVariable<word16>(word16 x,
unsigned int y)
1730 return _rotl16(x, static_cast<byte>(y));
1733 template<>
inline word16 rotrVariable<word16>(word16 x,
unsigned int y)
1735 return _rotr16(x, static_cast<byte>(y));
1738 template<>
inline word16 rotlMod<word16>(word16 x,
unsigned int y)
1740 return _rotl16(x, static_cast<byte>(y));
1743 template<>
inline word16 rotrMod<word16>(word16 x,
unsigned int y)
1745 return _rotr16(x, static_cast<byte>(y));
1748 template<>
inline byte rotlFixed<byte>(
byte x,
unsigned int y)
1751 return _rotl8(x, static_cast<byte>(y));
1754 template<>
inline byte rotrFixed<byte>(
byte x,
unsigned int y)
1757 return _rotr8(x, static_cast<byte>(y));
1760 template<>
inline byte rotlVariable<byte>(
byte x,
unsigned int y)
1762 return _rotl8(x, static_cast<byte>(y));
1765 template<>
inline byte rotrVariable<byte>(
byte x,
unsigned int y)
1767 return _rotr8(x, static_cast<byte>(y));
1770 template<>
inline byte rotlMod<byte>(
byte x,
unsigned int y)
1772 return _rotl8(x, static_cast<byte>(y));
1775 template<>
inline byte rotrMod<byte>(
byte x,
unsigned int y)
1777 return _rotr8(x, static_cast<byte>(y));
1780 #endif // #if _MSC_VER >= 1400 1782 #if (defined(__MWERKS__) && TARGET_CPU_PPC) 1784 template<>
inline word32 rotlFixed<word32>(word32 x,
unsigned int y)
1787 return y ? __rlwinm(x,y,0,31) : x;
1790 template<>
inline word32 rotrFixed<word32>(word32 x,
unsigned int y)
1793 return y ? __rlwinm(x,32-y,0,31) : x;
1796 template<>
inline word32 rotlVariable<word32>(word32 x,
unsigned int y)
1799 return (__rlwnm(x,y,0,31));
1802 template<>
inline word32 rotrVariable<word32>(word32 x,
unsigned int y)
1805 return (__rlwnm(x,32-y,0,31));
1808 template<>
inline word32 rotlMod<word32>(word32 x,
unsigned int y)
1810 return (__rlwnm(x,y,0,31));
1813 template<>
inline word32 rotrMod<word32>(word32 x,
unsigned int y)
1815 return (__rlwnm(x,32-y,0,31));
1818 #endif // #if (defined(__MWERKS__) && TARGET_CPU_PPC) 1830 return GETBYTE(value, index);
1832 return GETBYTE(value,
sizeof(T)-index-1);
1848 #if defined(CRYPTOPP_BYTESWAP_AVAILABLE) 1849 return bswap_16(value);
1850 #elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL)) 1851 return _byteswap_ushort(value);
1862 #if defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) 1863 __asm__ (
"bswap %0" :
"=r" (value) :
"0" (value));
1865 #elif defined(CRYPTOPP_BYTESWAP_AVAILABLE) 1866 return bswap_32(value);
1867 #elif defined(__MWERKS__) && TARGET_CPU_PPC 1868 return (word32)__lwbrx(&value,0);
1869 #elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL)) 1870 return _byteswap_ulong(value);
1871 #elif CRYPTOPP_FAST_ROTATE(32) && !defined(__xlC__) 1876 value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
1886 #if defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(__x86_64__) 1887 __asm__ (
"bswap %0" :
"=r" (value) :
"0" (value));
1889 #elif defined(CRYPTOPP_BYTESWAP_AVAILABLE) 1890 return bswap_64(value);
1891 #elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL)) 1892 return _byteswap_uint64(value);
1893 #elif CRYPTOPP_BOOL_SLOW_WORD64 1896 value = ((value & W64LIT(0xFF00FF00FF00FF00)) >> 8) | ((value & W64LIT(0x00FF00FF00FF00FF)) << 8);
1897 value = ((value & W64LIT(0xFFFF0000FFFF0000)) >> 16) | ((value & W64LIT(0x0000FFFF0000FFFF)) << 16);
1907 value = byte((value & 0xAA) >> 1) | byte((value & 0x55) << 1);
1908 value = byte((value & 0xCC) >> 2) | byte((value & 0x33) << 2);
1917 value = word16((value & 0xAAAA) >> 1) | word16((value & 0x5555) << 1);
1918 value = word16((value & 0xCCCC) >> 2) | word16((value & 0x3333) << 2);
1919 value = word16((value & 0xF0F0) >> 4) | word16((value & 0x0F0F) << 4);
1928 value = word32((value & 0xAAAAAAAA) >> 1) | word32((value & 0x55555555) << 1);
1929 value = word32((value & 0xCCCCCCCC) >> 2) | word32((value & 0x33333333) << 2);
1930 value = word32((value & 0xF0F0F0F0) >> 4) | word32((value & 0x0F0F0F0F) << 4);
1939 #if CRYPTOPP_BOOL_SLOW_WORD64 1942 value = word64((value & W64LIT(0xAAAAAAAAAAAAAAAA)) >> 1) | word64((value & W64LIT(0x5555555555555555)) << 1);
1943 value = word64((value & W64LIT(0xCCCCCCCCCCCCCCCC)) >> 2) | word64((value & W64LIT(0x3333333333333333)) << 2);
1944 value = word64((value & W64LIT(0xF0F0F0F0F0F0F0F0)) >> 4) | word64((value & W64LIT(0x0F0F0F0F0F0F0F0F)) << 4);
1960 else if (
sizeof(T) == 2)
1962 else if (
sizeof(T) == 4)
2023 size_t count = byteCount/
sizeof(T);
2024 for (
size_t i=0; i<count; i++)
2047 memcpy_s(out, byteCount, in, byteCount);
2051 inline void GetUserKey(
ByteOrder order, T *out,
size_t outlen,
const byte *in,
size_t inlen)
2053 const size_t U =
sizeof(T);
2055 memcpy_s(out, outlen*U, in, inlen);
2056 memset_z((
byte *)out+inlen, 0, outlen*U-inlen);
2060 #ifndef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS 2061 inline byte UnalignedGetWordNonTemplate(
ByteOrder order,
const byte *block,
const byte *)
2063 CRYPTOPP_UNUSED(order);
2067 inline word16 UnalignedGetWordNonTemplate(
ByteOrder order,
const byte *block,
const word16 *)
2070 ? block[1] | (block[0] << 8)
2071 : block[0] | (block[1] << 8);
2074 inline word32 UnalignedGetWordNonTemplate(
ByteOrder order,
const byte *block,
const word32 *)
2077 ? word32(block[3]) | (word32(block[2]) << 8) | (word32(block[1]) << 16) | (word32(block[0]) << 24)
2078 : word32(block[0]) | (word32(block[1]) << 8) | (word32(block[2]) << 16) | (word32(block[3]) << 24);
2081 inline word64 UnalignedGetWordNonTemplate(
ByteOrder order,
const byte *block,
const word64 *)
2086 (word64(block[6]) << 8) |
2087 (word64(block[5]) << 16) |
2088 (word64(block[4]) << 24) |
2089 (word64(block[3]) << 32) |
2090 (word64(block[2]) << 40) |
2091 (word64(block[1]) << 48) |
2092 (word64(block[0]) << 56))
2095 (word64(block[1]) << 8) |
2096 (word64(block[2]) << 16) |
2097 (word64(block[3]) << 24) |
2098 (word64(block[4]) << 32) |
2099 (word64(block[5]) << 40) |
2100 (word64(block[6]) << 48) |
2101 (word64(block[7]) << 56));
2104 inline void UnalignedbyteNonTemplate(
ByteOrder order,
byte *block,
byte value,
const byte *xorBlock)
2106 CRYPTOPP_UNUSED(order);
2107 block[0] = (byte)(xorBlock ? (value ^ xorBlock[0]) : value);
2110 inline void UnalignedbyteNonTemplate(
ByteOrder order,
byte *block, word16 value,
const byte *xorBlock)
2116 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2117 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2121 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2122 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2129 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2130 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2134 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2135 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2140 inline void UnalignedbyteNonTemplate(
ByteOrder order,
byte *block, word32 value,
const byte *xorBlock)
2146 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2147 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2148 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2149 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2153 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2154 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2155 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2156 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2163 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2164 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2165 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2166 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2170 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2171 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2172 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2173 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2178 inline void UnalignedbyteNonTemplate(
ByteOrder order,
byte *block, word64 value,
const byte *xorBlock)
2184 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2185 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2186 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2187 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2188 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2189 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2190 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2191 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2195 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2196 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2197 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2198 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2199 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2200 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2201 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2202 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2209 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2210 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2211 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2212 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2213 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2214 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2215 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2216 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2220 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2221 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2222 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2223 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2224 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2225 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2226 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2227 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2231 #endif // #ifndef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS 2252 CRYPTOPP_UNUSED(assumeAligned);
2253 #ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS 2257 memcpy(&temp, block,
sizeof(T));
2281 result = GetWord<T>(assumeAligned, order, block);
2295 inline void PutWord(
bool assumeAligned,
ByteOrder order,
byte *block, T value,
const byte *xorBlock = NULLPTR)
2297 CRYPTOPP_UNUSED(assumeAligned);
2298 #ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS 2299 *reinterpret_cast<T *>((
void *)block) =
ConditionalByteReverse(order, value) ^ (xorBlock ? *reinterpret_cast<const T *>((
const void *)xorBlock) : 0);
2303 if (xorBlock) {memcpy(&t2, xorBlock,
sizeof(T)); t1 ^= t2;}
2304 memcpy(block, &t1,
sizeof(T));
2323 template <
class T,
class B,
bool A=false>
2330 : m_block((const byte *)block) {}
2340 x = GetWord<T>(A, B::ToEnum(), m_block);
2341 m_block +=
sizeof(T);
2346 const byte *m_block;
2364 template <
class T,
class B,
bool A=false>
2372 : m_xorBlock((const byte *)xorBlock), m_block((byte *)block) {}
2381 PutWord(A, B::ToEnum(), m_block, (T)x, m_xorBlock);
2382 m_block +=
sizeof(T);
2384 m_xorBlock +=
sizeof(T);
2389 const byte *m_xorBlock;
2401 template <
class T,
class B,
bool GA=false,
bool PA=false>
2420 return std::string((
char *)&value,
sizeof(value));
2459 CRYPTOPP_UNUSED(value); CRYPTOPP_UNUSED(bits);
2471 CRYPTOPP_UNUSED(value); CRYPTOPP_UNUSED(bits);
2489 return value >> bits;
2500 return value << bits;
2512 template <
unsigned int bits,
class T>
2515 return SafeShifter<(bits>=(8*
sizeof(T)))>::RightShift(value, bits);
2526 template <
unsigned int bits,
class T>
2529 return SafeShifter<(bits>=(8*
sizeof(T)))>::LeftShift(value, bits);
2539 template<
typename InputIt,
typename T>
2540 inline InputIt
FindIfNot(InputIt first, InputIt last,
const T &value) {
2541 #ifdef CRYPTOPP_CXX11_LAMBDA 2542 return std::find_if(first, last, [&value](
const T &o) {
2546 return std::find_if(first, last, std::bind2nd(std::not_equal_to<T>(), value));
2552 #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);} 2553 #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);} 2554 #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);} 2555 #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);} 2556 #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);} 2557 #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);} 2558 #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);} 2559 #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);} 2560 #define CRYPTOPP_BLOCKS_END(i) size_t SST() {return SS##i();} void AllocateBlocks() {m_aggregate.New(SST());} AlignedSecByteBlock m_aggregate; 2564 #if (CRYPTOPP_MSC_VERSION) 2565 # pragma warning(pop) 2568 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 2569 # pragma GCC diagnostic pop void SecureWipeBuffer(T *buf, size_t n)
Sets each element of an array to 0.
InputIt FindIfNot(InputIt first, InputIt last, const T &value)
Finds first element not in a range.
the cipher is performing decryption
An invalid argument was detected.
std::string StringNarrow(const wchar_t *str, bool throwOnError=true)
Converts a wide character C-string to a multibyte string.
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.
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.
T SafeRightShift(T value)
Safely right shift values when undefined behavior could occur.
size_t BitsToBytes(size_t bitCount)
Returns the number of 8-bit bytes or octets required for the specified number of bits.
T StringToWord(const std::string &str, ByteOrder order=BIG_ENDIAN_ORDER)
Convert a string to a word.
bool IsAligned(const void *ptr)
Determines whether ptr is minimally aligned.
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.
void PutWord(bool assumeAligned, ByteOrder order, byte *block, T value, const byte *xorBlock=NULL)
Access a block of memory.
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 an enumeration to a type suitable for use as a template parameter.
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()
unsigned int GetAlignmentOf()
Returns the minimum alignment requirements of a type.
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.
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.
std::string WordToString(T value, ByteOrder order=BIG_ENDIAN_ORDER)
Convert a word 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
T GetWord(bool assumeAligned, ByteOrder order, const byte *block)
Access a block of memory.
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.
T rotlConstant(T x)
Performs a left rotate.
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 endianness.
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.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
std::wstring StringWiden(const char *str, bool throwOnError=true)
Converts a multibyte C-string to a wide character string.
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.
T SafeLeftShift(T value)
Safely left shift values when undefined behavior could occur.
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.
T rotrConstant(T x)
Performs a right rotate.
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.
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.
Crypto++ library namespace.
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.
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.
const T & Ref(...) const
Return a reference to the inner Singleton object.
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.
void vec_swap(T &a, T &b)
Swaps two variables which are arrays.