From 2d9678fa6db28598eb9c7f978491327383aa2d3d Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Wed, 3 May 2017 21:06:49 -0400 Subject: Remove BLOCKSIZE from VariableBlockSize (Issue 408) VariableBlockSize and VariableBlockCipherImpl were added at Commit bd8edfa87b579073. 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 bd8edfa87b579073 check-in could not handle the difference, so we fix it now. --- seckey.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'seckey.h') diff --git a/seckey.h b/seckey.h index dcf28fbe..323f4d3e 100644 --- a/seckey.h +++ b/seckey.h @@ -125,7 +125,7 @@ class VariableBlockSize { public: //! \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. CRYPTOPP_CONSTANT(DEFAULT_BLOCKSIZE = D) //! \brief The minimum blocksize for the algorithm provided as a constant. @@ -438,13 +438,14 @@ template class CRYPTOPP_NO_VTABLE VariableBlockCipherImpl : public AlgorithmImpl > > { public: - VariableBlockCipherImpl() : m_blocksize(0) {} - VariableBlockCipherImpl(unsigned int blocksize) : m_blocksize(blocksize) {} + VariableBlockCipherImpl() : m_blocksize(0), m_ivlength(0) {} + 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 //! \returns the block size, in bytes 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 @@ -452,11 +453,11 @@ public: unsigned int IVSize() const { if (!this->IsResynchronizable()) 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: - unsigned int m_blocksize; + unsigned int m_blocksize, m_ivlength; }; //! \class BlockCipherFinal -- cgit v1.2.1