Cleared UBsan errors
parent
b54e637896
commit
d19790bbca
84
filters.cpp
84
filters.cpp
|
|
@ -106,6 +106,9 @@ void Filter::PropagateInitialize(const NameValuePairs ¶meters, int propagati
|
||||||
|
|
||||||
size_t Filter::OutputModifiable(int outputSite, byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel)
|
size_t Filter::OutputModifiable(int outputSite, byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
if (messageEnd)
|
if (messageEnd)
|
||||||
messageEnd--;
|
messageEnd--;
|
||||||
size_t result = AttachedTransformation()->ChannelPutModifiable2(channel, inString, length, messageEnd, blocking);
|
size_t result = AttachedTransformation()->ChannelPutModifiable2(channel, inString, length, messageEnd, blocking);
|
||||||
|
|
@ -115,6 +118,9 @@ size_t Filter::OutputModifiable(int outputSite, byte *inString, size_t length, i
|
||||||
|
|
||||||
size_t Filter::Output(int outputSite, const byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel)
|
size_t Filter::Output(int outputSite, const byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
if (messageEnd)
|
if (messageEnd)
|
||||||
messageEnd--;
|
messageEnd--;
|
||||||
size_t result = AttachedTransformation()->ChannelPut2(channel, inString, length, messageEnd, blocking);
|
size_t result = AttachedTransformation()->ChannelPut2(channel, inString, length, messageEnd, blocking);
|
||||||
|
|
@ -274,6 +280,8 @@ byte *FilterWithBufferedInput::BlockQueue::GetContigousBlocks(size_t &numberOfBy
|
||||||
|
|
||||||
size_t FilterWithBufferedInput::BlockQueue::GetAll(byte *outString)
|
size_t FilterWithBufferedInput::BlockQueue::GetAll(byte *outString)
|
||||||
{
|
{
|
||||||
|
if (!outString) return 0;
|
||||||
|
|
||||||
size_t size = m_size;
|
size_t size = m_size;
|
||||||
size_t numberOfBytes = m_maxBlocks*m_blockSize;
|
size_t numberOfBytes = m_maxBlocks*m_blockSize;
|
||||||
const byte *ptr = GetContigousBlocks(numberOfBytes);
|
const byte *ptr = GetContigousBlocks(numberOfBytes);
|
||||||
|
|
@ -283,8 +291,11 @@ size_t FilterWithBufferedInput::BlockQueue::GetAll(byte *outString)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilterWithBufferedInput::BlockQueue::Put(const byte *inString, size_t length)
|
size_t FilterWithBufferedInput::BlockQueue::Put(const byte *inString, size_t length)
|
||||||
{
|
{
|
||||||
|
if (!inString || !length) return length;
|
||||||
|
if (!m_buffer.data()) return length;
|
||||||
|
|
||||||
assert(m_size + length <= m_buffer.size());
|
assert(m_size + length <= m_buffer.size());
|
||||||
byte *end = (m_size < size_t(m_buffer.end()-m_begin)) ? m_begin + m_size : m_begin + m_size - m_buffer.size();
|
byte *end = (m_size < size_t(m_buffer.end()-m_begin)) ? m_begin + m_size : m_begin + m_size - m_buffer.size();
|
||||||
size_t len = STDMIN(length, size_t(m_buffer.end()-end));
|
size_t len = STDMIN(length, size_t(m_buffer.end()-end));
|
||||||
|
|
@ -292,6 +303,7 @@ void FilterWithBufferedInput::BlockQueue::Put(const byte *inString, size_t lengt
|
||||||
if (len < length)
|
if (len < length)
|
||||||
memcpy(m_buffer, inString+len, length-len);
|
memcpy(m_buffer, inString+len, length-len);
|
||||||
m_size += length;
|
m_size += length;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FilterWithBufferedInput::FilterWithBufferedInput(BufferedTransformation *attachment)
|
FilterWithBufferedInput::FilterWithBufferedInput(BufferedTransformation *attachment)
|
||||||
|
|
@ -332,6 +344,9 @@ bool FilterWithBufferedInput::IsolatedFlush(bool hardFlush, bool blocking)
|
||||||
|
|
||||||
size_t FilterWithBufferedInput::PutMaybeModifiable(byte *inString, size_t length, int messageEnd, bool blocking, bool modifiable)
|
size_t FilterWithBufferedInput::PutMaybeModifiable(byte *inString, size_t length, int messageEnd, bool blocking, bool modifiable)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
if (!blocking)
|
if (!blocking)
|
||||||
throw BlockingInputOnly("FilterWithBufferedInput");
|
throw BlockingInputOnly("FilterWithBufferedInput");
|
||||||
|
|
||||||
|
|
@ -440,6 +455,9 @@ void FilterWithBufferedInput::ForceNextPut()
|
||||||
|
|
||||||
void FilterWithBufferedInput::NextPutMultiple(const byte *inString, size_t length)
|
void FilterWithBufferedInput::NextPutMultiple(const byte *inString, size_t length)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
assert(m_blockSize > 1); // m_blockSize = 1 should always override this function
|
assert(m_blockSize > 1); // m_blockSize = 1 should always override this function
|
||||||
while (length > 0)
|
while (length > 0)
|
||||||
{
|
{
|
||||||
|
|
@ -514,10 +532,13 @@ size_t RandomNumberSink::Put2(const byte *begin, size_t length, int messageEnd,
|
||||||
|
|
||||||
size_t ArraySink::Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
|
size_t ArraySink::Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
|
||||||
{
|
{
|
||||||
if(!begin || !length) return length;
|
if (!begin || !length) return length;
|
||||||
|
if (!m_buf) return length;
|
||||||
|
|
||||||
if (m_buf+m_total != begin)
|
if (m_buf+m_total != begin)
|
||||||
memcpy(m_buf+m_total, begin, STDMIN(length, SaturatingSubtract(m_size, m_total)));
|
memcpy(m_buf+m_total, begin, STDMIN(length, SaturatingSubtract(m_size, m_total)));
|
||||||
m_total += length;
|
m_total += length;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -539,6 +560,9 @@ void ArraySink::IsolatedInitialize(const NameValuePairs ¶meters)
|
||||||
|
|
||||||
size_t ArrayXorSink::Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
|
size_t ArrayXorSink::Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
|
||||||
{
|
{
|
||||||
|
if (!begin || !length) return length;
|
||||||
|
if (!m_buf) return length;
|
||||||
|
|
||||||
xorbuf(m_buf+m_total, begin, STDMIN(length, SaturatingSubtract(m_size, m_total)));
|
xorbuf(m_buf+m_total, begin, STDMIN(length, SaturatingSubtract(m_size, m_total)));
|
||||||
m_total += length;
|
m_total += length;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -588,14 +612,15 @@ void StreamTransformationFilter::InitializeDerivedAndReturnNewSizes(const NameVa
|
||||||
|
|
||||||
void StreamTransformationFilter::FirstPut(const byte *inString)
|
void StreamTransformationFilter::FirstPut(const byte *inString)
|
||||||
{
|
{
|
||||||
|
assert(inString);
|
||||||
m_optimalBufferSize = m_cipher.OptimalBlockSize();
|
m_optimalBufferSize = m_cipher.OptimalBlockSize();
|
||||||
m_optimalBufferSize = (unsigned int)STDMAX(m_optimalBufferSize, RoundDownToMultipleOf(4096U, m_optimalBufferSize));
|
m_optimalBufferSize = (unsigned int)STDMAX(m_optimalBufferSize, RoundDownToMultipleOf(4096U, m_optimalBufferSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamTransformationFilter::NextPutMultiple(const byte *inString, size_t length)
|
void StreamTransformationFilter::NextPutMultiple(const byte *inString, size_t length)
|
||||||
{
|
{
|
||||||
if (!length)
|
assert((inString && length) || (!inString && !length));
|
||||||
return;
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
size_t s = m_cipher.MandatoryBlockSize();
|
size_t s = m_cipher.MandatoryBlockSize();
|
||||||
|
|
||||||
|
|
@ -610,7 +635,9 @@ void StreamTransformationFilter::NextPutMultiple(const byte *inString, size_t le
|
||||||
len = RoundDownToMultipleOf(len, s);
|
len = RoundDownToMultipleOf(len, s);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
len = length;
|
len = length;
|
||||||
|
}
|
||||||
m_cipher.ProcessString(space, inString, len);
|
m_cipher.ProcessString(space, inString, len);
|
||||||
AttachedTransformation()->PutModifiable(space, len);
|
AttachedTransformation()->PutModifiable(space, len);
|
||||||
inString += len;
|
inString += len;
|
||||||
|
|
@ -621,12 +648,18 @@ void StreamTransformationFilter::NextPutMultiple(const byte *inString, size_t le
|
||||||
|
|
||||||
void StreamTransformationFilter::NextPutModifiable(byte *inString, size_t length)
|
void StreamTransformationFilter::NextPutModifiable(byte *inString, size_t length)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
m_cipher.ProcessString(inString, length);
|
m_cipher.ProcessString(inString, length);
|
||||||
AttachedTransformation()->PutModifiable(inString, length);
|
AttachedTransformation()->PutModifiable(inString, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamTransformationFilter::LastPut(const byte *inString, size_t length)
|
void StreamTransformationFilter::LastPut(const byte *inString, size_t length)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
byte *space = NULL;
|
byte *space = NULL;
|
||||||
|
|
||||||
switch (m_padding)
|
switch (m_padding)
|
||||||
|
|
@ -643,7 +676,8 @@ void StreamTransformationFilter::LastPut(const byte *inString, size_t length)
|
||||||
// do padding
|
// do padding
|
||||||
size_t blockSize = STDMAX(minLastBlockSize, (size_t)m_cipher.MandatoryBlockSize());
|
size_t blockSize = STDMAX(minLastBlockSize, (size_t)m_cipher.MandatoryBlockSize());
|
||||||
space = HelpCreatePutSpace(*AttachedTransformation(), DEFAULT_CHANNEL, blockSize);
|
space = HelpCreatePutSpace(*AttachedTransformation(), DEFAULT_CHANNEL, blockSize);
|
||||||
memcpy(space, inString, length);
|
if (inString && length)
|
||||||
|
memcpy(space, inString, length);
|
||||||
memset(space + length, 0, blockSize - length);
|
memset(space + length, 0, blockSize - length);
|
||||||
m_cipher.ProcessLastBlock(space, space, blockSize);
|
m_cipher.ProcessLastBlock(space, space, blockSize);
|
||||||
AttachedTransformation()->Put(space, blockSize);
|
AttachedTransformation()->Put(space, blockSize);
|
||||||
|
|
@ -674,7 +708,8 @@ void StreamTransformationFilter::LastPut(const byte *inString, size_t length)
|
||||||
if (m_cipher.IsForwardTransformation())
|
if (m_cipher.IsForwardTransformation())
|
||||||
{
|
{
|
||||||
assert(length < s);
|
assert(length < s);
|
||||||
memcpy(space, inString, length);
|
if (inString && length)
|
||||||
|
memcpy(space, inString, length);
|
||||||
if (m_padding == PKCS_PADDING)
|
if (m_padding == PKCS_PADDING)
|
||||||
{
|
{
|
||||||
assert(s < 256);
|
assert(s < 256);
|
||||||
|
|
@ -697,7 +732,7 @@ void StreamTransformationFilter::LastPut(const byte *inString, size_t length)
|
||||||
if (m_padding == PKCS_PADDING)
|
if (m_padding == PKCS_PADDING)
|
||||||
{
|
{
|
||||||
byte pad = space[s-1];
|
byte pad = space[s-1];
|
||||||
if (pad < 1 || pad > s || std::find_if(space+s-pad, space+s, std::bind2nd(std::not_equal_to<byte>(), pad)) != space+s)
|
if (pad < 1 || pad > s || std::find_if (space+s-pad, space+s, std::bind2nd(std::not_equal_to<byte>(), pad)) != space+s)
|
||||||
throw InvalidCiphertext("StreamTransformationFilter: invalid PKCS #7 block padding found");
|
throw InvalidCiphertext("StreamTransformationFilter: invalid PKCS #7 block padding found");
|
||||||
length = s-pad;
|
length = s-pad;
|
||||||
}
|
}
|
||||||
|
|
@ -735,6 +770,9 @@ void HashFilter::IsolatedInitialize(const NameValuePairs ¶meters)
|
||||||
|
|
||||||
size_t HashFilter::Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
|
size_t HashFilter::Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
FILTER_BEGIN;
|
FILTER_BEGIN;
|
||||||
if (m_putMessage)
|
if (m_putMessage)
|
||||||
FILTER_OUTPUT3(1, 0, inString, length, 0, m_messagePutChannel);
|
FILTER_OUTPUT3(1, 0, inString, length, 0, m_messagePutChannel);
|
||||||
|
|
@ -773,10 +811,14 @@ void HashVerificationFilter::InitializeDerivedAndReturnNewSizes(const NameValueP
|
||||||
|
|
||||||
void HashVerificationFilter::FirstPut(const byte *inString)
|
void HashVerificationFilter::FirstPut(const byte *inString)
|
||||||
{
|
{
|
||||||
|
assert(inString);
|
||||||
|
|
||||||
if (m_flags & HASH_AT_BEGIN)
|
if (m_flags & HASH_AT_BEGIN)
|
||||||
{
|
{
|
||||||
m_expectedHash.New(m_digestSize);
|
m_expectedHash.New(m_digestSize);
|
||||||
memcpy(m_expectedHash, inString, m_expectedHash.size());
|
|
||||||
|
if(inString)
|
||||||
|
memcpy(m_expectedHash, inString, m_expectedHash.size());
|
||||||
if (m_flags & PUT_HASH)
|
if (m_flags & PUT_HASH)
|
||||||
AttachedTransformation()->Put(inString, m_expectedHash.size());
|
AttachedTransformation()->Put(inString, m_expectedHash.size());
|
||||||
}
|
}
|
||||||
|
|
@ -784,6 +826,9 @@ void HashVerificationFilter::FirstPut(const byte *inString)
|
||||||
|
|
||||||
void HashVerificationFilter::NextPutMultiple(const byte *inString, size_t length)
|
void HashVerificationFilter::NextPutMultiple(const byte *inString, size_t length)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
m_hashModule.Update(inString, length);
|
m_hashModule.Update(inString, length);
|
||||||
if (m_flags & PUT_MESSAGE)
|
if (m_flags & PUT_MESSAGE)
|
||||||
AttachedTransformation()->Put(inString, length);
|
AttachedTransformation()->Put(inString, length);
|
||||||
|
|
@ -791,6 +836,9 @@ void HashVerificationFilter::NextPutMultiple(const byte *inString, size_t length
|
||||||
|
|
||||||
void HashVerificationFilter::LastPut(const byte *inString, size_t length)
|
void HashVerificationFilter::LastPut(const byte *inString, size_t length)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
if (m_flags & HASH_AT_BEGIN)
|
if (m_flags & HASH_AT_BEGIN)
|
||||||
{
|
{
|
||||||
assert(length == 0);
|
assert(length == 0);
|
||||||
|
|
@ -850,6 +898,9 @@ size_t AuthenticatedEncryptionFilter::ChannelPut2(const std::string &channel, co
|
||||||
|
|
||||||
void AuthenticatedEncryptionFilter::LastPut(const byte *inString, size_t length)
|
void AuthenticatedEncryptionFilter::LastPut(const byte *inString, size_t length)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
StreamTransformationFilter::LastPut(inString, length);
|
StreamTransformationFilter::LastPut(inString, length);
|
||||||
m_hf.MessageEnd();
|
m_hf.MessageEnd();
|
||||||
}
|
}
|
||||||
|
|
@ -905,16 +956,23 @@ size_t AuthenticatedDecryptionFilter::ChannelPut2(const std::string &channel, co
|
||||||
|
|
||||||
void AuthenticatedDecryptionFilter::FirstPut(const byte *inString)
|
void AuthenticatedDecryptionFilter::FirstPut(const byte *inString)
|
||||||
{
|
{
|
||||||
|
assert(inString && length);
|
||||||
m_hashVerifier.Put(inString, m_firstSize);
|
m_hashVerifier.Put(inString, m_firstSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuthenticatedDecryptionFilter::NextPutMultiple(const byte *inString, size_t length)
|
void AuthenticatedDecryptionFilter::NextPutMultiple(const byte *inString, size_t length)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
m_streamFilter.Put(inString, length);
|
m_streamFilter.Put(inString, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuthenticatedDecryptionFilter::LastPut(const byte *inString, size_t length)
|
void AuthenticatedDecryptionFilter::LastPut(const byte *inString, size_t length)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
m_streamFilter.MessageEnd();
|
m_streamFilter.MessageEnd();
|
||||||
m_hashVerifier.PutMessageEnd(inString, length);
|
m_hashVerifier.PutMessageEnd(inString, length);
|
||||||
}
|
}
|
||||||
|
|
@ -929,6 +987,9 @@ void SignerFilter::IsolatedInitialize(const NameValuePairs ¶meters)
|
||||||
|
|
||||||
size_t SignerFilter::Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
|
size_t SignerFilter::Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
FILTER_BEGIN;
|
FILTER_BEGIN;
|
||||||
m_messageAccumulator->Update(inString, length);
|
m_messageAccumulator->Update(inString, length);
|
||||||
if (m_putMessage)
|
if (m_putMessage)
|
||||||
|
|
@ -964,6 +1025,7 @@ void SignatureVerificationFilter::InitializeDerivedAndReturnNewSizes(const NameV
|
||||||
|
|
||||||
void SignatureVerificationFilter::FirstPut(const byte *inString)
|
void SignatureVerificationFilter::FirstPut(const byte *inString)
|
||||||
{
|
{
|
||||||
|
assert(inString);
|
||||||
if (m_flags & SIGNATURE_AT_BEGIN)
|
if (m_flags & SIGNATURE_AT_BEGIN)
|
||||||
{
|
{
|
||||||
if (m_verifier.SignatureUpfront())
|
if (m_verifier.SignatureUpfront())
|
||||||
|
|
@ -985,6 +1047,9 @@ void SignatureVerificationFilter::FirstPut(const byte *inString)
|
||||||
|
|
||||||
void SignatureVerificationFilter::NextPutMultiple(const byte *inString, size_t length)
|
void SignatureVerificationFilter::NextPutMultiple(const byte *inString, size_t length)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
m_messageAccumulator->Update(inString, length);
|
m_messageAccumulator->Update(inString, length);
|
||||||
if (m_flags & PUT_MESSAGE)
|
if (m_flags & PUT_MESSAGE)
|
||||||
AttachedTransformation()->Put(inString, length);
|
AttachedTransformation()->Put(inString, length);
|
||||||
|
|
@ -992,6 +1057,9 @@ void SignatureVerificationFilter::NextPutMultiple(const byte *inString, size_t l
|
||||||
|
|
||||||
void SignatureVerificationFilter::LastPut(const byte *inString, size_t length)
|
void SignatureVerificationFilter::LastPut(const byte *inString, size_t length)
|
||||||
{
|
{
|
||||||
|
assert((inString && length) || (!inString && !length));
|
||||||
|
if (inString == NULL) { length = 0; }
|
||||||
|
|
||||||
if (m_flags & SIGNATURE_AT_BEGIN)
|
if (m_flags & SIGNATURE_AT_BEGIN)
|
||||||
{
|
{
|
||||||
assert(length == 0);
|
assert(length == 0);
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@ protected:
|
||||||
byte *GetBlock();
|
byte *GetBlock();
|
||||||
byte *GetContigousBlocks(size_t &numberOfBytes);
|
byte *GetContigousBlocks(size_t &numberOfBytes);
|
||||||
size_t GetAll(byte *outString);
|
size_t GetAll(byte *outString);
|
||||||
void Put(const byte *inString, size_t length);
|
size_t Put(const byte *inString, size_t length);
|
||||||
size_t CurrentSize() const {return m_size;}
|
size_t CurrentSize() const {return m_size;}
|
||||||
size_t MaxSize() const {return m_buffer.size();}
|
size_t MaxSize() const {return m_buffer.size();}
|
||||||
|
|
||||||
|
|
|
||||||
12
modes.cpp
12
modes.cpp
|
|
@ -29,7 +29,7 @@ void CFB_ModePolicy::Iterate(byte *output, const byte *input, CipherDir dir, siz
|
||||||
assert(m_cipher->IsForwardTransformation()); // CFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
|
assert(m_cipher->IsForwardTransformation()); // CFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
|
||||||
assert(m_feedbackSize == BlockSize());
|
assert(m_feedbackSize == BlockSize());
|
||||||
|
|
||||||
unsigned int s = BlockSize();
|
const unsigned int s = BlockSize();
|
||||||
if (dir == ENCRYPTION)
|
if (dir == ENCRYPTION)
|
||||||
{
|
{
|
||||||
m_cipher->ProcessAndXorBlock(m_register, input, output);
|
m_cipher->ProcessAndXorBlock(m_register, input, output);
|
||||||
|
|
@ -38,10 +38,10 @@ void CFB_ModePolicy::Iterate(byte *output, const byte *input, CipherDir dir, siz
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memcpy(m_temp, input+(iterationCount-1)*s, s); // make copy first in case of in-place decryption
|
memcpy_s(m_temp, m_temp.size(), input+(iterationCount-1)*s, s); // make copy first in case of in-place decryption
|
||||||
m_cipher->AdvancedProcessBlocks(input, input+s, output+s, (iterationCount-1)*s, BlockTransformation::BT_ReverseDirection);
|
m_cipher->AdvancedProcessBlocks(input, input+s, output+s, (iterationCount-1)*s, BlockTransformation::BT_ReverseDirection);
|
||||||
m_cipher->ProcessAndXorBlock(m_register, input, output);
|
m_cipher->ProcessAndXorBlock(m_register, input, output);
|
||||||
memcpy(m_register, m_temp, s);
|
memcpy_s(m_register, m_register.size(), m_temp, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,8 +49,10 @@ void CFB_ModePolicy::TransformRegister()
|
||||||
{
|
{
|
||||||
assert(m_cipher->IsForwardTransformation()); // CFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
|
assert(m_cipher->IsForwardTransformation()); // CFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt
|
||||||
m_cipher->ProcessBlock(m_register, m_temp);
|
m_cipher->ProcessBlock(m_register, m_temp);
|
||||||
unsigned int updateSize = BlockSize()-m_feedbackSize;
|
const unsigned int updateSize = BlockSize()-m_feedbackSize;
|
||||||
memmove_s(m_register, m_register.size(), m_register+m_feedbackSize, updateSize);
|
|
||||||
|
if(updateSize)
|
||||||
|
memmove_s(m_register, m_register.size(), m_register+m_feedbackSize, updateSize);
|
||||||
memcpy_s(m_register+updateSize, m_register.size()-updateSize, m_temp, m_feedbackSize);
|
memcpy_s(m_register+updateSize, m_register.size()-updateSize, m_temp, m_feedbackSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue