summaryrefslogtreecommitdiff
path: root/seckey.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-01-18 20:26:10 -0500
committerJeffrey Walton <noloader@gmail.com>2018-01-18 20:26:10 -0500
commit58b69992747d10561e65dd8b390a665063bdd619 (patch)
treea5d45d1b508facd006020e130ee32351ad3473e6 /seckey.h
parent1eca4fd940ba0f3f87e933c315dccc3cdd863958 (diff)
downloadcryptopp-git-58b69992747d10561e65dd8b390a665063bdd619.tar.gz
Convert Kalyna from variable block size (GH #535)
Diffstat (limited to 'seckey.h')
-rw-r--r--seckey.h152
1 files changed, 0 insertions, 152 deletions
diff --git a/seckey.h b/seckey.h
index 74e1ac15..a417dcf4 100644
--- a/seckey.h
+++ b/seckey.h
@@ -138,123 +138,6 @@ protected:
}
};
-/// \class VariableBlockSize
-/// \brief Inherited by algorithms with variable blocksize
-/// \tparam D Default blocksize
-/// \tparam N Minimum blocksize
-/// \tparam M Maximum blocksize
-template <unsigned int D, unsigned int N=1, unsigned int M=INT_MAX> // use INT_MAX here because enums are treated as signed ints
-class VariableBlockSize
-{
-public:
- /// \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.
- CRYPTOPP_CONSTANT(MIN_BLOCKSIZE = N)
- /// \brief The maximum blocksize for the algorithm provided as a constant.
- CRYPTOPP_CONSTANT(MAX_BLOCKSIZE = M)
- /// \brief The default block size for the algorithm provided by a static function.
- /// \param blocksize the block size, in bytes
- /// \details The default implementation returns BLOCKSIZE. blocksize is unused
- /// in the default implementation.
- CRYPTOPP_STATIC_CONSTEXPR size_t CRYPTOPP_API StaticGetValidBlockSize(size_t blocksize)
- {
- return CRYPTOPP_UNUSED(blocksize), static_cast<size_t>(DEFAULT_BLOCKSIZE);
- }
- /// \brief The default block size under a key provided by a static function.
- /// \param keylength the size of the key, in bytes
- /// \param blocksize the block size, in bytes
- /// \details The default implementation returns BLOCKSIZE. blocksize is unused
- /// in the default implementation.
- CRYPTOPP_STATIC_CONSTEXPR size_t CRYPTOPP_API StaticGetValidBlockSize(size_t keylength, size_t blocksize)
- {
- return CRYPTOPP_UNUSED(keylength), CRYPTOPP_UNUSED(blocksize), static_cast<size_t>(DEFAULT_BLOCKSIZE);
- }
-
-protected:
- /// \brief Validates the blocksize for an algorithm.
- /// \param blocksize the candidate blocksize
- /// \param alg an Algorithm object used if the blocksize is invalid
- /// \throws InvalidBlockSize if the blocksize is invalid
- /// \details ThrowIfInvalidBlockSize() validates the blocksize and throws if invalid.
- inline void ThrowIfInvalidBlockSize(int blocksize, const Algorithm *alg)
- {
- if (M == INT_MAX) // Coverity and result_independent_of_operands
- {
- if (blocksize < MIN_BLOCKSIZE)
- throw InvalidBlockSize(alg ? alg->AlgorithmName() : std::string("VariableBlockSize"), blocksize);
- }
- else
- {
- if (blocksize < MIN_BLOCKSIZE || blocksize > MAX_BLOCKSIZE)
- throw InvalidBlockSize(alg ? alg->AlgorithmName() : std::string("VariableBlockSize"), blocksize);
- }
- }
-
- /// \brief Validates the blocksize for an algorithm
- /// \param param the candidate blocksize
- /// \param alg an Algorithm object used if the blocksize is invalid
- /// \returns the blocksize for the algorithm
- /// \throws InvalidBlockSize if the blocksize is invalid
- /// \details GetBlockSizeAndThrowIfInvalid() validates the blocksize and throws if invalid.
- inline unsigned int GetBlockSizeAndThrowIfInvalid(const NameValuePairs &param, const Algorithm *alg)
- {
- int keylength = param.GetIntValueWithDefault("KeySize", 0);
- int blocksize = param.GetIntValueWithDefault("BlockSize", DEFAULT_BLOCKSIZE);
- if (keylength > 0)
- ThrowIfInvalidBlockSize(keylength, blocksize, alg);
- else
- ThrowIfInvalidBlockSize(blocksize, alg);
- return static_cast<unsigned int>(blocksize);
- }
-
- /// Provides the block size of the cipher
- /// \return the block size, in bytes
- /// \details The sematics of BlockSize() is return DEFAULT_BLOCKSIZE if the default blocksize
- /// is in effect. If the blocksize has changed, then the value returned is the BlockSize()
- /// parameter used during SetKey().
- /// \details DEFAULT_BLOCKSIZE should be paired with DEFAULT_KEYLENGTH, and it is the same as
- /// BLOCKSIZE in a FixedBlockSize cipher.
- virtual unsigned int BlockSize() const =0;
-
- /// Provides the minimum block size of the cipher
- /// \return the minimum block size, in bytes
- /// \details MinBlockSize() returns the smallest blocksize a cipher can use. The size can
- /// be affected by the key length. For example, Threefish has key sizes of 256, 512 and 1024 bits,
- /// and the blocksize follows the key length. If a 512-bit key is used, then the block size is 512
- /// bits. Once keyed, the minimum block size of 256 is not accurate, nor is a block size of 1024 bit.
- virtual unsigned int MinBlockSize() const
- { return MIN_BLOCKSIZE; }
-
- /// Provides the maximum block size of the cipher
- /// \return the maximum block size, in bytes
- /// \details MaxBlockSize() returns the largest blocksize a cipher can use. The size can
- /// be affected by the key length. For example, Threefish has key sizes of 256, 512 and 1024 bits,
- /// and the blocksize follows the key length. If a 512-bit key is used, then the block size is 512
- /// bits. Once keyed, the minimum block size of 256 is not accurate, nor is a block size of 1024 bit.
- virtual unsigned int MaxBlockSize() const
- { return MAX_BLOCKSIZE; }
-
- /// Provides the initialization vector length of the cipher
- /// \return the initialization vector length, in bytes
- /// \details The sematics of IVSize() is return IV_LENGTH if the default blocksize is
- /// in effect. If the blocksize has changed, then the default implentation returns the value of
- /// the BlockSize() parameter used during SetKey().
- /// \details Derived classes may override the behavior such that a different value is returned.
- /// This may happen with a cipher that requires an IV that is twice the block size.
- virtual unsigned int IVSize() const =0;
-
- /// \brief Provides the minimum size of an IV
- /// \return minimal length of IVs accepted by this cipher, in bytes
- virtual unsigned int MinIVLength() const
- { return MIN_BLOCKSIZE; }
-
- /// \brief Provides the maximum size of an IV
- /// \return maximal length of IVs accepted by this cipher, in bytes
- virtual unsigned int MaxIVLength() const
- { return MAX_BLOCKSIZE; }
-};
-
// ************** key length ***************
/// \class FixedKeyLength
@@ -456,41 +339,6 @@ public:
unsigned int BlockSize() const {return this->BLOCKSIZE;}
};
-/// \class VariableBlockCipherImpl
-/// \brief Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers with varibale block sizes
-/// \tparam INFO a SimpleKeyingInterface derived class
-/// \tparam BASE a SimpleKeyingInterface derived class
-/// \details VariableBlockCipherImpl() provides a default implementation for block ciphers with varibale block sizes using AlgorithmImpl()
-/// and SimpleKeyingInterfaceImpl().
-/// \sa Algorithm(), SimpleKeyingInterface(), AlgorithmImpl(), SimpleKeyingInterfaceImpl()
-template <class INFO, class BASE = BlockCipher>
-class CRYPTOPP_NO_VTABLE VariableBlockCipherImpl : public AlgorithmImpl<SimpleKeyingInterfaceImpl<TwoBases<BASE, INFO> > >
-{
-public:
- 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 :
- static_cast<unsigned int>(this->DEFAULT_BLOCKSIZE);
- }
-
- /// Provides the initialization vector length of the algorithm
- /// \returns the initialization vector length, in bytes
- unsigned int IVSize() const {
- if (!this->IsResynchronizable())
- throw NotImplemented(this->GetAlgorithm().AlgorithmName() + ": this object doesn't support resynchronization");
- return m_ivlength ? m_ivlength :
- static_cast<unsigned int>(this->IV_LENGTH);
- }
-
-protected:
- unsigned int m_blocksize, m_ivlength;
-};
-
/// \class BlockCipherFinal
/// \brief Provides class member functions to key a block cipher
/// \tparam DIR a CipherDir