6 #ifndef CRYPTOPP_MISC_H
7 #define CRYPTOPP_MISC_H
17 #if !defined(CRYPTOPP_DOXYGEN_PROCESSING)
19 #if (CRYPTOPP_MSC_VERSION)
20 # pragma warning(push)
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 # if defined(CRYPTOPP_GCC_COMPATIBLE)
84 # include <x86intrin.h>
86 # include <immintrin.h>
91 #if defined(__clang__)
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
120 # define SIZE_MAX ...
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
193 # define COUNTOF(arr)
197 # if defined(_MSC_VER) && (_MSC_VER >= 1400)
198 # define COUNTOF(x) _countof(x)
200 # define COUNTOF(x) (sizeof(x)/sizeof(x[0]))
213 #if !defined(CRYPTOPP_DOXYGEN_PROCESSING)
214 template <
class BASE1,
class BASE2>
215 class CRYPTOPP_NO_VTABLE TwoBases :
public BASE1,
public BASE2
219 template <
class BASE1,
class BASE2,
class BASE3>
220 class 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 (_MSC_VER >= 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()
307 template <
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;
328 template <
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 s_pObject.store(newObject, std::memory_order_relaxed);
350 std::atomic_thread_fence(std::memory_order_release);
355 T *p = s_pObject.m_p;
361 T *newObject = m_objectFactory();
371 s_pObject.m_p = newObject;
387 template <
typename PTR,
typename OFF>
388 inline PTR
PtrAdd(PTR pointer, OFF offset)
390 return pointer+
static_cast<ptrdiff_t
>(offset);
400 template <
typename PTR,
typename OFF>
401 inline PTR
PtrSub(PTR pointer, OFF offset)
403 return pointer-
static_cast<ptrdiff_t
>(offset);
415 template <
typename PTR>
416 inline ptrdiff_t
PtrDiff(
const PTR pointer1,
const PTR pointer2)
418 return pointer1 - pointer2;
430 template <
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)
499 template <
typename T>
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)
527 inline 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
551 # pragma warning(pop)
573 inline 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
595 # pragma warning(pop)
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)
640 inline 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);
657 template <
class T>
inline const T&
STDMIN(
const T& a,
const T& b)
659 return b < a ? b : a;
668 template <
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"
695 template <
class T1,
class T2>
inline const T1
UnsignedMin(
const T1& a,
const T2& b)
698 if (
sizeof(T1)<=
sizeof(T2))
699 return b < (T2)a ? (T1)b : a;
701 return (T1)b < a ? (T1)b : a;
714 template <
class T1,
class T2>
717 to =
static_cast<T2
>(from);
718 if (from != to || (from > 0) != (to > 0))
742 to =
static_cast<word64>(from);
756 to =
static_cast<word64>(from);
772 to =
static_cast<word64>(from);
786 if (from >
static_cast<word64>(std::numeric_limits<sword64>::max()))
788 to =
static_cast<sword64>(from);
802 to =
static_cast<sword64>(from);
816 to =
static_cast<sword64>(from);
830 if (from >
static_cast<word64>(std::numeric_limits<word32>::max()))
832 to =
static_cast<word32>(from);
848 else if (from >
static_cast<sword64>(std::numeric_limits<word32>::max()))
850 to =
static_cast<word32>(from);
866 to =
static_cast<word32>(from);
880 if (from >
static_cast<word64>(std::numeric_limits<sword32>::max()))
882 to =
static_cast<sword32>(from);
896 if (from >
static_cast<sword64>(std::numeric_limits<sword32>::max()))
898 else if (from <
static_cast<sword64>(std::numeric_limits<sword32>::min()))
900 to =
static_cast<sword32>(from);
914 if (from >
static_cast<word32>(std::numeric_limits<sword32>::max()))
916 to =
static_cast<sword32>(from);
929 const unsigned int HIGH_BIT = (1U << 31);
930 const char CH = !!(base & HIGH_BIT) ?
'A' :
'a';
946 T digit = value % base;
947 result = char((digit < 10 ?
'0' : (CH - 10)) + digit) + result;
951 result =
"-" + result;
961 template <> CRYPTOPP_DLL
983 template <> CRYPTOPP_DLL
986 #if CRYPTOPP_MSC_VERSION
987 # pragma warning(pop)
990 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
991 # pragma GCC diagnostic pop
994 #define RETURN_IF_NONZERO(x) size_t returnedValue = x; if (returnedValue) return returnedValue
997 #define GETBYTE(x, y) (unsigned int)byte((x)>>(8*(y)))
1002 #define CRYPTOPP_GET_BYTE_AS_BYTE(x, y) byte((x)>>(8*(y)))
1011 for (
unsigned int i=8*
sizeof(value)/2; i>0; i/=2)
1012 value ^= value >> i;
1013 return (
unsigned int)value&1;
1026 unsigned int l=0, h=8*
sizeof(value);
1029 unsigned int t = (l+h)/2;
1049 unsigned int l=0, h=8*
sizeof(value);
1053 unsigned int t = (l+h)/2;
1075 #if defined(__BMI__)
1076 return (
unsigned int)_tzcnt_u32(v);
1077 #elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400)
1078 return (
unsigned int)__builtin_ctz(v);
1079 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
1080 unsigned long result;
1081 _BitScanForward(&result, v);
1082 return static_cast<unsigned int>(result);
1085 static const int MultiplyDeBruijnBitPosition[32] =
1087 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
1088 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
1090 return MultiplyDeBruijnBitPosition[((
word32)((v & -v) * 0x077CB531U)) >> 27];
1106 #if defined(__BMI__) && defined(__x86_64__)
1107 return (
unsigned int)_tzcnt_u64(v);
1108 #elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400)
1109 return (
unsigned int)__builtin_ctzll(v);
1110 #elif defined(_MSC_VER) && (_MSC_VER >= 1400) && (defined(_M_X64) || defined(_M_IA64))
1111 unsigned long result;
1112 _BitScanForward64(&result, v);
1113 return static_cast<unsigned int>(result);
1128 inline T
Crop(T value,
size_t bits)
1130 if (bits < 8*
sizeof(value))
1131 return T(value & ((T(1) << bits) - 1));
1142 return ((bitCount+7)/(8));
1214 return value > 0 && (value & (value-1)) == 0;
1217 #if defined(__BMI__)
1219 inline bool IsPowerOf2<word32>(
const word32 &value)
1221 return value > 0 && _blsr_u32(value) == 0;
1224 # if defined(__x86_64__)
1226 inline bool IsPowerOf2<word64>(
const word64 &value)
1228 return value > 0 && _blsr_u64(value) == 0;
1248 return (std::numeric_limits<T>::min)();
1266 return (std::numeric_limits<T>::max)();
1271 #if defined(CRYPTOPP_WORD128_AVAILABLE)
1294 template <
class T1,
class T2>
1298 return T1((a > b) ? (a - b) : 0);
1311 template <
class T1,
class T2>
1315 return T1((a > b) ? (a - b) : 1);
1326 template <
class T1,
class T2>
1346 template <
class T1,
class T2>
1350 #if !defined(CRYPTOPP_APPLE_CLANG_VERSION) || (CRYPTOPP_APPLE_CLANG_VERSION >= 80000)
1376 template <
class T1,
class T2>
1380 #if !defined(CRYPTOPP_APPLE_CLANG_VERSION) || (CRYPTOPP_APPLE_CLANG_VERSION >= 80000)
1388 if (NumericLimitsMax<T1>() - m + 1 < n)
1404 #if defined(CRYPTOPP_CXX11_ALIGNOF)
1406 #elif (_MSC_VER >= 1300)
1407 return __alignof(T);
1408 #elif defined(__GNUC__)
1409 return __alignof__(T);
1410 #elif defined(__SUNPRO_CC)
1411 return __alignof__(T);
1412 #elif defined(__IBM_ALIGNOF__)
1413 return __alignof__(T);
1414 #elif CRYPTOPP_BOOL_SLOW_WORD64
1431 const uintptr_t x =
reinterpret_cast<uintptr_t
>(ptr);
1432 return alignment==1 || (
IsPowerOf2(alignment) ?
ModPowerOf2(x, alignment) == 0 : x % alignment == 0);
1448 #if (CRYPTOPP_LITTLE_ENDIAN)
1450 #elif (CRYPTOPP_BIG_ENDIAN)
1453 # error "Unable to determine endianness"
1468 return NativeByteOrder::ToEnum();
1505 unsigned int carry=1;
1506 while (carry && size != 0)
1509 carry = ! ++inout[size-1];
1526 unsigned int carry=1;
1527 while (carry && size != 0)
1530 carry = ! (output[size-1] = input[size-1] + 1);
1536 output[size-1] = input[size-1];
1562 ptrdiff_t t = size_t(c) * (a - b);
1581 volatile T *p = buf+n;
1586 #if !defined(CRYPTOPP_DISABLE_ASM) && \
1587 (_MSC_VER >= 1400 || defined(__GNUC__)) && \
1588 (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86)
1597 volatile byte *p = buf;
1599 asm volatile(
"rep stosb" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1601 __stosb(
reinterpret_cast<byte *
>(
reinterpret_cast<size_t>(p)), 0, n);
1612 volatile word16 *p = buf;
1614 asm volatile(
"rep stosw" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1616 __stosw(
reinterpret_cast<word16 *
>(
reinterpret_cast<size_t>(p)), 0, n);
1627 volatile word32 *p = buf;
1629 asm volatile(
"rep stosl" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1631 __stosd(
reinterpret_cast<unsigned long *
>(
reinterpret_cast<size_t>(p)), 0, n);
1642 #if CRYPTOPP_BOOL_X64
1643 volatile word64 *p = buf;
1645 asm volatile(
"rep stosq" :
"+c"(n),
"+D"(p) :
"a"(0) :
"memory");
1647 __stosq(
const_cast<word64 *
>(p), 0, n);
1656 #if !defined(CRYPTOPP_DISABLE_ASM) && (_MSC_VER >= 1700) && defined(_M_ARM)
1659 char *p =
reinterpret_cast<char*
>(buf+n);
1661 __iso_volatile_store8(--p, 0);
1666 short *p =
reinterpret_cast<short*
>(buf+n);
1668 __iso_volatile_store16(--p, 0);
1673 int *p =
reinterpret_cast<int*
>(buf+n);
1675 __iso_volatile_store32(--p, 0);
1680 __int64 *p =
reinterpret_cast<__int64*
>(buf+n);
1682 __iso_volatile_store64(--p, 0);
1695 if (
sizeof(T) % 8 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word64>() == 0)
1697 else if (
sizeof(T) % 4 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word32>() == 0)
1699 else if (
sizeof(T) % 2 == 0 && GetAlignmentOf<T>() % GetAlignmentOf<word16>() == 0)
1702 SecureWipeBuffer(
reinterpret_cast<byte *
>(
static_cast<void *
>(buf)), n *
sizeof(T));
1756 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1757 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1759 return T((x<<R)|(x>>(-R&MASK)));
1782 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1783 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1785 return T((x >> R)|(x<<(-R&MASK)));
1807 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1808 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1810 return T((x<<y)|(x>>(-y&MASK)));
1832 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1833 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1835 return T((x >> y)|(x<<(-y&MASK)));
1852 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1853 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1855 return T((x<<y)|(x>>(-y&MASK)));
1872 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1873 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1875 return T((x>>y)|(x<<(-y&MASK)));
1887 template <
class T>
inline T
rotlMod(T x,
unsigned int y)
1889 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1890 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1891 return T((x<<(y&MASK))|(x>>(-y&MASK)));
1903 template <
class T>
inline T
rotrMod(T x,
unsigned int y)
1905 CRYPTOPP_CONSTANT(THIS_SIZE =
sizeof(T)*8);
1906 CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1);
1907 return T((x>>(y&MASK))|(x<<(-y&MASK)));
1921 template<>
inline word32 rotlFixed<word32>(
word32 x,
unsigned int y)
1925 return y ? _lrotl(x,
static_cast<byte>(y)) : x;
1937 template<>
inline word32 rotrFixed<word32>(
word32 x,
unsigned int y)
1941 return y ? _lrotr(x,
static_cast<byte>(y)) : x;
1953 template<>
inline word32 rotlVariable<word32>(
word32 x,
unsigned int y)
1956 return _lrotl(x,
static_cast<byte>(y));
1968 template<>
inline word32 rotrVariable<word32>(
word32 x,
unsigned int y)
1971 return _lrotr(x,
static_cast<byte>(y));
1982 template<>
inline word32 rotlMod<word32>(
word32 x,
unsigned int y)
1985 return _lrotl(x,
static_cast<byte>(y));
1996 template<>
inline word32 rotrMod<word32>(
word32 x,
unsigned int y)
1999 return _lrotr(x,
static_cast<byte>(y));
2004 #if (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL))
2016 template<>
inline word64 rotlFixed<word64>(
word64 x,
unsigned int y)
2020 return y ? _rotl64(x,
static_cast<byte>(y)) : x;
2032 template<>
inline word64 rotrFixed<word64>(
word64 x,
unsigned int y)
2036 return y ? _rotr64(x,
static_cast<byte>(y)) : x;
2048 template<>
inline word64 rotlVariable<word64>(
word64 x,
unsigned int y)
2051 return _rotl64(x,
static_cast<byte>(y));
2063 template<>
inline word64 rotrVariable<word64>(
word64 x,
unsigned int y)
2066 return y ? _rotr64(x,
static_cast<byte>(y)) : x;
2077 template<>
inline word64 rotlMod<word64>(
word64 x,
unsigned int y)
2080 return y ? _rotl64(x,
static_cast<byte>(y)) : x;
2091 template<>
inline word64 rotrMod<word64>(
word64 x,
unsigned int y)
2094 return y ? _rotr64(x,
static_cast<byte>(y)) : x;
2099 #if _MSC_VER >= 1400 && !defined(__INTEL_COMPILER)
2101 template<>
inline word16 rotlFixed<word16>(
word16 x,
unsigned int y)
2104 return _rotl16(x,
static_cast<byte>(y));
2107 template<>
inline word16 rotrFixed<word16>(
word16 x,
unsigned int y)
2110 return _rotr16(x,
static_cast<byte>(y));
2113 template<>
inline word16 rotlVariable<word16>(
word16 x,
unsigned int y)
2115 return _rotl16(x,
static_cast<byte>(y));
2118 template<>
inline word16 rotrVariable<word16>(
word16 x,
unsigned int y)
2120 return _rotr16(x,
static_cast<byte>(y));
2123 template<>
inline word16 rotlMod<word16>(
word16 x,
unsigned int y)
2125 return _rotl16(x,
static_cast<byte>(y));
2128 template<>
inline word16 rotrMod<word16>(
word16 x,
unsigned int y)
2130 return _rotr16(x,
static_cast<byte>(y));
2133 template<>
inline byte rotlFixed<byte>(
byte x,
unsigned int y)
2136 return _rotl8(x,
static_cast<byte>(y));
2139 template<>
inline byte rotrFixed<byte>(
byte x,
unsigned int y)
2142 return _rotr8(x,
static_cast<byte>(y));
2145 template<>
inline byte rotlVariable<byte>(
byte x,
unsigned int y)
2147 return _rotl8(x,
static_cast<byte>(y));
2150 template<>
inline byte rotrVariable<byte>(
byte x,
unsigned int y)
2152 return _rotr8(x,
static_cast<byte>(y));
2155 template<>
inline byte rotlMod<byte>(
byte x,
unsigned int y)
2157 return _rotl8(x,
static_cast<byte>(y));
2160 template<>
inline byte rotrMod<byte>(
byte x,
unsigned int y)
2162 return _rotr8(x,
static_cast<byte>(y));
2167 #if (defined(__MWERKS__) && TARGET_CPU_PPC)
2169 template<>
inline word32 rotlFixed<word32>(
word32 x,
unsigned int y)
2172 return y ? __rlwinm(x,y,0,31) : x;
2175 template<>
inline word32 rotrFixed<word32>(
word32 x,
unsigned int y)
2178 return y ? __rlwinm(x,32-y,0,31) : x;
2181 template<>
inline word32 rotlVariable<word32>(
word32 x,
unsigned int y)
2184 return (__rlwnm(x,y,0,31));
2187 template<>
inline word32 rotrVariable<word32>(
word32 x,
unsigned int y)
2190 return (__rlwnm(x,32-y,0,31));
2193 template<>
inline word32 rotlMod<word32>(
word32 x,
unsigned int y)
2195 return (__rlwnm(x,y,0,31));
2198 template<>
inline word32 rotrMod<word32>(
word32 x,
unsigned int y)
2200 return (__rlwnm(x,32-y,0,31));
2215 return GETBYTE(value, index);
2217 return GETBYTE(value,
sizeof(T)-index-1);
2235 #if defined(CRYPTOPP_BYTESWAP_AVAILABLE)
2236 return bswap_16(value);
2237 #elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL))
2238 return _byteswap_ushort(value);
2250 #if defined(CRYPTOPP_BYTESWAP_AVAILABLE)
2251 return bswap_32(value);
2252 #elif defined(CRYPTOPP_ARM_BYTEREV_AVAILABLE)
2254 __asm__ (
"rev %0, %1" :
"=r" (rvalue) :
"r" (value));
2256 #elif defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE)
2257 __asm__ (
"bswap %0" :
"=r" (value) :
"0" (value));
2259 #elif defined(__MWERKS__) && TARGET_CPU_PPC
2260 return (
word32)__lwbrx(&value,0);
2261 #elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL))
2262 return _byteswap_ulong(value);
2263 #elif CRYPTOPP_FAST_ROTATE(32) && !defined(__xlC__)
2268 value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
2279 #if defined(CRYPTOPP_BYTESWAP_AVAILABLE)
2280 return bswap_64(value);
2281 #elif defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(__x86_64__)
2282 __asm__ (
"bswap %0" :
"=r" (value) :
"0" (value));
2284 #elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL))
2285 return _byteswap_uint64(value);
2286 #elif CRYPTOPP_BOOL_SLOW_WORD64
2289 value = ((value &
W64LIT(0xFF00FF00FF00FF00)) >> 8) | ((value &
W64LIT(0x00FF00FF00FF00FF)) << 8);
2290 value = ((value &
W64LIT(0xFFFF0000FFFF0000)) >> 16) | ((value &
W64LIT(0x0000FFFF0000FFFF)) << 16);
2295 #if defined(CRYPTOPP_WORD128_AVAILABLE)
2314 value =
byte((value & 0xAA) >> 1) |
byte((value & 0x55) << 1);
2315 value =
byte((value & 0xCC) >> 2) |
byte((value & 0x33) << 2);
2324 #if defined(CRYPTOPP_ARM_BITREV_AVAILABLE)
2327 __asm__ (
"rbit %0, %1" :
"=r" (rvalue) :
"r" (value));
2328 return word16(rvalue >> 16);
2331 value =
word16((value & 0xAAAA) >> 1) |
word16((value & 0x5555) << 1);
2332 value =
word16((value & 0xCCCC) >> 2) |
word16((value & 0x3333) << 2);
2333 value =
word16((value & 0xF0F0) >> 4) |
word16((value & 0x0F0F) << 4);
2343 #if defined(CRYPTOPP_ARM_BITREV_AVAILABLE)
2346 __asm__ (
"rbit %0, %1" :
"=r" (rvalue) :
"r" (value));
2350 value =
word32((value & 0xAAAAAAAA) >> 1) |
word32((value & 0x55555555) << 1);
2351 value =
word32((value & 0xCCCCCCCC) >> 2) |
word32((value & 0x33333333) << 2);
2352 value =
word32((value & 0xF0F0F0F0) >> 4) |
word32((value & 0x0F0F0F0F) << 4);
2362 #if CRYPTOPP_BOOL_SLOW_WORD64
2385 else if (
sizeof(T) == 2)
2387 else if (
sizeof(T) == 4)
2389 else if (
sizeof(T) == 8)
2391 #if defined(CRYPTOPP_WORD128_AVAILABLE)
2392 else if (
sizeof(T) == 16)
2458 size_t count = byteCount/
sizeof(T);
2459 for (
size_t i=0; i<count; i++)
2482 memcpy_s(out, byteCount, in, byteCount);
2495 const size_t U =
sizeof(T);
2497 memcpy_s(out, outlen*U, in, inlen);
2498 memset_z((
byte *)out+inlen, 0, outlen*U-inlen);
2511 CRYPTOPP_UNUSED(order); CRYPTOPP_UNUSED(unused);
2524 CRYPTOPP_UNUSED(unused);
2526 ? block[1] | (block[0] << 8)
2527 : block[0] | (block[1] << 8);
2539 CRYPTOPP_UNUSED(unused);
2554 CRYPTOPP_UNUSED(unused);
2558 (
word64(block[6]) << 8) |
2559 (
word64(block[5]) << 16) |
2560 (
word64(block[4]) << 24) |
2561 (
word64(block[3]) << 32) |
2562 (
word64(block[2]) << 40) |
2563 (
word64(block[1]) << 48) |
2564 (
word64(block[0]) << 56))
2567 (
word64(block[1]) << 8) |
2568 (
word64(block[2]) << 16) |
2569 (
word64(block[3]) << 24) |
2570 (
word64(block[4]) << 32) |
2571 (
word64(block[5]) << 40) |
2572 (
word64(block[6]) << 48) |
2573 (
word64(block[7]) << 56));
2576 #if defined(CRYPTOPP_WORD128_AVAILABLE)
2587 CRYPTOPP_UNUSED(unused);
2635 CRYPTOPP_UNUSED(order);
2636 block[0] =
static_cast<byte>(xorBlock ? (value ^ xorBlock[0]) : value);
2652 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2653 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2657 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2658 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2665 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2666 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2670 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2671 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2689 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2690 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2691 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2692 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2696 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2697 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2698 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2699 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2706 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2707 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2708 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2709 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2713 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2714 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2715 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2716 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2734 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2735 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2736 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2737 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2738 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2739 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2740 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2741 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2745 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2746 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2747 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2748 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2749 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2750 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2751 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2752 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2759 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2760 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2761 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2762 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2763 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2764 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2765 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2766 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2770 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2771 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2772 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2773 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2774 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2775 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2776 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2777 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2782 #if defined(CRYPTOPP_WORD128_AVAILABLE)
2797 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 15);
2798 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 14);
2799 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 13);
2800 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 12);
2801 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 11);
2802 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 10);
2803 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 9);
2804 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 8);
2806 block[ 8] = xorBlock[ 8] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2807 block[ 9] = xorBlock[ 9] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2808 block[10] = xorBlock[10] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2809 block[11] = xorBlock[11] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2810 block[12] = xorBlock[12] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2811 block[13] = xorBlock[13] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2812 block[14] = xorBlock[14] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2813 block[15] = xorBlock[15] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2817 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 15);
2818 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 14);
2819 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 13);
2820 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 12);
2821 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 11);
2822 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 10);
2823 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 9);
2824 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 8);
2826 block[ 8] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2827 block[ 9] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2828 block[10] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2829 block[11] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2830 block[12] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2831 block[13] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2832 block[14] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2833 block[15] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2840 block[0] = xorBlock[0] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2841 block[1] = xorBlock[1] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2842 block[2] = xorBlock[2] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2843 block[3] = xorBlock[3] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2844 block[4] = xorBlock[4] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2845 block[5] = xorBlock[5] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2846 block[6] = xorBlock[6] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2847 block[7] = xorBlock[7] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2849 block[ 8] = xorBlock[ 8] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 8);
2850 block[ 9] = xorBlock[ 9] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 9);
2851 block[10] = xorBlock[10] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 10);
2852 block[11] = xorBlock[11] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 11);
2853 block[12] = xorBlock[12] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 12);
2854 block[13] = xorBlock[13] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 13);
2855 block[14] = xorBlock[14] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 14);
2856 block[15] = xorBlock[15] ^ CRYPTOPP_GET_BYTE_AS_BYTE(value, 15);
2860 block[0] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 0);
2861 block[1] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 1);
2862 block[2] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 2);
2863 block[3] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 3);
2864 block[4] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 4);
2865 block[5] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 5);
2866 block[6] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 6);
2867 block[7] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 7);
2869 block[ 8] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 8);
2870 block[ 9] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 9);
2871 block[10] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 10);
2872 block[11] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 11);
2873 block[12] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 12);
2874 block[13] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 13);
2875 block[14] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 14);
2876 block[15] = CRYPTOPP_GET_BYTE_AS_BYTE(value, 15);
2901 CRYPTOPP_UNUSED(assumeAligned);
2904 if (block != NULLPTR) {std::memcpy(&temp, block,
sizeof(T));}
2927 result = GetWord<T>(assumeAligned, order, block);
2941 inline void PutWord(
bool assumeAligned,
ByteOrder order,
byte *block, T value,
const byte *xorBlock = NULLPTR)
2943 CRYPTOPP_UNUSED(assumeAligned);
2947 if (xorBlock != NULLPTR) {std::memcpy(&t2, xorBlock,
sizeof(T)); t1 ^= t2;}
2948 if (block != NULLPTR) {std::memcpy(block, &t1,
sizeof(T));}
2966 template <
class T,
class B,
bool A=false>
2973 : m_block((const
byte *)block) {}
2983 x = GetWord<T>(A, B::ToEnum(), m_block);
2984 m_block +=
sizeof(T);
2989 const byte *m_block;
3007 template <
class T,
class B,
bool A=false>
3015 : m_xorBlock((const
byte *)xorBlock), m_block((
byte *)block) {}
3024 PutWord(A, B::ToEnum(), m_block, (T)x, m_xorBlock);
3025 m_block +=
sizeof(T);
3027 m_xorBlock +=
sizeof(T);
3032 const byte *m_xorBlock;
3044 template <
class T,
class B,
bool GA=false,
bool PA=false>
3063 return std::string((
char *)&value,
sizeof(value));
3102 CRYPTOPP_UNUSED(value); CRYPTOPP_UNUSED(bits);
3114 CRYPTOPP_UNUSED(value); CRYPTOPP_UNUSED(bits);
3132 return value >> bits;
3143 return value << bits;
3155 template <
unsigned int bits,
class T>
3158 return SafeShifter<(bits>=(8*
sizeof(T)))>::RightShift(value, bits);
3169 template <
unsigned int bits,
class T>
3172 return SafeShifter<(bits>=(8*
sizeof(T)))>::LeftShift(value, bits);
3182 template<
typename InputIt,
typename T>
3183 inline InputIt
FindIfNot(InputIt first, InputIt last,
const T &value) {
3184 #ifdef CRYPTOPP_CXX11_LAMBDA
3185 return std::find_if(first, last, [&value](
const T &o) {
3189 return std::find_if(first, last, std::bind2nd(std::not_equal_to<T>(), value));
3195 #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);}
3196 #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);}
3197 #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);}
3198 #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);}
3199 #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);}
3200 #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);}
3201 #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);}
3202 #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);}
3203 #define CRYPTOPP_BLOCKS_END(i) size_t SST() {return SS##i();} void AllocateBlocks() {m_aggregate.New(SST());} AlignedSecByteBlock m_aggregate;
3207 #if (CRYPTOPP_MSC_VERSION)
3208 # pragma warning(pop)
3211 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
3212 # 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(const void *xorBlock, void *block)
Construct a PutBlock.
PutBlock< T, B, A > & operator()(U x)
Access a block of memory.
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
void * memset_z(void *ptr, int val, size_t num)
Memory block initializer.
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.
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 std::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.
#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.
#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.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
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.
byte * BytePtr(std::string &str)
Pointer to the first element of a string.
#define EnumToInt(v)
Integer value.
T rotlMod(T x, unsigned int y)
Performs a left rotate.
void memmove_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
Bounds checking replacement for std::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.
const T & STDMAX(const T &a, const T &b)
Replacement function for std::max.
T NumericLimitsMax()
Provide the maximum value for a type.
const byte * ConstBytePtr(const std::string &str)
Const pointer to the first element of a string.
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.