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
23#if defined(__OpenBSD__)
24# if defined (CRYPTOPP_GCC_VERSION) && (CRYPTOPP_GCC_VERSION < 43000)
25# undef CRYPTOPP_DISABLE_ASM
26# define CRYPTOPP_DISABLE_ASM 1
30#ifndef CRYPTOPP_DISABLE_ASM
32# include <emmintrin.h>
35# include <immintrin.h>
38# if defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
39# if (CRYPTOPP_ARM_NEON_HEADER) || (CRYPTOPP_ARM_ASIMD_AVAILABLE)
54 return reinterpret_cast<byte*
>(str.
data());
61 return reinterpret_cast<const byte*
>(str.
data());
70void xorbuf(
byte *buf,
const byte *mask,
size_t count)
76#ifndef CRYPTOPP_DISABLE_ASM
80 __m256i b = _mm256_loadu_si256(
reinterpret_cast<const __m256i*
>(buf));
81 __m256i m = _mm256_loadu_si256(
reinterpret_cast<const __m256i*
>(mask));
82 _mm256_storeu_si256(
reinterpret_cast<__m256i*
>(buf), _mm256_castps_si256(
83 _mm256_xor_ps(_mm256_castsi256_ps(b), _mm256_castsi256_ps(m))));
84 buf += 32; mask += 32; count -= 32;
92 __m128i b = _mm_loadu_si128(
reinterpret_cast<const __m128i*
>(buf));
93 __m128i m = _mm_loadu_si128(
reinterpret_cast<const __m128i*
>(mask));
94 _mm_storeu_si128(
reinterpret_cast<__m128i*
>(buf), _mm_castps_si128(
95 _mm_xor_ps(_mm_castsi128_ps(b), _mm_castsi128_ps(m))));
96 buf += 16; mask += 16; count -= 16;
99# if defined(__aarch64__) || defined(__aarch32__) || defined(_M_ARM64)
102 vst1q_u8(buf, veorq_u8(vld1q_u8(buf), vld1q_u8(mask)));
103 buf += 16; mask += 16; count -= 16;
108#if CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64
115 std::memcpy(&b, buf, 16); std::memcpy(&m, mask, 16);
119 std::memcpy(buf, &r, 16);
121 buf += 16; mask += 16; count -= 16;
126 if (count == 0)
return;
131 std::memcpy(&b, buf, 4); std::memcpy(&m, mask, 4);
134 std::memcpy(buf, &r, 4);
136 buf += 4; mask += 4; count -= 4;
139 for (
size_t i=0; i<count; i++)
144void xorbuf(
byte *output,
const byte *input,
const byte *mask,
size_t count)
150#ifndef CRYPTOPP_DISABLE_ASM
154 __m256i b = _mm256_loadu_si256(
reinterpret_cast<const __m256i*
>(input));
155 __m256i m = _mm256_loadu_si256(
reinterpret_cast<const __m256i*
>(mask));
156 _mm256_storeu_si256(
reinterpret_cast<__m256i*
>(output), _mm256_castps_si256(
157 _mm256_xor_ps(_mm256_castsi256_ps(b), _mm256_castsi256_ps(m))));
158 output += 32; input += 32; mask += 32; count -= 32;
163# if defined(__SSE2__)
166 __m128i b = _mm_loadu_si128(
reinterpret_cast<const __m128i*
>(input));
167 __m128i m = _mm_loadu_si128(
reinterpret_cast<const __m128i*
>(mask));
168 _mm_storeu_si128(
reinterpret_cast<__m128i*
>(output), _mm_castps_si128(
169 _mm_xor_ps(_mm_castsi128_ps(b), _mm_castsi128_ps(m))));
170 output += 16; input += 16; mask += 16; count -= 16;
173# if defined(__aarch64__) || defined(__aarch32__) || defined(_M_ARM64)
176 vst1q_u8(output, veorq_u8(vld1q_u8(input), vld1q_u8(mask)));
177 output += 16; input += 16; mask += 16; count -= 16;
182#if CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64
189 std::memcpy(&b, input, 16); std::memcpy(&m, mask, 16);
193 std::memcpy(output, &r, 16);
195 output += 16; input += 16; mask += 16; count -= 16;
200 if (count == 0)
return;
205 std::memcpy(&b, input, 4); std::memcpy(&m, mask, 4);
208 std::memcpy(output, &r, 4);
210 output += 4; input += 4; mask += 4; count -= 4;
213 for (
size_t i=0; i<count; i++)
214 output[i] = input[i] ^ mask[i];
224#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_ARM64 || CRYPTOPP_BOOL_PPC64 || CRYPTOPP_BOOL_MIPS64 || CRYPTOPP_BOOL_SPARC64
229 std::memcpy(&b, buf, 8); std::memcpy(&m, mask, 8);
232 buf += 8; mask += 8; count -= 8;
235 word32 acc8 = (acc64 >> 32) | (acc64 & 0xffffffff);
236 acc8 =
static_cast<byte>(acc8) |
static_cast<byte>(acc8 >> 8) |
237 static_cast<byte>(acc8 >> 16) |
static_cast<byte>(acc8 >> 24);
243 std::memcpy(&b, buf, 4); std::memcpy(&m, mask, 4);
246 buf += 4; mask += 4; count -= 4;
250 acc8 =
static_cast<byte>(acc8) |
static_cast<byte>(acc8 >> 8) |
251 static_cast<byte>(acc8 >> 16) |
static_cast<byte>(acc8 >> 24);
254 for (
size_t i=0; i<count; i++)
255 acc8 |= buf[i] ^ mask[i];
264std::string
StringNarrow(
const wchar_t *str,
bool throwOnError)
270#if (CRYPTOPP_MSC_VERSION >= 1400)
271 size_t len=0, size=0;
278 err = wcstombs_s(&size, NULLPTR, 0, str, len*
sizeof(
wchar_t));
285 return std::string();
289 err = wcstombs_s(&size, &result[0], size, str, len*
sizeof(
wchar_t));
296 return std::string();
300 if (!result.empty() && result[size - 1] ==
'\0')
301 result.erase(size - 1);
303 size_t size = wcstombs(NULLPTR, str, 0);
305 if (size == (
size_t)-1)
310 return std::string();
314 size = wcstombs(&result[0], str, size);
316 if (size == (
size_t)-1)
321 return std::string();
328std::wstring
StringWiden(
const char *str,
bool throwOnError)
334#if (CRYPTOPP_MSC_VERSION >= 1400)
335 size_t len=0, size=0;
340 len = std::strlen(str)+1;
342 err = mbstowcs_s(&size, NULLPTR, 0, str, len);
349 return std::wstring();
353 err = mbstowcs_s(&size, &result[0], size, str, len);
360 return std::wstring();
364 if (!result.empty() && result[size - 1] ==
'\0')
365 result.erase(size - 1);
367 size_t size = mbstowcs(NULLPTR, str, 0);
369 if (size == (
size_t)-1)
374 return std::wstring();
378 size = mbstowcs(&result[0], str, size);
380 if (size == (
size_t)-1)
385 return std::wstring();
An invalid argument was detected.
A::pointer data()
Provides a pointer to the first element in the memory block.
bool empty() const
Determines if the SecBlock is empty.
size_type size() const
Provides the count of elements in the SecBlock.
Library configuration file.
unsigned int word32
32-bit unsigned datatype
unsigned long long word64
64-bit unsigned datatype
Multiple precision integer with arithmetic operations.
Utility functions for the Crypto++ library.
size_t BytePtrSize(const std::string &str)
Size of a string.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
const byte * ConstBytePtr(const std::string &str)
Const pointer to the first element of a string.
std::string StringNarrow(const wchar_t *str, bool throwOnError=true)
Converts a wide character C-string to a multibyte string.
std::wstring StringWiden(const char *str, bool throwOnError=true)
Converts a multibyte C-string to a wide character string.
byte * BytePtr(std::string &str)
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.
CRYPTOPP_DLL void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
Crypto++ library namespace.
Classes and functions for secure memory allocations.
Debugging and diagnostic assertions.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Support functions for word operations.