11
#if defined(CRYPTOPP_MEMALIGN_AVAILABLE) || defined(CRYPTOPP_MM_MALLOC_AVAILABLE) || defined(QNX)
11
15
NAMESPACE_BEGIN(CryptoPP)
17
// Vectorization at -O3 requires IsStrictAligned<word64> for GCC 4.8 and above with xorbuf and VerifyBufsEqual.
18
// Problems have not been experienced for the word32 variant, but it may aoccur in the future.
13
20
void xorbuf(byte *buf, const byte *mask, size_t count)
15
if (((size_t)buf | (size_t)mask | count) % WORD_SIZE == 0)
16
XorWords((word *)buf, (const word *)mask, count/WORD_SIZE);
24
if (IsAligned<word32>(buf) && IsAligned<word32>(mask))
19
for (unsigned int i=0; i<count; i++)
26
if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsStrictAligned<word64>(buf) && IsStrictAligned<word64>(mask))
28
assert(IsAlignedOn(buf, GetStrictAlignmentOf<word64>()));
29
assert(IsAlignedOn(mask, GetStrictAlignmentOf<word64>()));
31
for (i=0; i<count/8; i++)
32
((word64*)buf)[i] ^= ((word64*)mask)[i];
40
for (i=0; i<count/4; i++)
41
((word32*)buf)[i] ^= ((word32*)mask)[i];
49
for (i=0; i<count; i++)
24
53
void xorbuf(byte *output, const byte *input, const byte *mask, size_t count)
26
if (((size_t)output | (size_t)input | (size_t)mask | count) % WORD_SIZE == 0)
27
XorWords((word *)output, (const word *)input, (const word *)mask, count/WORD_SIZE);
30
for (unsigned int i=0; i<count; i++)
31
output[i] = input[i] ^ mask[i];
57
if (IsAligned<word32>(output) && IsAligned<word32>(input) && IsAligned<word32>(mask))
59
if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsStrictAligned<word64>(output) && IsStrictAligned<word64>(input) && IsStrictAligned<word64>(mask))
61
assert(IsAlignedOn(output, GetStrictAlignmentOf<word64>()));
62
assert(IsAlignedOn(input, GetStrictAlignmentOf<word64>()));
63
assert(IsAlignedOn(mask, GetStrictAlignmentOf<word64>()));
65
for (i=0; i<count/8; i++)
66
((word64*)output)[i] = ((word64*)input)[i] ^ ((word64*)mask)[i];
75
for (i=0; i<count/4; i++)
76
((word32*)output)[i] = ((word32*)input)[i] ^ ((word32*)mask)[i];
85
for (i=0; i<count; i++)
86
output[i] = input[i] ^ mask[i];
89
bool VerifyBufsEqual(const byte *buf, const byte *mask, size_t count)
94
if (IsAligned<word32>(buf) && IsAligned<word32>(mask))
97
if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsStrictAligned<word64>(buf) && IsStrictAligned<word64>(mask))
99
assert(IsAlignedOn(buf, GetStrictAlignmentOf<word64>()));
100
assert(IsAlignedOn(mask, GetStrictAlignmentOf<word64>()));
103
for (i=0; i<count/8; i++)
104
acc64 |= ((word64*)buf)[i] ^ ((word64*)mask)[i];
110
acc32 = word32(acc64) | word32(acc64>>32);
113
for (i=0; i<count/4; i++)
114
acc32 |= ((word32*)buf)[i] ^ ((word32*)mask)[i];
120
acc8 = byte(acc32) | byte(acc32>>8) | byte(acc32>>16) | byte(acc32>>24);
123
for (i=0; i<count; i++)
124
acc8 |= buf[i] ^ mask[i];
35
128
#if !(defined(_MSC_VER) && (_MSC_VER < 1300))
49
142
throw std::bad_alloc();
145
#if CRYPTOPP_BOOL_ALIGN16_ENABLED
147
void * AlignedAllocate(size_t size)
150
#ifdef CRYPTOPP_MM_MALLOC_AVAILABLE
151
while (!(p = (byte *)_mm_malloc(size, 16)))
152
#elif defined(CRYPTOPP_MEMALIGN_AVAILABLE)
153
while (!(p = (byte *)memalign(16, size)))
154
#elif defined(CRYPTOPP_MALLOC_ALIGNMENT_IS_16)
155
while (!(p = (byte *)malloc(size)))
157
while (!(p = (byte *)malloc(size + 16)))
161
#ifdef CRYPTOPP_NO_ALIGNED_ALLOC
162
size_t adjustment = 16-((size_t)p%16);
164
p[-1] = (byte)adjustment;
167
assert(IsAlignedOn(p, 16));
171
void AlignedDeallocate(void *p)
173
#ifdef CRYPTOPP_MM_MALLOC_AVAILABLE
175
#elif defined(CRYPTOPP_NO_ALIGNED_ALLOC)
176
p = (byte *)p - ((byte *)p)[-1];
185
void * UnalignedAllocate(size_t size)
188
while (!(p = malloc(size)))
193
void UnalignedDeallocate(void *p)