6 #if CRYPTOPP_MSC_VERSION 7 # pragma warning(disable: 4189 6237) 10 #ifndef CRYPTOPP_IMPORTS 19 #if defined(CRYPTOPP_MEMALIGN_AVAILABLE) || defined(CRYPTOPP_MM_MALLOC_AVAILABLE) || defined(QNX) 32 if (IsAligned<word32>(buf) && IsAligned<word32>(mask))
34 if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsAligned<word64>(buf) && IsAligned<word64>(mask))
36 for (i=0; i<count/8; i++)
37 ((word64*)buf)[i] ^= ((word64*)mask)[i];
45 for (i=0; i<count/4; i++)
46 ((word32*)buf)[i] ^= ((word32*)mask)[i];
54 for (i=0; i<count; i++)
58 void xorbuf(byte *output,
const byte *input,
const byte *mask,
size_t count)
60 assert(output != NULL);
61 assert(input != NULL);
65 if (IsAligned<word32>(output) && IsAligned<word32>(input) && IsAligned<word32>(mask))
67 if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsAligned<word64>(output) && IsAligned<word64>(input) && IsAligned<word64>(mask))
69 for (i=0; i<count/8; i++)
70 ((word64*)output)[i] = ((word64*)input)[i] ^ ((word64*)mask)[i];
79 for (i=0; i<count/4; i++)
80 ((word32*)output)[i] = ((word32*)input)[i] ^ ((word32*)mask)[i];
89 for (i=0; i<count; i++)
90 output[i] = input[i] ^ mask[i];
102 if (IsAligned<word32>(buf) && IsAligned<word32>(mask))
105 if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsAligned<word64>(buf) && IsAligned<word64>(mask))
108 for (i=0; i<count/8; i++)
109 acc64 |= ((word64*)buf)[i] ^ ((word64*)mask)[i];
115 acc32 = word32(acc64) | word32(acc64>>32);
118 for (i=0; i<count/4; i++)
119 acc32 |= ((word32*)buf)[i] ^ ((word32*)mask)[i];
125 acc8 = byte(acc32) | byte(acc32>>8) | byte(acc32>>16) | byte(acc32>>24);
128 for (i=0; i<count; i++)
129 acc8 |= buf[i] ^ mask[i];
133 #if !(defined(_MSC_VER) && (_MSC_VER < 1300)) 134 using std::new_handler;
135 using std::set_new_handler;
140 new_handler newHandler = set_new_handler(NULL);
142 set_new_handler(newHandler);
147 throw std::bad_alloc();
150 #if CRYPTOPP_BOOL_ALIGN16 155 #if defined(CRYPTOPP_APPLE_ALLOC_AVAILABLE) 156 while ((p = (byte *)calloc(1, size)) == NULL)
157 #elif defined(CRYPTOPP_MM_MALLOC_AVAILABLE) 158 while ((p = (byte *)_mm_malloc(size, 16)) == NULL)
159 #elif defined(CRYPTOPP_MEMALIGN_AVAILABLE) 160 while ((p = (byte *)memalign(16, size)) == NULL)
161 #elif defined(CRYPTOPP_MALLOC_ALIGNMENT_IS_16) 162 while ((p = (byte *)malloc(size)) == NULL)
164 while ((p = (byte *)malloc(size + 16)) == NULL)
168 #ifdef CRYPTOPP_NO_ALIGNED_ALLOC 169 size_t adjustment = 16-((size_t)p%16);
171 p[-1] = (byte)adjustment;
180 #ifdef CRYPTOPP_MM_MALLOC_AVAILABLE 182 #elif defined(CRYPTOPP_NO_ALIGNED_ALLOC) 183 p = (byte *)p - ((byte *)p)[-1];
195 while ((p = malloc(size)) == NULL)
Utility functions for the Crypto++ library.
void AlignedDeallocate(void *ptr)
Frees a buffer allocated with AlignedAllocate.
Library configuration file.
bool IsAlignedOn(const void *ptr, unsigned int alignment)
Determines whether ptr is aligned to a minimum value.
void * UnalignedAllocate(size_t size)
Allocates a buffer.
void CallNewHandler()
Attempts to reclaim unused memory.
void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
bool VerifyBufsEqual(const byte *buf1, const byte *buf2, size_t count)
Performs a near constant-time comparison of two equally sized buffers.
Crypto++ library namespace.
void UnalignedDeallocate(void *ptr)
Frees a buffer allocated with UnalignedAllocate.
void * AlignedAllocate(size_t size)
Allocates a buffer on 16-byte boundary.