70void xorbuf(
byte *buf,
const byte *mask,
size_t count)
72 CRYPTOPP_ASSERT(buf != NULLPTR);
73 CRYPTOPP_ASSERT(mask != NULLPTR);
74 CRYPTOPP_ASSERT(count > 0);
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
114 word64 r[2], b[2], m[2];
115 memcpy(&b, buf, 16); memcpy(&m, mask, 16);
121 buf += 16; mask += 16; count -= 16;
126 if (count == 0)
return;
131 memcpy(&b, buf, 4); memcpy(&m, mask, 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)
146 CRYPTOPP_ASSERT(output != NULLPTR);
147 CRYPTOPP_ASSERT(input != NULLPTR);
148 CRYPTOPP_ASSERT(count > 0);
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
188 word64 b[2], m[2], r[2];
189 memcpy(&b, input, 16); memcpy(&m, mask, 16);
193 memcpy(output, &r, 16);
195 output += 16; input += 16; mask += 16; count -= 16;
200 if (count == 0)
return;
205 memcpy(&b, input, 4); memcpy(&m, mask, 4);
208 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];
218bool VerifyBufsEqual(
const byte *buf,
const byte *mask,
size_t count)
220 CRYPTOPP_ASSERT(buf != NULLPTR);
221 CRYPTOPP_ASSERT(mask != NULLPTR);
224#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_ARM64 || CRYPTOPP_BOOL_PPC64 || CRYPTOPP_BOOL_MIPS64 || CRYPTOPP_BOOL_SPARC64
229 memcpy(&b, buf, 8); 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 memcpy(&b, buf, 4); 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)
266 CRYPTOPP_ASSERT(str);
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));
279 CRYPTOPP_ASSERT(err == 0);
285 return std::string();
289 err = wcstombs_s(&size, &result[0], size, str, len*
sizeof(
wchar_t));
290 CRYPTOPP_ASSERT(err == 0);
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);
304 CRYPTOPP_ASSERT(size != (
size_t)-1);
305 if (size == (
size_t)-1)
310 return std::string();
314 size = wcstombs(&result[0], str, size);
315 CRYPTOPP_ASSERT(size != (
size_t)-1);
316 if (size == (
size_t)-1)
321 return std::string();
328std::wstring StringWiden(
const char *str,
bool throwOnError)
330 CRYPTOPP_ASSERT(str);
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);
343 CRYPTOPP_ASSERT(err == 0);
349 return std::wstring();
353 err = mbstowcs_s(&size, &result[0], size, str, len);
354 CRYPTOPP_ASSERT(err == 0);
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);
368 CRYPTOPP_ASSERT(size != (
size_t)-1);
369 if (size == (
size_t)-1)
374 return std::wstring();
378 size = mbstowcs(&result[0], str, size);
379 CRYPTOPP_ASSERT(size != (
size_t)-1);
380 if (size == (
size_t)-1)
385 return std::wstring();