6 #ifndef CRYPTOPP_SECKEY_H 7 #define CRYPTOPP_SECKEY_H 11 #if CRYPTOPP_MSC_VERSION 12 # pragma warning(push) 13 # pragma warning(disable: 4189) 27 return (dir == ENCRYPTION) ? DECRYPTION : ENCRYPTION;
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 static
unsigned int StaticGetDefaultRounds(
size_t keylength)
74 {CRYPTOPP_UNUSED(keylength);
return DEFAULT_ROUNDS;}
81 inline void ThrowIfInvalidRounds(
int rounds,
const Algorithm *alg)
83 #if (M==INT_MAX) // Coverity and result_independent_of_operands 84 if (rounds < MIN_ROUNDS)
87 if (rounds < MIN_ROUNDS || rounds > MAX_ROUNDS)
100 ThrowIfInvalidRounds(rounds, alg);
101 return (
unsigned int)rounds;
112 template <
unsigned int N,
unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE,
unsigned int IV_L = 0>
118 CRYPTOPP_CONSTANT(KEYLENGTH=N)
121 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N)
124 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=N)
127 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=N)
131 CRYPTOPP_CONSTANT(IV_REQUIREMENT = IV_REQ)
134 CRYPTOPP_CONSTANT(IV_LENGTH = IV_L)
139 static
size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t keylength)
140 {CRYPTOPP_UNUSED(keylength);
return KEYLENGTH;}
151 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>
165 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N)
168 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=M)
171 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=D)
174 CRYPTOPP_CONSTANT(KEYLENGTH_MULTIPLE=Q)
178 CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ)
181 CRYPTOPP_CONSTANT(IV_LENGTH=IV_L)
190 static
size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t keylength)
192 #if MIN_KEYLENGTH > 0 193 if (keylength < (
size_t)MIN_KEYLENGTH)
194 return MIN_KEYLENGTH;
197 if (keylength > (
size_t)MAX_KEYLENGTH)
198 return (
size_t)MAX_KEYLENGTH;
201 keylength += KEYLENGTH_MULTIPLE-1;
202 return keylength - keylength%KEYLENGTH_MULTIPLE;
212 template <
class T,
unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE,
unsigned int IV_L = 0>
218 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=T::MIN_KEYLENGTH)
221 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=T::MAX_KEYLENGTH)
224 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=T::DEFAULT_KEYLENGTH)
228 CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ)
231 CRYPTOPP_CONSTANT(IV_LENGTH=IV_L)
240 static
size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t keylength)
241 {
return T::StaticGetValidKeyLength(keylength);}
250 template <
class BASE,
class INFO = BASE>
256 {
return INFO::MIN_KEYLENGTH;}
260 {
return (
size_t)INFO::MAX_KEYLENGTH;}
264 {
return INFO::DEFAULT_KEYLENGTH;}
273 size_t GetValidKeyLength(
size_t keylength)
const {
return INFO::StaticGetValidKeyLength(keylength);}
284 {
return INFO::IV_LENGTH;}
291 template <
class INFO,
class BASE = BlockCipher>
304 template <CipherDir DIR,
class BASE>
317 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
325 {this->SetKey(key, length);}
334 {this->SetKeyWithRounds(key, length, rounds);}
346 template <
class BASE,
class INFO = BASE>
355 template <
class BASE>
367 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
374 {this->SetKey(key, length);}
424 #if CRYPTOPP_MSC_VERSION 425 # pragma warning(pop) Inherited by keyed algorithms with fixed key length.
Classes providing simple keying interfaces.
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.
Provides class member functions to access SimpleKeyingInterface constants.
CipherDir
Specifies a direction for a cipher to operate.
Abstract base classes that provide a uniform interface to this library.
unsigned int BlockSize() const
Provides the block size of the cipher.
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
Interface for one direction (encryption or decryption) of a block cipher.
Inherited by block ciphers with fixed block size.
BlockCipher Encryption
implements the BlockCipher interface
Inherited by ciphers with variable number of rounds.
int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
BlockCipherFinal()
Construct a default BlockCipherFinal.
Exception thrown when an invalid number of rounds is encountered.
size_t DefaultKeyLength() const
The default key length used by the cipher.
#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.
virtual std::string AlgorithmName() const
Provides the name of this algorithm.
Provides class member functions to access MessageAuthenticationCode constants.
MessageAuthenticationCodeFinal(const byte *key)
Construct a BlockCipherFinal.
bool IsForwardTransformation() const
Provides the direction of the cipher.
size_t GetValidKeyLength(size_t keylength) const
Provides a valid key length for the cipher.
Provides key lengths based on another class's key length.
Inherited by ciphers with fixed number of rounds.
CipherDir ReverseCipherDir(CipherDir dir)
Inverts the cipher's direction.
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...
AuthenticatedSymmetricCipher Encryption
implements the AuthenticatedSymmetricCipher interface
IV_Requirement
Provides IV requirements as an enumerated value.
BlockCipherFinal(const byte *key, size_t length, unsigned int rounds)
Construct a BlockCipherFinal.
Provides class member functions to access BlockCipher constants.
Crypto++ library namespace.
static const int BLOCKSIZE
The block size of the cipher provided as a constant.
AuthenticatedSymmetricCipher Decryption
implements the AuthenticatedSymmetricCipher interface
SimpleKeyingInterface::IV_Requirement IVRequirement() const
The default IV requirements for the cipher.
BlockCipherFinal(const byte *key, size_t length)
Construct a BlockCipherFinal.
unsigned int IVSize() const
The default initialization vector length for the cipher.
size_t MaxKeyLength() const
The maximum key length used by the cipher.
SymmetricCipher Encryption
implements the SymmetricCipher interface
size_t MinKeyLength() const
The minimum key length used by the cipher.
MessageAuthenticationCodeFinal()
Construct a default MessageAuthenticationCodeFinal.
Interface for retrieving values given their names.
Base class for identifying alogorithm.