pull/186/head
Berendea Nicolae 2016-06-13 01:02:22 +03:00 committed by GitHub
parent fb206e53d7
commit aaed9ae803
1 changed files with 29 additions and 8 deletions

View File

@ -207,9 +207,18 @@ 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);
inString += BlockSize(); if (inString == outString)
length -= BlockSize(); {
memcpy(outString+BlockSize(), m_register, length); length -= BlockSize();
memcpy(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
@ -267,11 +276,23 @@ void CBC_CTS_Decryption::ProcessLastBlock(byte *outString, const byte *inString,
memcpy(outString, m_temp, length); memcpy(outString, m_temp, length);
else else
{ {
memcpy(outString+BlockSize(), m_temp, length); if (inString == outString)
// decrypt next to last plaintext block {
memcpy(m_temp, pn, length); memcpy(outString, inString+BlockSize(), length);
m_cipher->ProcessBlock(m_temp); memcpy(outString+BlockSize(), m_temp, length);
xorbuf(outString, m_temp, m_register, BlockSize()); // 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);
// decrypt next to last plaintext block
memcpy(m_temp, pn, length);
m_cipher->ProcessBlock(m_temp);
xorbuf(outString, m_temp, m_register, BlockSize());
}
} }
} }