6#ifndef CRYPTOPP_SECKEY_H
7#define CRYPTOPP_SECKEY_H
15#if CRYPTOPP_MSC_VERSION
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"
27NAMESPACE_BEGIN(CryptoPP)
39template <
unsigned int N>
51template <
unsigned int R>
63template <
unsigned int D,
unsigned int N=1,
unsigned int M=INT_MAX>
79 return CRYPTOPP_UNUSED(keylength),
static_cast<unsigned int>(DEFAULT_ROUNDS);
92 if (rounds < MIN_ROUNDS)
97 if (rounds < MIN_ROUNDS || rounds > MAX_ROUNDS)
112 return static_cast<unsigned int>(rounds);
123template <
unsigned int N,
unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE,
unsigned int IV_L = 0>
152 return CRYPTOPP_UNUSED(keylength),
static_cast<size_t>(KEYLENGTH);
164template <
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>
168 CRYPTOPP_COMPILE_ASSERT(Q > 0);
169 CRYPTOPP_COMPILE_ASSERT(N % Q == 0);
170 CRYPTOPP_COMPILE_ASSERT(M % Q == 0);
171 CRYPTOPP_COMPILE_ASSERT(N < M);
172 CRYPTOPP_COMPILE_ASSERT(D >= N);
173 CRYPTOPP_COMPILE_ASSERT(M >= D);
205 return (keylength <= N) ? N :
206 (keylength >= M) ? M :
207 (keylength+Q-1) - (keylength+Q-1)%Q;
216template <
class T,
unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE,
unsigned int IV_L = 0>
245 {
return T::StaticGetValidKeyLength(keylength);}
256template <
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;}
304template <
class INFO,
class BASE = BlockCipher>
310 unsigned int BlockSize()
const {
return this->BLOCKSIZE;}
316template <CipherDir DIR,
class BASE>
329 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
337 {this->SetKey(key, length);}
346 {this->SetKeyWithRounds(key, length, rounds);}
361template <
class BASE,
class INFO = BASE>
381 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
388 {this->SetKey(key, length);}
435#if CRYPTOPP_MSC_VERSION
440#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
441# pragma GCC diagnostic pop
Interface for all crypto algorithms.
virtual std::string AlgorithmName() const
Provides the name of this algorithm.
Interface for authenticated encryption modes of operation.
Provides class member functions to key a block cipher.
bool IsForwardTransformation() const
Provides the direction of the cipher.
BlockCipherFinal()
Construct a default BlockCipherFinal.
BlockCipherFinal(const byte *key)
Construct a BlockCipherFinal.
BlockCipherFinal(const byte *key, size_t length, unsigned int rounds)
Construct a BlockCipherFinal.
BlockCipherFinal(const byte *key, size_t length)
Construct a BlockCipherFinal.
Interface for one direction (encryption or decryption) of a block cipher.
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
unsigned int BlockSize() const
Base class for identifying algorithm.
Inherited by algorithms with fixed block size.
CRYPTOPP_CONSTANT(BLOCKSIZE=N)
The block size of the algorithm provided as a constant.
Inherited by keyed algorithms with fixed key length.
CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ)
The default IV requirements for the algorithm provided as a constant.
CRYPTOPP_CONSTANT(IV_LENGTH=IV_L)
The default IV length used by the algorithm provided as a constant.
CRYPTOPP_CONSTANT(MAX_KEYLENGTH=N)
The maximum key length used by the algorithm provided as a constant.
CRYPTOPP_STATIC_CONSTEXPR size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength)
The default key length for the algorithm provided by a static function.
CRYPTOPP_CONSTANT(KEYLENGTH=N)
The default key length used by the algorithm provided as a constant.
CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N)
The minimum key length used by the algorithm provided as a constant.
CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=N)
The default key length used by the algorithm provided as a constant.
Inherited by algorithms with fixed number of rounds.
CRYPTOPP_CONSTANT(ROUNDS=R)
The number of rounds for the algorithm provided as a constant.
Exception thrown when an invalid number of rounds is encountered.
Provides class member functions to key a message authentication code.
MessageAuthenticationCodeFinal(const byte *key, size_t length)
Construct a BlockCipherFinal.
MessageAuthenticationCodeFinal(const byte *key)
Construct a BlockCipherFinal.
MessageAuthenticationCodeFinal()
Construct a default MessageAuthenticationCodeFinal.
Provides a base implementation of Algorithm and SimpleKeyingInterface for message authentication code...
Interface for retrieving values given their names.
CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
Provides key lengths based on another class's key length.
CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ)
The default IV requirements for the algorithm provided as a constant.
CRYPTOPP_CONSTANT(MIN_KEYLENGTH=T::MIN_KEYLENGTH)
The minimum key length used by the algorithm provided as a constant.
CRYPTOPP_CONSTANT(MAX_KEYLENGTH=T::MAX_KEYLENGTH)
The maximum key length used by the algorithm provided as a constant.
CRYPTOPP_STATIC_CONSTEXPR size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength)
Provides a valid key length for the algorithm provided by a static function.
CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=T::DEFAULT_KEYLENGTH)
The default key length used by the algorithm provided as a constant.
CRYPTOPP_CONSTANT(IV_LENGTH=IV_L)
The default initialization vector length for the algorithm provided as a constant.
IV_Requirement
Secure IVs requirements as enumerated values.
Provides a base implementation of SimpleKeyingInterface.
size_t DefaultKeyLength() const
The default key length used by the algorithm.
size_t GetValidKeyLength(size_t keylength) const
Provides a valid key length for the algorithm.
size_t MaxKeyLength() const
The maximum key length used by the algorithm.
unsigned int IVSize() const
The initialization vector length for the algorithm.
size_t MinKeyLength() const
The minimum key length used by the algorithm.
SimpleKeyingInterface::IV_Requirement IVRequirement() const
The default IV requirements for the algorithm.
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode.
Inherited by keyed algorithms with variable key length.
CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ)
The default IV requirements for the algorithm provided as a constant.
CRYPTOPP_CONSTANT(KEYLENGTH_MULTIPLE=Q)
The key length multiple used by the algorithm provided as a constant.
CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N)
The minimum key length used by the algorithm provided as a constant.
CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=D)
The default key length used by the algorithm provided as a constant.
CRYPTOPP_CONSTANT(MAX_KEYLENGTH=M)
The maximum key length used by the algorithm provided as a constant.
CRYPTOPP_STATIC_CONSTEXPR size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength)
Provides a valid key length for the algorithm provided by a static function.
CRYPTOPP_CONSTANT(IV_LENGTH=IV_L)
The default initialization vector length for the algorithm provided as a constant.
Inherited by algorithms with variable number of rounds.
CRYPTOPP_CONSTANT(DEFAULT_ROUNDS=D)
The default number of rounds for the algorithm provided as a constant.
unsigned int GetRoundsAndThrowIfInvalid(const NameValuePairs ¶m, const Algorithm *alg)
Validates the number of rounds for an algorithm.
CRYPTOPP_CONSTANT(MAX_ROUNDS=M)
The maximum number of rounds for the algorithm provided as a constant.
void ThrowIfInvalidRounds(int rounds, const Algorithm *alg)
Validates the number of rounds for an algorithm.
CRYPTOPP_STATIC_CONSTEXPR unsigned int StaticGetDefaultRounds(size_t keylength)
The default number of rounds for the algorithm based on key length provided by a static function.
CRYPTOPP_CONSTANT(MIN_ROUNDS=N)
The minimum number of rounds for the algorithm provided as a constant.
Library configuration file.
Abstract base classes that provide a uniform interface to this library.
CipherDir
Specifies a direction for a cipher to operate.
@ ENCRYPTION
the cipher is performing encryption
@ DECRYPTION
the cipher is performing decryption
Utility functions for the Crypto++ library.
CipherDir ReverseCipherDir(CipherDir dir)
Inverts the cipher's direction.
Classes providing basic library services.
Provides Encryption and Decryption typedefs used by derived classes to implement an authenticated enc...
AuthenticatedSymmetricCipher Decryption
implements the AuthenticatedSymmetricCipher interface
AuthenticatedSymmetricCipher Encryption
implements the AuthenticatedSymmetricCipher interface
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher.
BlockCipher Decryption
implements the BlockCipher interface
BlockCipher Encryption
implements the BlockCipher interface
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher.
SymmetricCipher Decryption
implements the SymmetricCipher interface
SymmetricCipher Encryption
implements the SymmetricCipher interface