Remove BLOCKSIZE from VariableBlockSize (Issue 408)

VariableBlockSize and VariableBlockCipherImpl were added at Commit bd8edfa87b. Reflecting on FixedKeyLength and VariableKeyLength, the const KEYLENGTH is only provided by FixedKeyLength. VariableKeyLength provides DEFAULT_KEYLENGTH. This check-in makes VariableBlockSize follow VariableKeyLength.
This check-in also splits block size and iv length. Its conceivable we will encounter a cipher with a block size of 128-bits with an iv of 256-bits. The bd8edfa87b check-in could not handle the difference, so we fix it now.
pull/416/head
Jeffrey Walton 2017-05-03 21:06:49 -04:00
parent ca9e788fbf
commit 2d9678fa6d
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 7 additions and 6 deletions

View File

@ -125,7 +125,7 @@ class VariableBlockSize
{ {
public: public:
//! \brief The default blocksize for the algorithm provided as a constant. //! \brief The default blocksize for the algorithm provided as a constant.
CRYPTOPP_CONSTANT(BLOCKSIZE = D) // CRYPTOPP_CONSTANT(BLOCKSIZE = D)
//! \brief The default blocksize for the algorithm provided as a constant. //! \brief The default blocksize for the algorithm provided as a constant.
CRYPTOPP_CONSTANT(DEFAULT_BLOCKSIZE = D) CRYPTOPP_CONSTANT(DEFAULT_BLOCKSIZE = D)
//! \brief The minimum blocksize for the algorithm provided as a constant. //! \brief The minimum blocksize for the algorithm provided as a constant.
@ -438,13 +438,14 @@ template <class INFO, class BASE = BlockCipher>
class CRYPTOPP_NO_VTABLE VariableBlockCipherImpl : public AlgorithmImpl<SimpleKeyingInterfaceImpl<TwoBases<BASE, INFO> > > class CRYPTOPP_NO_VTABLE VariableBlockCipherImpl : public AlgorithmImpl<SimpleKeyingInterfaceImpl<TwoBases<BASE, INFO> > >
{ {
public: public:
VariableBlockCipherImpl() : m_blocksize(0) {} VariableBlockCipherImpl() : m_blocksize(0), m_ivlength(0) {}
VariableBlockCipherImpl(unsigned int blocksize) : m_blocksize(blocksize) {} VariableBlockCipherImpl(unsigned int blockSize) : m_blocksize(blockSize), m_ivlength(blockSize) {}
VariableBlockCipherImpl(unsigned int blockSize, unsigned int ivLength) : m_blocksize(blocksize), m_ivlength(ivLength) {}
//! Provides the block size of the algorithm //! Provides the block size of the algorithm
//! \returns the block size, in bytes //! \returns the block size, in bytes
unsigned int BlockSize() const { unsigned int BlockSize() const {
return m_blocksize ? m_blocksize : this->BLOCKSIZE; return m_blocksize ? m_blocksize : this->DEFAULT_BLOCKSIZE;
} }
//! Provides the initialization vector length of the algorithm //! Provides the initialization vector length of the algorithm
@ -452,11 +453,11 @@ public:
unsigned int IVSize() const { unsigned int IVSize() const {
if (!this->IsResynchronizable()) if (!this->IsResynchronizable())
throw NotImplemented(this->GetAlgorithm().AlgorithmName() + ": this object doesn't support resynchronization"); throw NotImplemented(this->GetAlgorithm().AlgorithmName() + ": this object doesn't support resynchronization");
return m_blocksize ? m_blocksize : this->IV_LENGTH; return m_ivlength ? m_ivlength : this->IV_LENGTH;
} }
protected: protected:
unsigned int m_blocksize; unsigned int m_blocksize, m_ivlength;
}; };
//! \class BlockCipherFinal //! \class BlockCipherFinal