6 #ifndef CRYPTOPP_SECKEY_H 7 #define CRYPTOPP_SECKEY_H 15 #if CRYPTOPP_MSC_VERSION 16 # pragma warning(push) 17 # pragma warning(disable: 4189) 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>
57 return CRYPTOPP_UNUSED(blocksize),
static_cast<size_t>(
BLOCKSIZE);
66 return CRYPTOPP_UNUSED(keylength), CRYPTOPP_UNUSED(blocksize),
static_cast<size_t>(
BLOCKSIZE);
74 template <
unsigned int R>
79 CRYPTOPP_CONSTANT(ROUNDS = R)
86 template <
unsigned int D,
unsigned int N=1,
unsigned int M=INT_MAX>
91 CRYPTOPP_CONSTANT(DEFAULT_ROUNDS = D)
93 CRYPTOPP_CONSTANT(MIN_ROUNDS = N)
95 CRYPTOPP_CONSTANT(MAX_ROUNDS = M)
100 CRYPTOPP_STATIC_CONSTEXPR
unsigned int StaticGetDefaultRounds(
size_t keylength)
102 return CRYPTOPP_UNUSED(keylength),
static_cast<unsigned int>(DEFAULT_ROUNDS);
111 inline void ThrowIfInvalidRounds(
int rounds,
const Algorithm *alg)
115 if (rounds < MIN_ROUNDS)
120 if (rounds < MIN_ROUNDS || rounds > MAX_ROUNDS)
134 ThrowIfInvalidRounds(rounds, alg);
135 return static_cast<unsigned int>(rounds);
146 template <
unsigned int N,
unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE,
unsigned int IV_L = 0>
152 CRYPTOPP_CONSTANT(KEYLENGTH=N)
155 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N)
158 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=N)
161 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=N)
165 CRYPTOPP_CONSTANT(IV_REQUIREMENT = IV_REQ)
168 CRYPTOPP_CONSTANT(IV_LENGTH = IV_L)
173 CRYPTOPP_STATIC_CONSTEXPR
size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t keylength)
175 return CRYPTOPP_UNUSED(keylength),
static_cast<size_t>(KEYLENGTH);
187 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>
201 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N)
204 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=M)
207 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=D)
210 CRYPTOPP_CONSTANT(KEYLENGTH_MULTIPLE=Q)
214 CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ)
217 CRYPTOPP_CONSTANT(IV_LENGTH=IV_L)
226 CRYPTOPP_STATIC_CONSTEXPR
size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t keylength)
228 return (keylength <= N) ? N :
229 (keylength >= M) ? M :
230 (keylength+Q-1) - (keylength+Q-1)%Q;
239 template <
class T,
unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE,
unsigned int IV_L = 0>
245 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=T::MIN_KEYLENGTH)
248 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=T::MAX_KEYLENGTH)
251 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=T::DEFAULT_KEYLENGTH)
255 CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ)
258 CRYPTOPP_CONSTANT(IV_LENGTH=IV_L)
267 CRYPTOPP_STATIC_CONSTEXPR
size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t keylength)
268 {
return T::StaticGetValidKeyLength(keylength);}
279 template <
class BASE,
class INFO = BASE>
286 {
return INFO::MIN_KEYLENGTH;}
291 {
return (
size_t)INFO::MAX_KEYLENGTH;}
296 {
return INFO::DEFAULT_KEYLENGTH;}
306 size_t GetValidKeyLength(
size_t keylength)
const {
return INFO::StaticGetValidKeyLength(keylength);}
317 {
return INFO::IV_LENGTH;}
326 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);}
383 template <
class BASE,
class INFO = BASE>
391 template <
class BASE>
403 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
410 {this->SetKey(key, length);}
457 #if CRYPTOPP_MSC_VERSION 458 # pragma warning(pop) 462 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 463 # pragma GCC diagnostic 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 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.
static const int MIN_BLOCKSIZE
The minimum blocksize for the algorithm provided as a constant.
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.
static size_t StaticGetValidBlockSize(size_t blocksize)
The default block size for the algorithm provided by a static function.
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.
static const int DEFAULT_BLOCKSIZE
The default blocksize for the algorithm provided as a constant.
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.
static const int MAX_BLOCKSIZE
The maximum blocksize for the algorithm provided as a constant.
SymmetricCipher Encryption
implements the SymmetricCipher interface
MessageAuthenticationCodeFinal()
Construct a default MessageAuthenticationCodeFinal.
Interface for retrieving values given their names.