Merge pull request #368 from edrlab/aes256cbc-w3c-padding-scheme

Support for AES-256-CBC with W3C padding scheme ( http://www.w3.org/2001/04/xmlenc#aes256-cbc )
pull/378/head
Jeffrey Walton 2017-02-06 03:53:25 -05:00 committed by GitHub
commit 061f272da3
2 changed files with 10 additions and 0 deletions

View File

@ -701,6 +701,7 @@ void StreamTransformationFilter::LastPut(const byte *inString, size_t length)
case PKCS_PADDING: case PKCS_PADDING:
case ONE_AND_ZEROS_PADDING: case ONE_AND_ZEROS_PADDING:
case W3C_PADDING:
unsigned int s; unsigned int s;
s = m_cipher.MandatoryBlockSize(); s = m_cipher.MandatoryBlockSize();
CRYPTOPP_ASSERT(s > 1); CRYPTOPP_ASSERT(s > 1);
@ -735,6 +736,13 @@ void StreamTransformationFilter::LastPut(const byte *inString, size_t length)
throw InvalidCiphertext("StreamTransformationFilter: invalid PKCS #7 block padding found"); throw InvalidCiphertext("StreamTransformationFilter: invalid PKCS #7 block padding found");
length = s-pad; length = s-pad;
} }
else if (m_padding == W3C_PADDING)
{
byte pad = space[s - 1];
if (pad < 1 || pad > s)
throw InvalidCiphertext("StreamTransformationFilter: invalid W3C block padding found");
length = s - pad;
}
else else
{ {
while (length > 1 && space[length-1] == 0) while (length > 1 && space[length-1] == 0)

View File

@ -480,6 +480,8 @@ struct BlockPaddingSchemeDef
PKCS_PADDING, PKCS_PADDING,
//! \brief 1 and 0's padding added to a block //! \brief 1 and 0's padding added to a block
ONE_AND_ZEROS_PADDING, ONE_AND_ZEROS_PADDING,
//! \brief [Random bytes (0 ~ N-2) and padding's length (N-1)]'s padding to a block
W3C_PADDING,
//! \brief Default padding scheme //! \brief Default padding scheme
DEFAULT_PADDING DEFAULT_PADDING
}; };