Update modes.cpp
parent
caec8f98e2
commit
b8f42d784d
65
modes.cpp
65
modes.cpp
|
|
@ -201,31 +201,33 @@ void CBC_CTS_Encryption::ProcessLastBlock(byte *outString, const byte *inString,
|
||||||
// steal from IV
|
// steal from IV
|
||||||
memcpy(outString, m_register, length);
|
memcpy(outString, m_register, length);
|
||||||
outString = m_stolenIV;
|
outString = m_stolenIV;
|
||||||
|
|
||||||
|
// output last full ciphertext block
|
||||||
|
xorbuf(m_register, inString, length);
|
||||||
|
m_cipher->ProcessBlock(m_register);
|
||||||
|
memcpy(outString, m_register, BlockSize());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// steal from next to last block
|
// steal from next to last block
|
||||||
xorbuf(m_register, inString, BlockSize());
|
xorbuf(m_register, inString, BlockSize());
|
||||||
m_cipher->ProcessBlock(m_register);
|
m_cipher->ProcessBlock(m_register);
|
||||||
if (inString == outString)
|
|
||||||
{
|
|
||||||
length -= BlockSize();
|
length -= BlockSize();
|
||||||
memmove(outString, inString+BlockSize(), length);
|
|
||||||
memcpy(outString+BlockSize(), m_register, length);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
inString += BlockSize();
|
|
||||||
length -= BlockSize();
|
|
||||||
memcpy(outString+BlockSize(), m_register, length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// output last full ciphertext block
|
// output last full ciphertext block
|
||||||
xorbuf(m_register, inString, length);
|
if (inString == outString) {
|
||||||
|
memcpy(m_buffer, outString+BlockSize(), length);
|
||||||
|
memcpy(outString+BlockSize(), m_register, length);
|
||||||
|
xorbuf(m_register, m_buffer, length);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
memcpy(outString+BlockSize(), m_register, length);
|
||||||
|
xorbuf(m_register, inString+BlockSize(), length);
|
||||||
|
}
|
||||||
m_cipher->ProcessBlock(m_register);
|
m_cipher->ProcessBlock(m_register);
|
||||||
memcpy(outString, m_register, BlockSize());
|
memcpy(outString, m_register, BlockSize());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46
|
// Thanks to Zireael, http://github.com/weidai11/cryptopp/pull/46
|
||||||
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
|
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
|
||||||
|
|
@ -259,42 +261,37 @@ void CBC_CTS_Decryption::ProcessLastBlock(byte *outString, const byte *inString,
|
||||||
{
|
{
|
||||||
pn = inString;
|
pn = inString;
|
||||||
pn1 = m_register;
|
pn1 = m_register;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pn = inString + BlockSize();
|
|
||||||
pn1 = inString;
|
|
||||||
length -= BlockSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// decrypt last partial plaintext block
|
// decrypt last partial plaintext block
|
||||||
memcpy(m_temp, pn1, BlockSize());
|
memcpy(m_temp, pn1, BlockSize());
|
||||||
m_cipher->ProcessBlock(m_temp);
|
m_cipher->ProcessBlock(m_temp);
|
||||||
xorbuf(m_temp, pn, length);
|
xorbuf(m_temp, pn, length);
|
||||||
|
|
||||||
if (stealIV)
|
|
||||||
memcpy(outString, m_temp, length);
|
memcpy(outString, m_temp, length);
|
||||||
else
|
|
||||||
{
|
|
||||||
if (inString == outString)
|
|
||||||
{
|
|
||||||
memmove(outString, inString+BlockSize(), length);
|
|
||||||
memcpy(outString+BlockSize(), m_temp, length);
|
|
||||||
// decrypt next to last plaintext block
|
|
||||||
memcpy(m_temp, pn1, length);
|
|
||||||
m_cipher->ProcessBlock(m_temp);
|
|
||||||
xorbuf(outString, m_temp, m_register, BlockSize());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memcpy(outString+BlockSize(), m_temp, length);
|
length -= BlockSize();
|
||||||
|
|
||||||
|
// decrypt last partial plaintext block
|
||||||
|
memcpy(m_temp, inString, BlockSize());
|
||||||
|
m_cipher->ProcessBlock(m_temp);
|
||||||
|
xorbuf(m_temp, inString+BlockSize(), length);
|
||||||
|
|
||||||
// decrypt next to last plaintext block
|
// decrypt next to last plaintext block
|
||||||
memcpy(m_temp, pn, length);
|
if (inString == outString) {
|
||||||
|
memcpy(m_buffer, outString+BlockSize(), length);
|
||||||
|
memcpy(outString+BlockSize(), m_temp, length);
|
||||||
|
memcpy(m_temp, m_buffer, length);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
memcpy(outString+BlockSize(), m_temp, length);
|
||||||
|
memcpy(m_temp, inString+BlockSize(), length);
|
||||||
|
}
|
||||||
m_cipher->ProcessBlock(m_temp);
|
m_cipher->ProcessBlock(m_temp);
|
||||||
xorbuf(outString, m_temp, m_register, BlockSize());
|
xorbuf(outString, m_temp, m_register, BlockSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
NAMESPACE_END
|
NAMESPACE_END
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue