Add W3C_PADDING to encryption path

This commit is contained in:
Jeffrey Walton 2017-02-06 08:09:09 -05:00
parent 061f272da3
commit 8e088b4865
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
2 changed files with 9 additions and 3 deletions

View File

@ -700,8 +700,8 @@ void StreamTransformationFilter::LastPut(const byte *inString, size_t length)
break; break;
case PKCS_PADDING: case PKCS_PADDING:
case ONE_AND_ZEROS_PADDING:
case W3C_PADDING: case W3C_PADDING:
case ONE_AND_ZEROS_PADDING:
unsigned int s; unsigned int s;
s = m_cipher.MandatoryBlockSize(); s = m_cipher.MandatoryBlockSize();
CRYPTOPP_ASSERT(s > 1); CRYPTOPP_ASSERT(s > 1);
@ -713,9 +713,15 @@ void StreamTransformationFilter::LastPut(const byte *inString, size_t length)
if (m_padding == PKCS_PADDING) if (m_padding == PKCS_PADDING)
{ {
CRYPTOPP_ASSERT(s < 256); CRYPTOPP_ASSERT(s < 256);
byte pad = byte(s-length); byte pad = static_cast<byte>(s-length);
memset(space+length, pad, s-length); memset(space+length, pad, s-length);
} }
else if (m_padding == W3C_PADDING)
{
CRYPTOPP_ASSERT(s < 256);
memset(space+length, 0, s-length-1);
space[s-1] = static_cast<byte>(s-length);
}
else else
{ {
space[length] = 0x80; space[length] = 0x80;

View File

@ -480,7 +480,7 @@ 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 //! \brief W3C padding added to a block
W3C_PADDING, W3C_PADDING,
//! \brief Default padding scheme //! \brief Default padding scheme
DEFAULT_PADDING DEFAULT_PADDING