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) 35 if (IsAligned<word32>(buf) && IsAligned<word32>(mask))
37 if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsAligned<word64>(buf) && IsAligned<word64>(mask))
39 for (i=0; i<count/8; i++)
40 ((word64*)buf)[i] ^= ((word64*)mask)[i];
48 for (i=0; i<count/4; i++)
49 ((word32*)buf)[i] ^= ((word32*)mask)[i];
57 for (i=0; i<count; i++)
61 void xorbuf(byte *output,
const byte *input,
const byte *mask,
size_t count)
63 assert(output != NULL);
64 assert(input != NULL);
68 if (IsAligned<word32>(output) && IsAligned<word32>(input) && IsAligned<word32>(mask))
70 if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsAligned<word64>(output) && IsAligned<word64>(input) && IsAligned<word64>(mask))
72 for (i=0; i<count/8; i++)
73 ((word64*)output)[i] = ((word64*)input)[i] ^ ((word64*)mask)[i];
82 for (i=0; i<count/4; i++)
83 ((word32*)output)[i] = ((word32*)input)[i] ^ ((word32*)mask)[i];
92 for (i=0; i<count; i++)
93 output[i] = input[i] ^ mask[i];
105 if (IsAligned<word32>(buf) && IsAligned<word32>(mask))
108 if (!CRYPTOPP_BOOL_SLOW_WORD64 && IsAligned<word64>(buf) && IsAligned<word64>(mask))
111 for (i=0; i<count/8; i++)
112 acc64 |= ((word64*)buf)[i] ^ ((word64*)mask)[i];
118 acc32 = word32(acc64) | word32(acc64>>32);
121 for (i=0; i<count/4; i++)
122 acc32 |= ((word32*)buf)[i] ^ ((word32*)mask)[i];
128 acc8 = byte(acc32) | byte(acc32>>8) | byte(acc32>>16) | byte(acc32>>24);
131 for (i=0; i<count; i++)
132 acc8 |= buf[i] ^ mask[i];
136 #if !(defined(_MSC_VER) && (_MSC_VER < 1300)) 137 using std::new_handler;
138 using std::set_new_handler;
143 new_handler newHandler = set_new_handler(NULL);
145 set_new_handler(newHandler);
150 throw std::bad_alloc();
153 #if CRYPTOPP_BOOL_ALIGN16 158 #if defined(CRYPTOPP_APPLE_ALLOC_AVAILABLE) 159 while ((p = (byte *)calloc(1, size)) == NULL)
160 #elif defined(CRYPTOPP_MM_MALLOC_AVAILABLE) 161 while ((p = (byte *)_mm_malloc(size, 16)) == NULL)
162 #elif defined(CRYPTOPP_MEMALIGN_AVAILABLE) 163 while ((p = (byte *)memalign(16, size)) == NULL)
164 #elif defined(CRYPTOPP_MALLOC_ALIGNMENT_IS_16) 165 while ((p = (byte *)malloc(size)) == NULL)
167 while ((p = (byte *)malloc(size + 16)) == NULL)
171 #ifdef CRYPTOPP_NO_ALIGNED_ALLOC 172 size_t adjustment = 16-((size_t)p%16);
174 p[-1] = (byte)adjustment;
183 #ifdef CRYPTOPP_MM_MALLOC_AVAILABLE 185 #elif defined(CRYPTOPP_NO_ALIGNED_ALLOC) 186 p = (byte *)p - ((byte *)p)[-1];
198 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.