本文整理汇总了C++中xorbuf函数的典型用法代码示例。如果您正苦于以下问题:C++ xorbuf函数的具体用法?C++ xorbuf怎么用?C++ xorbuf使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xorbuf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InvalidArgument
void CBC_CTS_Encryption::ProcessLastBlock(byte *outString, const byte *inString, size_t length)
{
if (length <= BlockSize())
{
if (!m_stolenIV)
throw InvalidArgument("CBC_Encryption: message is too short for ciphertext stealing");
// steal from IV
memcpy(outString, m_register, length);
outString = m_stolenIV;
}
else
{
// steal from next to last block
xorbuf(m_register, inString, BlockSize());
m_cipher->ProcessBlock(m_register);
inString += BlockSize();
length -= BlockSize();
memcpy(outString+BlockSize(), m_register, length);
}
// output last full ciphertext block
xorbuf(m_register, inString, length);
m_cipher->ProcessBlock(m_register);
memcpy(outString, m_register, BlockSize());
}
示例2: BlockSize
void CBC_CTS_Decryption::ProcessLastBlock(byte *outString, const byte *inString, size_t length)
{
const byte *pn, *pn1;
bool stealIV = length <= BlockSize();
if (stealIV)
{
pn = inString;
pn1 = m_register;
}
else
{
pn = inString + BlockSize();
pn1 = inString;
length -= BlockSize();
}
// decrypt last partial plaintext block
memcpy(m_temp, pn1, BlockSize());
m_cipher->ProcessBlock(m_temp);
xorbuf(m_temp, pn, length);
if (stealIV)
memcpy(outString, m_temp, length);
else
{
memcpy(outString+BlockSize(), m_temp, length);
// decrypt next to last plaintext block
memcpy(m_temp, pn, length);
m_cipher->ProcessBlock(m_temp);
xorbuf(outString, m_temp, m_register, BlockSize());
}
}
示例3: xorbuf
byte X917RNG::GenerateByte()
{
if (randbuf_counter==0)
{
// calculate new enciphered timestamp
if (m_deterministicTimeVector)
{
xorbuf(dtbuf, (byte *)&m_deterministicTimeVector, STDMIN((int)sizeof(m_deterministicTimeVector), S));
while (++m_deterministicTimeVector == 0) {} // skip 0
}
else
{
clock_t tstamp = clock();
xorbuf(dtbuf, (byte *)&tstamp, STDMIN((int)sizeof(tstamp), S));
}
cipher->ProcessBlock(dtbuf);
// combine enciphered timestamp with seed
xorbuf(randseed, dtbuf, S);
// generate a new block of random bytes
cipher->ProcessBlock(randseed, randbuf);
// compute new seed vector
for (int i=0; i<S; i++)
randseed[i] = randbuf[i] ^ dtbuf[i];
cipher->ProcessBlock(randseed);
randbuf_counter=S;
}
return(randbuf[--randbuf_counter]);
}
示例4: STDMIN
void AdditiveCipherTemplate<S>::ProcessData(byte *outString, const byte *inString, size_t length)
{
if (m_leftOver > 0)
{
size_t len = STDMIN(m_leftOver, length);
xorbuf(outString, inString, KeystreamBufferEnd()-m_leftOver, len);
length -= len;
m_leftOver -= len;
inString += len;
outString += len;
if (!length)
return;
}
CRYPTOPP_ASSERT(m_leftOver == 0);
PolicyInterface &policy = this->AccessPolicy();
unsigned int bytesPerIteration = policy.GetBytesPerIteration();
if (policy.CanOperateKeystream() && length >= bytesPerIteration)
{
size_t iterations = length / bytesPerIteration;
unsigned int alignment = policy.GetAlignment();
KeystreamOperation operation = KeystreamOperation((IsAlignedOn(inString, alignment) * 2) | (int)IsAlignedOn(outString, alignment));
policy.OperateKeystream(operation, outString, inString, iterations);
inString += iterations * bytesPerIteration;
outString += iterations * bytesPerIteration;
length -= iterations * bytesPerIteration;
if (!length)
return;
}
size_t bufferByteSize = m_buffer.size();
size_t bufferIterations = bufferByteSize / bytesPerIteration;
while (length >= bufferByteSize)
{
policy.WriteKeystream(m_buffer, bufferIterations);
xorbuf(outString, inString, KeystreamBufferBegin(), bufferByteSize);
length -= bufferByteSize;
inString += bufferByteSize;
outString += bufferByteSize;
}
if (length > 0)
{
bufferByteSize = RoundUpToMultipleOf(length, bytesPerIteration);
bufferIterations = bufferByteSize / bytesPerIteration;
policy.WriteKeystream(KeystreamBufferEnd()-bufferByteSize, bufferIterations);
xorbuf(outString, inString, KeystreamBufferEnd()-bufferByteSize, length);
m_leftOver = bufferByteSize - length;
}
}
示例5: STDMIN
inline void AdditiveCipherTemplate<S>::ProcessData(byte *outString, const byte *inString, unsigned int length)
{
if (m_leftOver > 0)
{
unsigned int len = STDMIN(m_leftOver, length);
xorbuf(outString, inString, KeystreamBufferEnd()-m_leftOver, len);
length -= len;
m_leftOver -= len;
inString += len;
outString += len;
}
if (!length)
return;
assert(m_leftOver == 0);
PolicyInterface &policy = this->AccessPolicy();
unsigned int bytesPerIteration = policy.GetBytesPerIteration();
unsigned int alignment = policy.GetAlignment();
if (policy.CanOperateKeystream() && length >= bytesPerIteration && IsAlignedOn(outString, alignment))
{
if (IsAlignedOn(inString, alignment))
policy.OperateKeystream(XOR_KEYSTREAM, outString, inString, length / bytesPerIteration);
else
{
memcpy(outString, inString, length);
policy.OperateKeystream(XOR_KEYSTREAM_INPLACE, outString, outString, length / bytesPerIteration);
}
inString += length - length % bytesPerIteration;
outString += length - length % bytesPerIteration;
length %= bytesPerIteration;
if (!length)
return;
}
unsigned int bufferByteSize = GetBufferByteSize(policy);
unsigned int bufferIterations = policy.GetIterationsToBuffer();
while (length >= bufferByteSize)
{
policy.WriteKeystream(m_buffer, bufferIterations);
xorbuf(outString, inString, KeystreamBufferBegin(), bufferByteSize);
length -= bufferByteSize;
inString += bufferByteSize;
outString += bufferByteSize;
}
if (length > 0)
{
policy.WriteKeystream(m_buffer, bufferIterations);
xorbuf(outString, inString, KeystreamBufferBegin(), length);
m_leftOver = bytesPerIteration - length;
}
}
示例6: while
void SEAL::ProcessString(byte *outString, const byte *inString, unsigned int length)
{
while (length >= L/8-position)
{
xorbuf(outString, inString, buffer+position, L/8-position);
length -= L/8-position;
inString += L/8-position;
outString += L/8-position;
IncrementCounter();
}
xorbuf(outString, inString, buffer+position, length);
position += length;
}
示例7: BlockSize
void CBC_Encryption::ProcessBlocks(byte *outString, const byte *inString, size_t numberOfBlocks)
{
unsigned int blockSize = BlockSize();
xorbuf(m_register, inString, blockSize);
while (--numberOfBlocks)
{
m_cipher->ProcessBlock(m_register, outString);
inString += blockSize;
xorbuf(m_register, inString, outString, blockSize);
outString += blockSize;
}
m_cipher->ProcessBlock(m_register);
memcpy(outString, m_register, blockSize);
}
示例8: while
void SHA3::Update(const byte *input, size_t length)
{
size_t spaceLeft;
while (length >= (spaceLeft = r() - m_counter))
{
xorbuf(m_state.BytePtr() + m_counter, input, spaceLeft);
KeccakF1600(m_state);
input += spaceLeft;
length -= spaceLeft;
m_counter = 0;
}
xorbuf(m_state.BytePtr() + m_counter, input, length);
m_counter += (unsigned int)length;
}
示例9: xorbuf
void VDA_CBCNotPaddedDecryptor_3_2::NextPut(const byte *inString, unsigned int)
{
cipher.ProcessBlock(inString, buffer);
xorbuf(buffer, reg, S);
AttachedTransformation()->Put(buffer, S);
memcpy(reg, inString, S);
}
示例10: PBKDF2
int PBKDF2(byte* output, const byte* passwd, int pLen, const byte* salt,
int sLen, int iterations, int kLen, int hashType)
{
word32 i = 1;
int hLen;
int j, ret;
Hmac hmac;
byte buffer[MAX_DIGEST_SIZE];
if (hashType == MD5) {
hLen = MD5_DIGEST_SIZE;
}
else if (hashType == SHA) {
hLen = SHA_DIGEST_SIZE;
}
#ifndef NO_SHA256
else if (hashType == SHA256) {
hLen = SHA256_DIGEST_SIZE;
}
#endif
#ifdef CYASSL_SHA512
else if (hashType == SHA512) {
hLen = SHA512_DIGEST_SIZE;
}
#endif
else
return BAD_FUNC_ARG;
ret = HmacSetKey(&hmac, hashType, passwd, pLen);
if (ret != 0)
return ret;
while (kLen) {
int currentLen;
HmacUpdate(&hmac, salt, sLen);
/* encode i */
for (j = 0; j < 4; j++) {
byte b = (byte)(i >> ((3-j) * 8));
HmacUpdate(&hmac, &b, 1);
}
HmacFinal(&hmac, buffer);
currentLen = min(kLen, hLen);
XMEMCPY(output, buffer, currentLen);
for (j = 1; j < iterations; j++) {
HmacUpdate(&hmac, buffer, hLen);
HmacFinal(&hmac, buffer);
xorbuf(output, buffer, currentLen);
}
output += currentLen;
kLen -= currentLen;
i++;
}
return 0;
}
示例11: xorbuf
void CBCPaddedDecryptor::ProcessBuf()
{
cipher.ProcessBlock(buffer, temp);
xorbuf(temp, reg, S);
outQueue->Put(temp, S);
reg.swap(buffer);
counter = 0;
}
示例12: while
void OldRandomPool::IncorporateEntropy(const byte *input, size_t length)
{
size_t t;
while (length > (t = pool.size() - addPos))
{
xorbuf(pool+addPos, input, t);
input += t;
length -= t;
Stir();
}
if (length)
{
xorbuf(pool+addPos, input, length);
addPos += length;
getPos = pool.size(); // Force stir on get
}
}
示例13: CRYPTOPP_ASSERT
void EAX_Base::AuthenticateLastFooterBlock(byte *tag, size_t macSize)
{
CRYPTOPP_ASSERT(m_bufferedDataLength == 0);
MessageAuthenticationCode &mac = AccessMAC();
unsigned int blockSize = mac.TagSize();
mac.TruncatedFinal(m_buffer, macSize);
xorbuf(tag, m_buffer, m_buffer+blockSize, macSize);
}
示例14: assert
void CMAC_Base::Update(const byte *input, size_t length)
{
assert((input && length) || !(input || length));
if (!length)
return;
BlockCipher &cipher = AccessCipher();
unsigned int blockSize = cipher.BlockSize();
if (m_counter > 0)
{
const unsigned int len = UnsignedMin(blockSize - m_counter, length);
if (len)
{
xorbuf(m_reg+m_counter, input, len);
length -= len;
input += len;
m_counter += len;
}
if (m_counter == blockSize && length > 0)
{
cipher.ProcessBlock(m_reg);
m_counter = 0;
}
}
if (length > blockSize)
{
assert(m_counter == 0);
size_t leftOver = 1 + cipher.AdvancedProcessBlocks(m_reg, input, m_reg, length-1, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
input += (length - leftOver);
length = leftOver;
}
if (length > 0)
{
assert(m_counter + length <= blockSize);
xorbuf(m_reg+m_counter, input, length);
m_counter += (unsigned int)length;
}
assert(m_counter > 0);
}
示例15: while
void RandomPool::Put(const byte *inString, unsigned int length)
{
unsigned t;
while (length > (t = pool.size - addPos))
{
xorbuf(pool+addPos, inString, t);
inString += t;
length -= t;
Stir();
}
if (length)
{
xorbuf(pool+addPos, inString, length);
addPos += length;
getPos = pool.size; // Force stir on get
}
}