6 #ifndef CRYPTOPP_SECKEY_H 7 #define CRYPTOPP_SECKEY_H 11 #if CRYPTOPP_MSC_VERSION 12 # pragma warning(push) 13 # pragma warning(disable: 4189) 33 template <
unsigned int N>
46 template <
unsigned int R>
51 CRYPTOPP_CONSTANT(ROUNDS = R)
59 template <
unsigned int D,
unsigned int N=1,
unsigned int M=INT_MAX>
64 CRYPTOPP_CONSTANT(DEFAULT_ROUNDS = D)
66 CRYPTOPP_CONSTANT(MIN_ROUNDS = N)
68 CRYPTOPP_CONSTANT(MAX_ROUNDS = M)
73 CRYPTOPP_CONSTEXPR static
unsigned int StaticGetDefaultRounds(
size_t keylength)
77 #if defined(CRYPTOPP_CXX11_CONSTEXPR) 78 return CRYPTOPP_UNUSED(keylength),
static_cast<unsigned int>(DEFAULT_ROUNDS);
80 CRYPTOPP_UNUSED(keylength);
81 return static_cast<unsigned int>(DEFAULT_ROUNDS);
91 inline void ThrowIfInvalidRounds(
int rounds,
const Algorithm *alg)
95 if (rounds < MIN_ROUNDS)
100 if (rounds < MIN_ROUNDS || rounds > MAX_ROUNDS)
114 ThrowIfInvalidRounds(rounds, alg);
115 return (
unsigned int)rounds;
127 template <
unsigned int N,
unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE,
unsigned int IV_L = 0>
133 CRYPTOPP_CONSTANT(KEYLENGTH=N)
136 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N)
139 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=N)
142 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=N)
146 CRYPTOPP_CONSTANT(IV_REQUIREMENT = IV_REQ)
149 CRYPTOPP_CONSTANT(IV_LENGTH = IV_L)
154 CRYPTOPP_CONSTEXPR static
size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t keylength)
158 #if defined(CRYPTOPP_CXX11_CONSTEXPR) 159 return CRYPTOPP_UNUSED(keylength),
static_cast<size_t>(KEYLENGTH);
161 CRYPTOPP_UNUSED(keylength);
162 return static_cast<size_t>(KEYLENGTH);
176 template <
unsigned int D,
unsigned int N,
unsigned int M,
unsigned int Q = 1,
unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE,
unsigned int IV_L = 0>
190 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N)
193 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=M)
196 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=D)
199 CRYPTOPP_CONSTANT(KEYLENGTH_MULTIPLE=Q)
203 CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ)
206 CRYPTOPP_CONSTANT(IV_LENGTH=IV_L)
216 static
size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t keylength)
218 if (keylength < (
size_t)MIN_KEYLENGTH)
219 return MIN_KEYLENGTH;
220 else if (keylength > (
size_t)MAX_KEYLENGTH)
221 return (
size_t)MAX_KEYLENGTH;
224 keylength += KEYLENGTH_MULTIPLE-1;
225 return keylength - keylength%KEYLENGTH_MULTIPLE;
236 template <
class T,
unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE,
unsigned int IV_L = 0>
242 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=T::MIN_KEYLENGTH)
245 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=T::MAX_KEYLENGTH)
248 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=T::DEFAULT_KEYLENGTH)
252 CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ)
255 CRYPTOPP_CONSTANT(IV_LENGTH=IV_L)
264 CRYPTOPP_CONSTEXPR static
size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t keylength)
265 {
return T::StaticGetValidKeyLength(keylength);}
277 template <
class BASE,
class INFO = BASE>
284 {
return INFO::MIN_KEYLENGTH;}
289 {
return (
size_t)INFO::MAX_KEYLENGTH;}
294 {
return INFO::DEFAULT_KEYLENGTH;}
304 size_t GetValidKeyLength(
size_t keylength)
const {
return INFO::StaticGetValidKeyLength(keylength);}
315 {
return INFO::IV_LENGTH;}
325 template <
class INFO,
class BASE = BlockCipher>
338 template <CipherDir DIR,
class BASE>
351 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
359 {this->SetKey(key, length);}
368 {this->SetKeyWithRounds(key, length, rounds);}
384 template <
class BASE,
class INFO = BASE>
393 template <
class BASE>
405 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
412 {this->SetKey(key, length);}
462 #if CRYPTOPP_MSC_VERSION 463 # pragma warning(pop) int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
the cipher is performing decryption
size_t MinKeyLength() const
The minimum key length used by the algorithm.
Inherited by keyed algorithms with fixed key length.
size_t DefaultKeyLength() const
The default key length used by the algorithm.
Classes providing basic library services.
Utility functions for the Crypto++ library.
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
MessageAuthenticationCodeFinal(const byte *key, size_t length)
Construct a BlockCipherFinal.
Interface for one direction (encryption or decryption) of a stream cipher or block cipher mode with a...
Base class for identifying alogorithm.
SimpleKeyingInterface::IV_Requirement IVRequirement() const
The default IV requirements for the algorithm.
Provides a base implementation of SimpleKeyingInterface.
CipherDir
Specifies a direction for a cipher to operate.
Abstract base classes that provide a uniform interface to this library.
Provides Encryption and Decryption typedefs used by derived classes to implement an authenticated enc...
Library configuration file.
Provides class member functions to key a message authentication code.
BlockCipherFinal(const byte *key)
Construct a BlockCipherFinal.
BlockCipher Decryption
implements the BlockCipher interface
size_t MaxKeyLength() const
The maximum key length used by the algorithm.
Interface for one direction (encryption or decryption) of a block cipher.
the cipher is performing encryption
Inherited by algorithms with fixed block size.
BlockCipher Encryption
implements the BlockCipher interface
Inherited by algorithms with variable number of rounds.
bool IsForwardTransformation() const
Provides the direction of the cipher.
BlockCipherFinal()
Construct a default BlockCipherFinal.
Exception thrown when an invalid number of rounds is encountered.
#define CRYPTOPP_COMPILE_ASSERT(expr)
Compile time assertion.
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Provides class member functions to key a block cipher.
unsigned int BlockSize() const
Provides the block size of the algorithm.
Provides a base implementation of Algorithm and SimpleKeyingInterface for message authentication code...
MessageAuthenticationCodeFinal(const byte *key)
Construct a BlockCipherFinal.
Provides key lengths based on another class's key length.
virtual std::string AlgorithmName() const
Provides the name of this algorithm.
Inherited by algorithms with fixed number of rounds.
CipherDir ReverseCipherDir(CipherDir dir)
Inverts the cipher's direction.
size_t GetValidKeyLength(size_t keylength) const
Provides a valid key length for the algorithm.
SymmetricCipher Decryption
implements the SymmetricCipher interface
Inherited by keyed algorithms with variable key length.
Interface for all crypto algorithms.
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher...
unsigned int IVSize() const
The default initialization vector length for the algorithm.
AuthenticatedSymmetricCipher Encryption
implements the AuthenticatedSymmetricCipher interface
IV_Requirement
Secure IVs requirements as enumerated values.
BlockCipherFinal(const byte *key, size_t length, unsigned int rounds)
Construct a BlockCipherFinal.
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Crypto++ library namespace.
static const int BLOCKSIZE
The block size of the algorithm provided as a constant.
AuthenticatedSymmetricCipher Decryption
implements the AuthenticatedSymmetricCipher interface
BlockCipherFinal(const byte *key, size_t length)
Construct a BlockCipherFinal.
SymmetricCipher Encryption
implements the SymmetricCipher interface
MessageAuthenticationCodeFinal()
Construct a default MessageAuthenticationCodeFinal.
Interface for retrieving values given their names.
Base class for identifying alogorithm.