6#if CRYPTOPP_MSC_VERSION
7# pragma warning(disable: 4189)
8# if (CRYPTOPP_MSC_VERSION >= 1400)
9# pragma warning(disable: 6237)
13#ifndef CRYPTOPP_IMPORTS
22#if defined(CRYPTOPP_MEMALIGN_AVAILABLE) || defined(CRYPTOPP_MM_MALLOC_AVAILABLE) || defined(QNX)
26#if defined(CRYPTOPP_POSIX_MEMALIGN_AVAILABLE)
32void xorbuf(
byte *buf, const
byte *mask,
size_t count)
39 if (IsAligned<word32>(buf) && IsAligned<word32>(mask))
41 if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsAligned<word64>(buf) && IsAligned<word64>(mask))
43 for (i=0; i<count/8; i++)
44 ((word64*)(
void*)buf)[i] ^= ((word64*)(
void*)mask)[i];
52 for (i=0; i<count/4; i++)
53 ((word32*)(
void*)buf)[i] ^= ((word32*)(
void*)mask)[i];
61 for (i=0; i<count; i++)
65void xorbuf(
byte *output,
const byte *input,
const byte *mask,
size_t count)
72 if (IsAligned<word32>(output) && IsAligned<word32>(input) && IsAligned<word32>(mask))
74 if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsAligned<word64>(output) && IsAligned<word64>(input) && IsAligned<word64>(mask))
76 for (i=0; i<count/8; i++)
77 ((word64*)(
void*)output)[i] = ((word64*)(
void*)input)[i] ^ ((word64*)(
void*)mask)[i];
86 for (i=0; i<count/4; i++)
87 ((word32*)(
void*)output)[i] = ((word32*)(
void*)input)[i] ^ ((word32*)(
void*)mask)[i];
96 for (i=0; i<count; i++)
97 output[i] = input[i] ^ mask[i];
100bool VerifyBufsEqual(
const byte *buf,
const byte *mask,
size_t count)
109 if (IsAligned<word32>(buf) && IsAligned<word32>(mask))
112 if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsAligned<word64>(buf) && IsAligned<word64>(mask))
115 for (i=0; i<count/8; i++)
116 acc64 |= ((word64*)(
void*)buf)[i] ^ ((word64*)(
void*)mask)[i];
122 acc32 = word32(acc64) | word32(acc64>>32);
125 for (i=0; i<count/4; i++)
126 acc32 |= ((word32*)(
void*)buf)[i] ^ ((word32*)(
void*)mask)[i];
132 acc8 = byte(acc32) | byte(acc32>>8) | byte(acc32>>16) | byte(acc32>>24);
135 for (i=0; i<count; i++)
136 acc8 |= buf[i] ^ mask[i];
140std::string StringNarrow(
const wchar_t *str,
bool throwOnError)
146#if (CRYPTOPP_MSC_VERSION >= 1400)
147 size_t len=0, size=0;
154 err = wcstombs_s(&size, NULLPTR, 0, str, len*
sizeof(
wchar_t));
161 return std::string();
165 err = wcstombs_s(&size, &result[0], size, str, len*
sizeof(
wchar_t));
172 return std::string();
176 if (!result.empty() && result[size - 1] ==
'\0')
177 result.erase(size - 1);
179 size_t size = wcstombs(NULLPTR, str, 0);
181 if (size == (
size_t)-1)
186 return std::string();
190 size = wcstombs(&result[0], str, size);
192 if (size == (
size_t)-1)
197 return std::string();
204std::wstring StringWiden(
const char *str,
bool throwOnError)
210#if (CRYPTOPP_MSC_VERSION >= 1400)
211 size_t len=0, size=0;
216 len = std::strlen(str)+1;
218 err = mbstowcs_s(&size, NULLPTR, 0, str, len);
225 return std::wstring();
229 err = mbstowcs_s(&size, &result[0], size, str, len);
236 return std::wstring();
240 if (!result.empty() && result[size - 1] ==
'\0')
241 result.erase(size - 1);
243 size_t size = mbstowcs(NULLPTR, str, 0);
245 if (size == (
size_t)-1)
250 return std::wstring();
254 size = mbstowcs(&result[0], str, size);
256 if (size == (
size_t)-1)
261 return std::wstring();
270 using std::new_handler;
271 using std::set_new_handler;
273 new_handler newHandler = set_new_handler(NULLPTR);
275 set_new_handler(newHandler);
280 throw std::bad_alloc();
283void * AlignedAllocate(
size_t size)
286#if defined(CRYPTOPP_MM_MALLOC_AVAILABLE)
287 while ((p = (
byte *)_mm_malloc(size, 16)) == NULLPTR)
288#elif defined(CRYPTOPP_MEMALIGN_AVAILABLE)
289 while ((p = (
byte *)memalign(16, size)) == NULLPTR)
290#elif defined(CRYPTOPP_MALLOC_ALIGNMENT_IS_16)
291 while ((p = (
byte *)malloc(size)) == NULLPTR)
292#elif defined(CRYPTOPP_POSIX_MEMALIGN_AVAILABLE)
293 while (posix_memalign(
reinterpret_cast<void**
>(&p), 16, size) != 0)
295 while ((p = (
byte *)malloc(size + 16)) == NULLPTR)
299#ifdef CRYPTOPP_NO_ALIGNED_ALLOC
300 size_t adjustment = 16-((size_t)p%16);
303 p[-1] = (byte)adjustment;
312void AlignedDeallocate(
void *p)
314#ifdef CRYPTOPP_MM_MALLOC_AVAILABLE
316#elif defined(CRYPTOPP_NO_ALIGNED_ALLOC)
317 p = (
byte *)p - ((
byte *)p)[-1];
324void * UnalignedAllocate(
size_t size)
327 while ((p = malloc(size)) == NULLPTR)
332void UnalignedDeallocate(
void *p)
An invalid argument was detected.
Library configuration file.
Multiple precision integer with arithmetic operations.
Utility functions for the Crypto++ library.
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.
Crypto++ library namespace.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.