ext-cryptopp/misc.cpp

55 lines
1.1 KiB
C++
Raw Normal View History

2002-10-04 17:31:41 +00:00
// misc.cpp - written and placed in the public domain by Wei Dai
#include "pch.h"
#ifndef CRYPTOPP_IMPORTS
2002-10-04 17:31:41 +00:00
#include "misc.h"
#include "words.h"
#include <new>
2002-10-04 17:31:41 +00:00
NAMESPACE_BEGIN(CryptoPP)
2005-07-12 04:23:32 +00:00
void xorbuf(byte *buf, const byte *mask, size_t count)
2002-10-04 17:31:41 +00:00
{
2003-07-26 08:35:40 +00:00
if (((size_t)buf | (size_t)mask | count) % WORD_SIZE == 0)
2002-10-04 17:31:41 +00:00
XorWords((word *)buf, (const word *)mask, count/WORD_SIZE);
else
{
for (unsigned int i=0; i<count; i++)
buf[i] ^= mask[i];
}
}
2005-07-12 04:23:32 +00:00
void xorbuf(byte *output, const byte *input, const byte *mask, size_t count)
2002-10-04 17:31:41 +00:00
{
2003-07-26 08:35:40 +00:00
if (((size_t)output | (size_t)input | (size_t)mask | count) % WORD_SIZE == 0)
2002-10-04 17:31:41 +00:00
XorWords((word *)output, (const word *)input, (const word *)mask, count/WORD_SIZE);
else
{
for (unsigned int i=0; i<count; i++)
output[i] = input[i] ^ mask[i];
}
}
#if !(defined(_MSC_VER) && (_MSC_VER < 1300))
using std::new_handler;
2003-08-25 21:41:09 +00:00
using std::set_new_handler;
#endif
void CallNewHandler()
{
new_handler newHandler = set_new_handler(NULL);
if (newHandler)
set_new_handler(newHandler);
if (newHandler)
newHandler();
else
throw std::bad_alloc();
}
2002-10-04 17:31:41 +00:00
NAMESPACE_END
#endif