6 #ifndef CRYPTOPP_SECKEY_H 7 #define CRYPTOPP_SECKEY_H 15 #if CRYPTOPP_MSC_VERSION 16 # pragma warning(push) 17 # pragma warning(disable: 4189 4296) 21 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 22 # pragma GCC diagnostic push 23 # pragma GCC diagnostic ignored "-Wconversion" 24 # pragma GCC diagnostic ignored "-Wsign-conversion" 39 template <
unsigned int N>
51 template <
unsigned int R>
56 CRYPTOPP_CONSTANT(ROUNDS = R);
63 template <
unsigned int D,
unsigned int N=1,
unsigned int M=INT_MAX>
68 CRYPTOPP_CONSTANT(DEFAULT_ROUNDS = D);
70 CRYPTOPP_CONSTANT(MIN_ROUNDS = N);
72 CRYPTOPP_CONSTANT(MAX_ROUNDS = M);
77 CRYPTOPP_STATIC_CONSTEXPR
unsigned int StaticGetDefaultRounds(
size_t keylength)
79 return CRYPTOPP_UNUSED(keylength),
static_cast<unsigned int>(DEFAULT_ROUNDS);
88 inline void ThrowIfInvalidRounds(
int rounds,
const Algorithm *alg)
92 if (rounds < MIN_ROUNDS)
97 if (rounds < MIN_ROUNDS || rounds > MAX_ROUNDS)
111 ThrowIfInvalidRounds(rounds, alg);
112 return static_cast<unsigned int>(rounds);
123 template <
unsigned int N,
unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE,
unsigned int IV_L = 0>
129 CRYPTOPP_CONSTANT(KEYLENGTH=N);
132 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N);
135 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=N);
138 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=N);
142 CRYPTOPP_CONSTANT(IV_REQUIREMENT = IV_REQ);
145 CRYPTOPP_CONSTANT(IV_LENGTH = IV_L);
150 CRYPTOPP_STATIC_CONSTEXPR
size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t keylength)
152 return CRYPTOPP_UNUSED(keylength),
static_cast<size_t>(KEYLENGTH);
164 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>
178 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N);
181 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=M);
184 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=D);
187 CRYPTOPP_CONSTANT(KEYLENGTH_MULTIPLE=Q);
191 CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ);
194 CRYPTOPP_CONSTANT(IV_LENGTH=IV_L);
203 CRYPTOPP_STATIC_CONSTEXPR
size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t keylength)
205 return (keylength <= N) ? N :
206 (keylength >= M) ? M :
207 (keylength+Q-1) - (keylength+Q-1)%Q;
216 template <
class T,
unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE,
unsigned int IV_L = 0>
222 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=T::MIN_KEYLENGTH);
225 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=T::MAX_KEYLENGTH);
228 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=T::DEFAULT_KEYLENGTH);
232 CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ);
235 CRYPTOPP_CONSTANT(IV_LENGTH=IV_L);
244 CRYPTOPP_STATIC_CONSTEXPR
size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t keylength)
245 {
return T::StaticGetValidKeyLength(keylength);}
256 template <
class BASE,
class INFO = BASE>
263 {
return INFO::MIN_KEYLENGTH;}
268 {
return static_cast<size_t>(INFO::MAX_KEYLENGTH);}
273 {
return INFO::DEFAULT_KEYLENGTH;}
283 size_t GetValidKeyLength(
size_t keylength)
const {
return INFO::StaticGetValidKeyLength(keylength);}
295 {
return INFO::IV_LENGTH;}
304 template <
class INFO,
class BASE = BlockCipher>
316 template <CipherDir DIR,
class BASE>
329 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
337 {this->SetKey(key, length);}
346 {this->SetKeyWithRounds(key, length, rounds);}
361 template <
class BASE,
class INFO = BASE>
369 template <
class BASE>
381 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
388 {this->SetKey(key, length);}
435 #if CRYPTOPP_MSC_VERSION 436 # pragma warning(pop) 440 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 441 # pragma GCC diagnostic pop 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.
CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
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 authenticated encryption modes of operation.
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 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.