From 46a9323d19632f74d0d091b689ae3f12c3209615 Mon Sep 17 00:00:00 2001 From: danielweck Date: Tue, 24 Jan 2017 16:40:26 +0000 Subject: [PATCH] patched CryptoPP Crypto++ to add support for AES-256-CBC with W3C padding scheme (based on https://github.com/readium/readium-lcp-client/pull/26 ) --- filters.cpp | 8 ++++++++ filters.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/filters.cpp b/filters.cpp index 28d2276c..5691c550 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 2e6b8c11..22ef4c2c 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 };