5 #ifndef CRYPTOPP_SECKEY_H
6 #define CRYPTOPP_SECKEY_H
12 NAMESPACE_BEGIN(CryptoPP)
16 return (dir == ENCRYPTION) ? DECRYPTION : ENCRYPTION;
20 template <
unsigned int N>
24 CRYPTOPP_CONSTANT(BLOCKSIZE = N)
30 template <
unsigned int R>
34 CRYPTOPP_CONSTANT(ROUNDS = R)
38 template <
unsigned int D,
unsigned int N=1,
unsigned int M=INT_MAX>
42 CRYPTOPP_CONSTANT(DEFAULT_ROUNDS = D)
43 CRYPTOPP_CONSTANT(MIN_ROUNDS = N)
44 CRYPTOPP_CONSTANT(MAX_ROUNDS = M)
45 static unsigned int StaticGetDefaultRounds(
size_t keylength) {
return DEFAULT_ROUNDS;}
48 inline void ThrowIfInvalidRounds(
int rounds,
const Algorithm *alg)
50 if (rounds < MIN_ROUNDS || rounds > MAX_ROUNDS)
57 ThrowIfInvalidRounds(rounds, alg);
58 return (
unsigned int)rounds;
65 template <
unsigned int N,
unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE,
unsigned int IV_L = 0>
69 CRYPTOPP_CONSTANT(KEYLENGTH=N)
70 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N)
71 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=N)
72 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=N)
73 CRYPTOPP_CONSTANT(IV_REQUIREMENT = IV_REQ)
74 CRYPTOPP_CONSTANT(IV_LENGTH = IV_L)
75 static size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t) {
return KEYLENGTH;}
79 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>
83 CRYPTOPP_COMPILE_ASSERT(Q > 0);
84 CRYPTOPP_COMPILE_ASSERT(N % Q == 0);
85 CRYPTOPP_COMPILE_ASSERT(M % Q == 0);
86 CRYPTOPP_COMPILE_ASSERT(N < M);
87 CRYPTOPP_COMPILE_ASSERT(D >= N);
88 CRYPTOPP_COMPILE_ASSERT(M >= D);
91 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N)
92 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=M)
93 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=D)
94 CRYPTOPP_CONSTANT(KEYLENGTH_MULTIPLE=Q)
95 CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ)
96 CRYPTOPP_CONSTANT(IV_LENGTH=IV_L)
98 static size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t n)
100 if (n < (
size_t)MIN_KEYLENGTH)
101 return MIN_KEYLENGTH;
102 else if (n > (
size_t)MAX_KEYLENGTH)
103 return (
size_t)MAX_KEYLENGTH;
106 n += KEYLENGTH_MULTIPLE-1;
107 return n - n%KEYLENGTH_MULTIPLE;
113 template <
class T,
unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE,
unsigned int IV_L = 0>
117 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=T::MIN_KEYLENGTH)
118 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=T::MAX_KEYLENGTH)
119 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=T::DEFAULT_KEYLENGTH)
120 CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ)
121 CRYPTOPP_CONSTANT(IV_LENGTH=IV_L)
123 static size_t CRYPTOPP_API StaticGetValidKeyLength(
size_t keylength)
124 {
return T::StaticGetValidKeyLength(keylength);}
130 template <
class BASE,
class INFO = BASE>
134 size_t MinKeyLength()
const {
return INFO::MIN_KEYLENGTH;}
135 size_t MaxKeyLength()
const {
return (
size_t)INFO::MAX_KEYLENGTH;}
136 size_t DefaultKeyLength()
const {
return INFO::DEFAULT_KEYLENGTH;}
137 size_t GetValidKeyLength(
size_t n)
const {
return INFO::StaticGetValidKeyLength(n);}
138 SimpleKeyingInterface::IV_Requirement IVRequirement()
const {
return (SimpleKeyingInterface::IV_Requirement)INFO::IV_REQUIREMENT;}
139 unsigned int IVSize()
const {
return INFO::IV_LENGTH;}
142 template <
class INFO,
class BASE = BlockCipher>
146 unsigned int BlockSize()
const {
return this->BLOCKSIZE;}
150 template <CipherDir DIR,
class BASE>
156 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
158 {this->SetKey(key, length);}
160 {this->SetKeyWithRounds(key, length, rounds);}
162 bool IsForwardTransformation()
const {
return DIR == ENCRYPTION;}
166 template <
class BASE,
class INFO = BASE>
172 template <
class BASE>
178 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
180 {this->SetKey(key, length);}