diff --git a/filters.cpp b/filters.cpp index bd2e44e5..95654b47 100644 --- a/filters.cpp +++ b/filters.cpp @@ -701,6 +701,7 @@ void StreamTransformationFilter::LastPut(const byte *inString, size_t length) case PKCS_PADDING: case ONE_AND_ZEROS_PADDING: + case W3C_PADDING: unsigned int s; s = m_cipher.MandatoryBlockSize(); 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"); 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 { while (length > 1 && space[length-1] == 0) diff --git a/filters.h b/filters.h index 574e27a9..8851dfdb 100644 --- a/filters.h +++ b/filters.h @@ -480,6 +480,8 @@ struct BlockPaddingSchemeDef PKCS_PADDING, //! \brief 1 and 0's padding added to a block 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 DEFAULT_PADDING };