diff options
author | Jeffrey Walton <noloader@gmail.com> | 2019-10-13 04:31:39 -0400 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2019-10-13 04:31:39 -0400 |
commit | 9c711221c68c0366ed7549bb6c5e0ed38b25d352 (patch) | |
tree | 6e1789c33d05aecf44e9890afefedddfe4f78f8d | |
parent | 97aa173507c125ff2cc48c4ef30f776e6193ea47 (diff) | |
download | cryptopp-git-9c711221c68c0366ed7549bb6c5e0ed38b25d352.tar.gz |
Fix XTS GetValidKeyLength (GH #891)
-rw-r--r-- | xts.cpp | 7 | ||||
-rw-r--r-- | xts.h | 7 |
2 files changed, 11 insertions, 3 deletions
@@ -206,9 +206,16 @@ ANONYMOUS_NAMESPACE_END NAMESPACE_BEGIN(CryptoPP)
+void XTS_ModeBase::ThrowIfInvalidKeyLength(size_t length)
+{
+ if (!AccessBlockCipher().IsValidKeyLength((length+1)/2))
+ throw InvalidKeyLength(AlgorithmName(), length);
+}
+
void XTS_ModeBase::SetKey(const byte *key, size_t length, const NameValuePairs ¶ms)
{
CRYPTOPP_ASSERT(length % 2 == 0);
+ ThrowIfInvalidKeyLength(length);
#if (CRYPTOPP_XTS_WIDE_BLOCK_CIPHERS == 0)
CRYPTOPP_ASSERT(BlockSize() == 16);
@@ -61,9 +61,10 @@ public: size_t DefaultKeyLength() const
{return GetBlockCipher().DefaultKeyLength()*2;}
size_t GetValidKeyLength(size_t n) const
- {return GetBlockCipher().GetValidKeyLength((n+1)/2);}
+ {return 2*GetBlockCipher().GetValidKeyLength((n+1)/2);}
bool IsValidKeyLength(size_t keylength) const
{return keylength == GetValidKeyLength(keylength);}
+ void ThrowIfInvalidKeyLength(size_t length);
/// Provides the block size of the cipher
/// \return the block size of the cipher, in bytes
@@ -111,8 +112,8 @@ template <class CIPHER> class CRYPTOPP_NO_VTABLE XTS_Final : public XTS_ModeBase
{
public:
- static std::string CRYPTOPP_API StaticAlgorithmName()
- {return std::string(CIPHER::StaticAlgorithmName()) + "/XTS";}
+ static const char* CRYPTOPP_API StaticAlgorithmName()
+ {return "XTS";}
protected:
BlockCipher& AccessBlockCipher()
|