fix bug #185
parent
fb206e53d7
commit
aaed9ae803
21
modes.cpp
21
modes.cpp
|
|
@ -207,10 +207,19 @@ void CBC_CTS_Encryption::ProcessLastBlock(byte *outString, const byte *inString,
|
||||||
// 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();
|
||||||
|
memcpy(outString, inString+BlockSize(), length);
|
||||||
|
memcpy(outString+BlockSize(), m_register, length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
inString += BlockSize();
|
inString += BlockSize();
|
||||||
length -= BlockSize();
|
length -= BlockSize();
|
||||||
memcpy(outString+BlockSize(), m_register, length);
|
memcpy(outString+BlockSize(), m_register, length);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// output last full ciphertext block
|
// output last full ciphertext block
|
||||||
xorbuf(m_register, inString, length);
|
xorbuf(m_register, inString, length);
|
||||||
|
|
@ -266,6 +275,17 @@ void CBC_CTS_Decryption::ProcessLastBlock(byte *outString, const byte *inString,
|
||||||
if (stealIV)
|
if (stealIV)
|
||||||
memcpy(outString, m_temp, length);
|
memcpy(outString, m_temp, length);
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (inString == outString)
|
||||||
|
{
|
||||||
|
memcpy(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
|
||||||
{
|
{
|
||||||
memcpy(outString+BlockSize(), m_temp, length);
|
memcpy(outString+BlockSize(), m_temp, length);
|
||||||
// decrypt next to last plaintext block
|
// decrypt next to last plaintext block
|
||||||
|
|
@ -273,6 +293,7 @@ void CBC_CTS_Decryption::ProcessLastBlock(byte *outString, const byte *inString,
|
||||||
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