Crypto++ 8.5 Free C++ class library of cryptographic schemes

seckey.h
Go to the documentation of this file.
1 // seckey.h - originally written and placed in the public domain by Wei Dai
2
3 /// \file seckey.h
4 /// \brief Classes and functions for implementing secret key algorithms.
5
6 #ifndef CRYPTOPP_SECKEY_H
7 #define CRYPTOPP_SECKEY_H
8
9 #include "config.h"
10 #include "cryptlib.h"
11 #include "misc.h"
12 #include "simple.h"
13 #include "stdcpp.h"
14
15 #if CRYPTOPP_MSC_VERSION
16 # pragma warning(push)
17 # pragma warning(disable: 4189 4296)
18 #endif
19
20 // Issue 340
21 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
22 # pragma GCC diagnostic push
23 # pragma GCC diagnostic ignored "-Wconversion"
24 # pragma GCC diagnostic ignored "-Wsign-conversion"
25 #endif
26
27 NAMESPACE_BEGIN(CryptoPP)
28
29 /// \brief Inverts the cipher's direction
30 /// \param dir the cipher's direction
31 /// \return DECRYPTION if \ref CipherDir "dir" is ENCRYPTION, DECRYPTION otherwise
32 inline CipherDir ReverseCipherDir(CipherDir dir)
33 {
34 return (dir == ENCRYPTION) ? DECRYPTION : ENCRYPTION;
35 }
36
37 /// \brief Inherited by algorithms with fixed block size
38 /// \tparam N the blocksize of the algorithm
39 template <unsigned int N>
40 class FixedBlockSize
41 {
42 public:
43 /// \brief The block size of the algorithm provided as a constant.
44 CRYPTOPP_CONSTANT(BLOCKSIZE = N);
45 };
46
47 // ************** rounds ***************
48
49 /// \brief Inherited by algorithms with fixed number of rounds
50 /// \tparam R the number of rounds used by the algorithm
51 template <unsigned int R>
52 class FixedRounds
53 {
54 public:
55 /// \brief The number of rounds for the algorithm provided as a constant.
56 CRYPTOPP_CONSTANT(ROUNDS = R);
57 };
58
59 /// \brief Inherited by algorithms with variable number of rounds
60 /// \tparam D Default number of rounds
61 /// \tparam N Minimum number of rounds
62 /// \tparam M Maximum number of rounds
63 template <unsigned int D, unsigned int N=1, unsigned int M=INT_MAX> // use INT_MAX here because enums are treated as signed ints
64 class VariableRounds
65 {
66 public:
67 /// \brief The default number of rounds for the algorithm provided as a constant.
68 CRYPTOPP_CONSTANT(DEFAULT_ROUNDS = D);
69 /// \brief The minimum number of rounds for the algorithm provided as a constant.
70 CRYPTOPP_CONSTANT(MIN_ROUNDS = N);
71 /// \brief The maximum number of rounds for the algorithm provided as a constant.
72 CRYPTOPP_CONSTANT(MAX_ROUNDS = M);
73 /// \brief The default number of rounds for the algorithm based on key length
74 /// provided by a static function.
75 /// \param keylength the size of the key, in bytes
76 /// \details keylength is unused in the default implementation.
77 CRYPTOPP_STATIC_CONSTEXPR unsigned int StaticGetDefaultRounds(size_t keylength)
78 {
79 return CRYPTOPP_UNUSED(keylength), static_cast<unsigned int>(DEFAULT_ROUNDS);
80 }
81
82 protected:
83 /// \brief Validates the number of rounds for an algorithm.
84 /// \param rounds the candidate number of rounds
85 /// \param alg an Algorithm object used if the number of rounds are invalid
86 /// \throw InvalidRounds if the number of rounds are invalid
87 /// \details ThrowIfInvalidRounds() validates the number of rounds and throws if invalid.
88 inline void ThrowIfInvalidRounds(int rounds, const Algorithm *alg)
89 {
90 if (M == INT_MAX) // Coverity and result_independent_of_operands
91 {
92 if (rounds < MIN_ROUNDS)
93 throw InvalidRounds(alg ? alg->AlgorithmName() : std::string("VariableRounds"), rounds);
94 }
95 else
96 {
97 if (rounds < MIN_ROUNDS || rounds > MAX_ROUNDS)
98 throw InvalidRounds(alg ? alg->AlgorithmName() : std::string("VariableRounds"), rounds);
99 }
100 }
101
102 /// \brief Validates the number of rounds for an algorithm
103 /// \param param the candidate number of rounds
104 /// \param alg an Algorithm object used if the number of rounds are invalid
105 /// \return the number of rounds for the algorithm
106 /// \throw InvalidRounds if the number of rounds are invalid
107 /// \details GetRoundsAndThrowIfInvalid() validates the number of rounds and throws if invalid.
108 inline unsigned int GetRoundsAndThrowIfInvalid(const NameValuePairs &param, const Algorithm *alg)
109 {
110 int rounds = param.GetIntValueWithDefault("Rounds", DEFAULT_ROUNDS);
111 ThrowIfInvalidRounds(rounds, alg);
112 return static_cast<unsigned int>(rounds);
113 }
114 };
115
116 // ************** key length ***************
117
118 /// \brief Inherited by keyed algorithms with fixed key length
119 /// \tparam N Default key length, in bytes
120 /// \tparam IV_REQ the \ref SimpleKeyingInterface::IV_Requirement "IV requirements"
121 /// \tparam IV_L default IV length, in bytes
122 /// \sa SimpleKeyingInterface
123 template <unsigned int N, unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE, unsigned int IV_L = 0>
124 class FixedKeyLength
125 {
126 public:
127 /// \brief The default key length used by the algorithm provided as a constant
128 /// \details KEYLENGTH is provided in bytes, not bits
129 CRYPTOPP_CONSTANT(KEYLENGTH=N);
130 /// \brief The minimum key length used by the algorithm provided as a constant
131 /// \details MIN_KEYLENGTH is provided in bytes, not bits
132 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N);
133 /// \brief The maximum key length used by the algorithm provided as a constant
134 /// \details MAX_KEYLENGTH is provided in bytes, not bits
135 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=N);
136 /// \brief The default key length used by the algorithm provided as a constant
137 /// \details DEFAULT_KEYLENGTH is provided in bytes, not bits
138 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=N);
139 /// \brief The default IV requirements for the algorithm provided as a constant
140 /// \details The default value is NOT_RESYNCHRONIZABLE. See IV_Requirement
141 /// in cryptlib.h for allowed values.
142 CRYPTOPP_CONSTANT(IV_REQUIREMENT = IV_REQ);
143 /// \brief The default IV length used by the algorithm provided as a constant
144 /// \details IV_LENGTH is provided in bytes, not bits. The default implementation uses 0.
145 CRYPTOPP_CONSTANT(IV_LENGTH = IV_L);
146 /// \brief The default key length for the algorithm provided by a static function.
147 /// \param keylength the size of the key, in bytes
148 /// \details The default implementation returns KEYLENGTH. keylength is unused
149 /// in the default implementation.
150 CRYPTOPP_STATIC_CONSTEXPR size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength)
151 {
152 return CRYPTOPP_UNUSED(keylength), static_cast<size_t>(KEYLENGTH);
153 }
154 };
155
156 /// \brief Inherited by keyed algorithms with variable key length
157 /// \tparam D Default key length, in bytes
158 /// \tparam N Minimum key length, in bytes
159 /// \tparam M Maximum key length, in bytes
160 /// \tparam Q Default key length multiple, in bytes. The default multiple is 1.
161 /// \tparam IV_REQ the \ref SimpleKeyingInterface::IV_Requirement "IV requirements"
162 /// \tparam IV_L default IV length, in bytes. The default length is 0.
163 /// \sa SimpleKeyingInterface
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>
165 class VariableKeyLength
166 {
167 // Make these private to avoid Doxygen documenting them in all derived classes
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);
174
175 public:
176 /// \brief The minimum key length used by the algorithm provided as a constant
177 /// \details MIN_KEYLENGTH is provided in bytes, not bits
178 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=N);
179 /// \brief The maximum key length used by the algorithm provided as a constant
180 /// \details MAX_KEYLENGTH is provided in bytes, not bits
181 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=M);
182 /// \brief The default key length used by the algorithm provided as a constant
183 /// \details DEFAULT_KEYLENGTH is provided in bytes, not bits
184 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=D);
185 /// \brief The key length multiple used by the algorithm provided as a constant
186 /// \details MAX_KEYLENGTH is provided in bytes, not bits
187 CRYPTOPP_CONSTANT(KEYLENGTH_MULTIPLE=Q);
188 /// \brief The default IV requirements for the algorithm provided as a constant
189 /// \details The default value is NOT_RESYNCHRONIZABLE. See IV_Requirement
190 /// in cryptlib.h for allowed values.
191 CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ);
192 /// \brief The default initialization vector length for the algorithm provided as a constant
193 /// \details IV_LENGTH is provided in bytes, not bits. The default implementation uses 0.
194 CRYPTOPP_CONSTANT(IV_LENGTH=IV_L);
195 /// \brief Provides a valid key length for the algorithm provided by a static function.
196 /// \param keylength the size of the key, in bytes
197 /// \details If keylength is less than MIN_KEYLENGTH, then the function returns
198 /// MIN_KEYLENGTH. If keylength is greater than MAX_KEYLENGTH, then the function
199 /// returns MAX_KEYLENGTH. If keylength is a multiple of KEYLENGTH_MULTIPLE,
200 /// then keylength is returned. Otherwise, the function returns keylength rounded
201 /// \a down to the next smaller multiple of KEYLENGTH_MULTIPLE.
202 /// \details keylength is provided in bytes, not bits.
203 CRYPTOPP_STATIC_CONSTEXPR size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength)
204 {
205 return (keylength <= N) ? N :
206 (keylength >= M) ? M :
207 (keylength+Q-1) - (keylength+Q-1)%Q;
208 }
209 };
210
211 /// \brief Provides key lengths based on another class's key length
212 /// \tparam T another FixedKeyLength or VariableKeyLength class
213 /// \tparam IV_REQ the \ref SimpleKeyingInterface::IV_Requirement "IV requirements"
214 /// \tparam IV_L default IV length, in bytes
215 /// \sa SimpleKeyingInterface
216 template <class T, unsigned int IV_REQ = SimpleKeyingInterface::NOT_RESYNCHRONIZABLE, unsigned int IV_L = 0>
217 class SameKeyLengthAs
218 {
219 public:
220 /// \brief The minimum key length used by the algorithm provided as a constant
221 /// \details MIN_KEYLENGTH is provided in bytes, not bits
222 CRYPTOPP_CONSTANT(MIN_KEYLENGTH=T::MIN_KEYLENGTH);
223 /// \brief The maximum key length used by the algorithm provided as a constant
224 /// \details MIN_KEYLENGTH is provided in bytes, not bits
225 CRYPTOPP_CONSTANT(MAX_KEYLENGTH=T::MAX_KEYLENGTH);
226 /// \brief The default key length used by the algorithm provided as a constant
227 /// \details MIN_KEYLENGTH is provided in bytes, not bits
228 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH=T::DEFAULT_KEYLENGTH);
229 /// \brief The default IV requirements for the algorithm provided as a constant
230 /// \details The default value is NOT_RESYNCHRONIZABLE. See IV_Requirement
231 /// in cryptlib.h for allowed values.
232 CRYPTOPP_CONSTANT(IV_REQUIREMENT=IV_REQ);
233 /// \brief The default initialization vector length for the algorithm provided as a constant
234 /// \details IV_LENGTH is provided in bytes, not bits. The default implementation uses 0.
235 CRYPTOPP_CONSTANT(IV_LENGTH=IV_L);
236 /// \brief Provides a valid key length for the algorithm provided by a static function.
237 /// \param keylength the size of the key, in bytes
238 /// \details If keylength is less than MIN_KEYLENGTH, then the function returns
239 /// MIN_KEYLENGTH. If keylength is greater than MAX_KEYLENGTH, then the function
240 /// returns MAX_KEYLENGTH. If keylength is a multiple of KEYLENGTH_MULTIPLE,
241 /// then keylength is returned. Otherwise, the function returns keylength rounded
242 /// \a down to the next smaller multiple of KEYLENGTH_MULTIPLE.
243 /// \details keylength is provided in bytes, not bits.
244 CRYPTOPP_STATIC_CONSTEXPR size_t CRYPTOPP_API StaticGetValidKeyLength(size_t keylength)
245 {return T::StaticGetValidKeyLength(keylength);}
246 };
247
248 // ************** implementation helper for SimpleKeyingInterface ***************
249
250 /// \brief Provides a base implementation of SimpleKeyingInterface
251 /// \tparam BASE a SimpleKeyingInterface derived class
252 /// \tparam INFO a SimpleKeyingInterface derived class
253 /// \details SimpleKeyingInterfaceImpl() provides a default implementation for ciphers providing a keying interface.
254 /// Functions are virtual and not eligible for C++11 <tt>constexpr</tt>-ness.
255 /// \sa Algorithm(), SimpleKeyingInterface()
256 template <class BASE, class INFO = BASE>
257 class CRYPTOPP_NO_VTABLE SimpleKeyingInterfaceImpl : public BASE
258 {
259 public:
260 /// \brief The minimum key length used by the algorithm
261 /// \return minimum key length used by the algorithm, in bytes
262 size_t MinKeyLength() const
263 {return INFO::MIN_KEYLENGTH;}
264
265 /// \brief The maximum key length used by the algorithm
266 /// \return maximum key length used by the algorithm, in bytes
267 size_t MaxKeyLength() const
268 {return static_cast<size_t>(INFO::MAX_KEYLENGTH);}
269
270 /// \brief The default key length used by the algorithm
271 /// \return default key length used by the algorithm, in bytes
272 size_t DefaultKeyLength() const
273 {return INFO::DEFAULT_KEYLENGTH;}
274
275 /// \brief Provides a valid key length for the algorithm
276 /// \param keylength the size of the key, in bytes
277 /// \return the valid key length, in bytes
278 /// \details keylength is provided in bytes, not bits. If keylength is less than MIN_KEYLENGTH,
279 /// then the function returns MIN_KEYLENGTH. If keylength is greater than MAX_KEYLENGTH,
280 /// then the function returns MAX_KEYLENGTH. if If keylength is a multiple of KEYLENGTH_MULTIPLE,
281 /// then keylength is returned. Otherwise, the function returns a \a lower multiple of
282 /// KEYLENGTH_MULTIPLE.
283 size_t GetValidKeyLength(size_t keylength) const {return INFO::StaticGetValidKeyLength(keylength);}
284
285 /// \brief The default IV requirements for the algorithm
286 /// \details The default value is NOT_RESYNCHRONIZABLE. See IV_Requirement
287 /// in cryptlib.h for allowed values.
288 SimpleKeyingInterface::IV_Requirement IVRequirement() const
289 {return static_cast<SimpleKeyingInterface::IV_Requirement>(INFO::IV_REQUIREMENT);}
290
291 /// \brief The initialization vector length for the algorithm
292 /// \details IVSize is provided in bytes, not bits. The default implementation uses
293 /// IV_LENGTH, which is 0.
294 unsigned int IVSize() const
295 {return INFO::IV_LENGTH;}
296 };
297
298 /// \brief Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers
299 /// \tparam INFO a SimpleKeyingInterface derived class
300 /// \tparam BASE a SimpleKeyingInterface derived class
301 /// \details BlockCipherImpl() provides a default implementation for block ciphers using AlgorithmImpl()
302 /// and SimpleKeyingInterfaceImpl(). Functions are virtual and not eligible for C++11 <tt>constexpr</tt>-ness.
303 /// \sa Algorithm(), SimpleKeyingInterface(), AlgorithmImpl(), SimpleKeyingInterfaceImpl()
304 template <class INFO, class BASE = BlockCipher>
305 class CRYPTOPP_NO_VTABLE BlockCipherImpl : public AlgorithmImpl<SimpleKeyingInterfaceImpl<TwoBases<BASE, INFO> > >
306 {
307 public:
308 /// Provides the block size of the algorithm
309 /// \return the block size of the algorithm, in bytes
310 unsigned int BlockSize() const {return this->BLOCKSIZE;}
311 };
312
313 /// \brief Provides class member functions to key a block cipher
314 /// \tparam DIR a CipherDir
315 /// \tparam BASE a BlockCipherImpl derived class
316 template <CipherDir DIR, class BASE>
317 class BlockCipherFinal : public ClonableImpl<BlockCipherFinal<DIR, BASE>, BASE>
318 {
319 public:
320 /// \brief Construct a default BlockCipherFinal
321 /// \details The cipher is not keyed.
322 BlockCipherFinal() {}
323
324 /// \brief Construct a BlockCipherFinal
325 /// \param key a byte array used to key the cipher
326 /// \details key must be at least DEFAULT_KEYLENGTH in length. Internally, the function calls
327 /// SimpleKeyingInterface::SetKey.
328 BlockCipherFinal(const byte *key)
329 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
330
331 /// \brief Construct a BlockCipherFinal
332 /// \param key a byte array used to key the cipher
333 /// \param length the length of the byte array
334 /// \details key must be at least DEFAULT_KEYLENGTH in length. Internally, the function calls
335 /// SimpleKeyingInterface::SetKey.
336 BlockCipherFinal(const byte *key, size_t length)
337 {this->SetKey(key, length);}
338
339 /// \brief Construct a BlockCipherFinal
340 /// \param key a byte array used to key the cipher
341 /// \param length the length of the byte array
342 /// \param rounds the number of rounds
343 /// \details key must be at least DEFAULT_KEYLENGTH in length. Internally, the function calls
344 /// SimpleKeyingInterface::SetKeyWithRounds.
345 BlockCipherFinal(const byte *key, size_t length, unsigned int rounds)
346 {this->SetKeyWithRounds(key, length, rounds);}
347
348 /// \brief Provides the direction of the cipher
349 /// \return true if DIR is ENCRYPTION, false otherwise
350 /// \sa GetCipherDirection(), IsPermutation()
351 bool IsForwardTransformation() const {return DIR == ENCRYPTION;}
352 };
353
354 /// \brief Provides a base implementation of Algorithm and SimpleKeyingInterface for message authentication codes
355 /// \tparam INFO a SimpleKeyingInterface derived class
356 /// \tparam BASE a SimpleKeyingInterface derived class
357 /// \details MessageAuthenticationCodeImpl() provides a default implementation for message authentication codes
358 /// using AlgorithmImpl() and SimpleKeyingInterfaceImpl(). Functions are virtual and not subject to C++11
359 /// <tt>constexpr</tt>.
360 /// \sa Algorithm(), SimpleKeyingInterface(), AlgorithmImpl(), SimpleKeyingInterfaceImpl()
361 template <class BASE, class INFO = BASE>
362 class MessageAuthenticationCodeImpl : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BASE, INFO>, INFO>
363 {
364 };
365
366 /// \brief Provides class member functions to key a message authentication code
367 /// \tparam BASE a BlockCipherImpl derived class
368 /// \details A default implementation for MessageAuthenticationCode
369 template <class BASE>
370 class MessageAuthenticationCodeFinal : public ClonableImpl<MessageAuthenticationCodeFinal<BASE>, MessageAuthenticationCodeImpl<BASE> >
371 {
372 public:
373 /// \brief Construct a default MessageAuthenticationCodeFinal
374 /// \details The message authentication code is not keyed.
375 MessageAuthenticationCodeFinal() {}
376 /// \brief Construct a BlockCipherFinal
377 /// \param key a byte array used to key the algorithm
378 /// \details key must be at least DEFAULT_KEYLENGTH in length. Internally, the function calls
379 /// SimpleKeyingInterface::SetKey.
380 MessageAuthenticationCodeFinal(const byte *key)
381 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
382 /// \brief Construct a BlockCipherFinal
383 /// \param key a byte array used to key the algorithm
384 /// \param length the length of the byte array
385 /// \details key must be at least DEFAULT_KEYLENGTH in length. Internally, the function calls
386 /// SimpleKeyingInterface::SetKey.
387 MessageAuthenticationCodeFinal(const byte *key, size_t length)
388 {this->SetKey(key, length);}
389 };
390
391 // ************** documentation ***************
392
393 /// \brief Provides Encryption and Decryption typedefs used by derived classes to
394 /// implement a block cipher
395 /// \details These objects usually should not be used directly. See CipherModeDocumentation
396 /// instead. Each class derived from this one defines two types, Encryption and Decryption,
397 /// both of which implement the BlockCipher interface.
398 struct BlockCipherDocumentation
399 {
400 /// implements the BlockCipher interface
401 typedef BlockCipher Encryption;
402 /// implements the BlockCipher interface
403 typedef BlockCipher Decryption;
404 };
405
406 /// \brief Provides Encryption and Decryption typedefs used by derived classes to
407 /// implement a symmetric cipher
408 /// \details Each class derived from this one defines two types, Encryption and Decryption,
409 /// both of which implement the SymmetricCipher interface. Two types of classes derive
410 /// from this class: stream ciphers and block cipher modes. Stream ciphers can be used
411 /// alone, cipher mode classes need to be used with a block cipher. See CipherModeDocumentation
412 /// for more for information about using cipher modes and block ciphers.
413 struct SymmetricCipherDocumentation
414 {
415 /// implements the SymmetricCipher interface
416 typedef SymmetricCipher Encryption;
417 /// implements the SymmetricCipher interface
418 typedef SymmetricCipher Decryption;
419 };
420
421 /// \brief Provides Encryption and Decryption typedefs used by derived classes to
422 /// implement an authenticated encryption cipher
423 /// \details Each class derived from this one defines two types, Encryption and Decryption,
424 /// both of which implement the AuthenticatedSymmetricCipher interface.
425 struct AuthenticatedSymmetricCipherDocumentation
426 {
427 /// implements the AuthenticatedSymmetricCipher interface
428 typedef AuthenticatedSymmetricCipher Encryption;
429 /// implements the AuthenticatedSymmetricCipher interface
430 typedef AuthenticatedSymmetricCipher Decryption;
431 };
432
433 NAMESPACE_END
434
435 #if CRYPTOPP_MSC_VERSION
436 # pragma warning(pop)
437 #endif
438
439 // Issue 340
440 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
441 # pragma GCC diagnostic pop
442 #endif
443
444 #endif
BlockCipherDocumentation::Encryption
BlockCipher Encryption
implements the BlockCipher interface
Definition: seckey.h:401
AuthenticatedSymmetricCipherDocumentation::Encryption
AuthenticatedSymmetricCipher Encryption
implements the AuthenticatedSymmetricCipher interface
Definition: seckey.h:428
Algorithm::AlgorithmName
virtual std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: cryptlib.h:619
SimpleKeyingInterfaceImpl::MinKeyLength
size_t MinKeyLength() const
The minimum key length used by the algorithm.
Definition: seckey.h:262
SimpleKeyingInterfaceImpl
Provides a base implementation of SimpleKeyingInterface.
Definition: seckey.h:257
SimpleKeyingInterfaceImpl::DefaultKeyLength
size_t DefaultKeyLength() const
The default key length used by the algorithm.
Definition: seckey.h:272
SymmetricCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher.
Definition: seckey.h:413
MessageAuthenticationCodeFinal::MessageAuthenticationCodeFinal
MessageAuthenticationCodeFinal()
Construct a default MessageAuthenticationCodeFinal.
Definition: seckey.h:375
VariableKeyLength::KEYLENGTH_MULTIPLE
static const int KEYLENGTH_MULTIPLE
The key length multiple used by the algorithm provided as a constant.
Definition: seckey.h:187
DECRYPTION
@ DECRYPTION
the cipher is performing decryption
Definition: cryptlib.h:127
SameKeyLengthAs::DEFAULT_KEYLENGTH
static const int DEFAULT_KEYLENGTH
The default key length used by the algorithm provided as a constant.
Definition: seckey.h:228
Algorithm
Interface for all crypto algorithms.
Definition: cryptlib.h:598
SimpleKeyingInterfaceImpl::IVRequirement
SimpleKeyingInterface::IV_Requirement IVRequirement() const
The default IV requirements for the algorithm.
Definition: seckey.h:288
SymmetricCipher
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode.
Definition: cryptlib.h:1290
AuthenticatedSymmetricCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement an authenticated enc...
Definition: seckey.h:425
BlockCipherFinal::BlockCipherFinal
BlockCipherFinal(const byte *key, size_t length, unsigned int rounds)
Construct a BlockCipherFinal.
Definition: seckey.h:345
BlockCipherDocumentation::Decryption
BlockCipher Decryption
implements the BlockCipher interface
Definition: seckey.h:403
ENCRYPTION
@ ENCRYPTION
the cipher is performing encryption
Definition: cryptlib.h:125
FixedKeyLength::KEYLENGTH
static const int KEYLENGTH
The default key length used by the algorithm provided as a constant.
Definition: seckey.h:129
FixedKeyLength::DEFAULT_KEYLENGTH
static const int DEFAULT_KEYLENGTH
The default key length used by the algorithm provided as a constant.
Definition: seckey.h:138
CRYPTOPP_COMPILE_ASSERT
#define CRYPTOPP_COMPILE_ASSERT(expr)
Compile time assertion.
Definition: misc.h:149
VariableKeyLength::IV_REQUIREMENT
static const int IV_REQUIREMENT
The default IV requirements for the algorithm provided as a constant.
Definition: seckey.h:191
FixedKeyLength::StaticGetValidKeyLength
static size_t StaticGetValidKeyLength(size_t keylength)
The default key length for the algorithm provided by a static function.
Definition: seckey.h:150
VariableRounds::MIN_ROUNDS
static const int MIN_ROUNDS
The minimum number of rounds for the algorithm provided as a constant.
Definition: seckey.h:70
FixedKeyLength::MIN_KEYLENGTH
static const int MIN_KEYLENGTH
The minimum key length used by the algorithm provided as a constant.
Definition: seckey.h:132
FixedBlockSize
Inherited by algorithms with fixed block size.
Definition: seckey.h:40
VariableRounds::DEFAULT_ROUNDS
static const int DEFAULT_ROUNDS
The default number of rounds for the algorithm provided as a constant.
Definition: seckey.h:68
MessageAuthenticationCodeFinal::MessageAuthenticationCodeFinal
MessageAuthenticationCodeFinal(const byte *key)
Construct a BlockCipherFinal.
Definition: seckey.h:380
ReverseCipherDir
CipherDir ReverseCipherDir(CipherDir dir)
Inverts the cipher's direction.
Definition: seckey.h:32
SimpleKeyingInterfaceImpl::MaxKeyLength
size_t MaxKeyLength() const
The maximum key length used by the algorithm.
Definition: seckey.h:267
BlockCipherImpl::BlockSize
unsigned int BlockSize() const
Provides the block size of the algorithm.
Definition: seckey.h:310
CipherDir
CipherDir
Specifies a direction for a cipher to operate.
Definition: cryptlib.h:123
simple.h
Classes providing basic library services.
SimpleKeyingInterface::IV_Requirement
IV_Requirement
Secure IVs requirements as enumerated values.
Definition: cryptlib.h:719
FixedRounds::ROUNDS
static const int ROUNDS
The number of rounds for the algorithm provided as a constant.
Definition: seckey.h:56
SameKeyLengthAs::IV_LENGTH
static const int IV_LENGTH
The default initialization vector length for the algorithm provided as a constant.
Definition: seckey.h:235
BlockCipherImpl
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:305
FixedKeyLength
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:124
misc.h
Utility functions for the Crypto++ library.
VariableRounds::StaticGetDefaultRounds
static unsigned int StaticGetDefaultRounds(size_t keylength)
The default number of rounds for the algorithm based on key length provided by a static function.
Definition: seckey.h:77
VariableKeyLength::IV_LENGTH
static const int IV_LENGTH
The default initialization vector length for the algorithm provided as a constant.
Definition: seckey.h:194
SameKeyLengthAs
Provides key lengths based on another class's key length.
Definition: seckey.h:217
InvalidRounds
Exception thrown when an invalid number of rounds is encountered.
Definition: simple.h:65
BlockCipherFinal::BlockCipherFinal
BlockCipherFinal(const byte *key, size_t length)
Construct a BlockCipherFinal.
Definition: seckey.h:336
BlockCipherFinal::BlockCipherFinal
BlockCipherFinal(const byte *key)
Construct a BlockCipherFinal.
Definition: seckey.h:328
VariableKeyLength::MIN_KEYLENGTH
static const int MIN_KEYLENGTH
The minimum key length used by the algorithm provided as a constant.
Definition: seckey.h:178
stdcpp.h
Common C++ header files.
VariableRounds::MAX_ROUNDS
static const int MAX_ROUNDS
The maximum number of rounds for the algorithm provided as a constant.
Definition: seckey.h:72
FixedBlockSize::BLOCKSIZE
static const int BLOCKSIZE
The block size of the algorithm provided as a constant.
Definition: seckey.h:44
SameKeyLengthAs::MAX_KEYLENGTH
static const int MAX_KEYLENGTH
The maximum key length used by the algorithm provided as a constant.
Definition: seckey.h:225
BlockCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher.
Definition: seckey.h:398
BlockCipherFinal
Provides class member functions to key a block cipher.
Definition: seckey.h:317
SimpleKeyingInterfaceImpl::GetValidKeyLength
size_t GetValidKeyLength(size_t keylength) const
Provides a valid key length for the algorithm.
Definition: seckey.h:283
MessageAuthenticationCodeImpl
Provides a base implementation of Algorithm and SimpleKeyingInterface for message authentication code...
Definition: seckey.h:362
SameKeyLengthAs::StaticGetValidKeyLength
static size_t StaticGetValidKeyLength(size_t keylength)
Provides a valid key length for the algorithm provided by a static function.
Definition: seckey.h:244
FixedKeyLength::IV_REQUIREMENT
static const int IV_REQUIREMENT
The default IV requirements for the algorithm provided as a constant.
Definition: seckey.h:142
SimpleKeyingInterfaceImpl::IVSize
unsigned int IVSize() const
The initialization vector length for the algorithm.
Definition: seckey.h:294
VariableKeyLength::MAX_KEYLENGTH
static const int MAX_KEYLENGTH
The maximum key length used by the algorithm provided as a constant.
Definition: seckey.h:181
ClonableImpl
Base class for identifying alogorithm.
Definition: simple.h:25
CryptoPP
Crypto++ library namespace.
CRYPTOPP_API
#define CRYPTOPP_API
Win32 calling convention.
Definition: config_dll.h:119
VariableKeyLength::DEFAULT_KEYLENGTH
static const int DEFAULT_KEYLENGTH
The default key length used by the algorithm provided as a constant.
Definition: seckey.h:184
config.h
Library configuration file.
BlockCipherFinal::IsForwardTransformation
bool IsForwardTransformation() const
Provides the direction of the cipher.
Definition: seckey.h:351
BlockCipher
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1282
BlockCipherFinal::BlockCipherFinal
BlockCipherFinal()
Construct a default BlockCipherFinal.
Definition: seckey.h:322
VariableKeyLength::StaticGetValidKeyLength
static size_t StaticGetValidKeyLength(size_t keylength)
Provides a valid key length for the algorithm provided by a static function.
Definition: seckey.h:203
SymmetricCipherDocumentation::Encryption
SymmetricCipher Encryption
implements the SymmetricCipher interface
Definition: seckey.h:416
FixedKeyLength::IV_LENGTH
static const int IV_LENGTH
The default IV length used by the algorithm provided as a constant.
Definition: seckey.h:145
FixedKeyLength::MAX_KEYLENGTH
static const int MAX_KEYLENGTH
The maximum key length used by the algorithm provided as a constant.
Definition: seckey.h:135
NameValuePairs::GetIntValueWithDefault
CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
Definition: cryptlib.h:424
MessageAuthenticationCodeFinal
Provides class member functions to key a message authentication code.
Definition: seckey.h:370
VariableRounds
Inherited by algorithms with variable number of rounds.
Definition: seckey.h:64
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:321
cryptlib.h
Abstract base classes that provide a uniform interface to this library.
FixedRounds
Inherited by algorithms with fixed number of rounds.
Definition: seckey.h:52
AuthenticatedSymmetricCipherDocumentation::Decryption
AuthenticatedSymmetricCipher Decryption
implements the AuthenticatedSymmetricCipher interface
Definition: seckey.h:430
SameKeyLengthAs::IV_REQUIREMENT
static const int IV_REQUIREMENT
The default IV requirements for the algorithm provided as a constant.
Definition: seckey.h:232
MessageAuthenticationCodeFinal::MessageAuthenticationCodeFinal
MessageAuthenticationCodeFinal(const byte *key, size_t length)
Construct a BlockCipherFinal.
Definition: seckey.h:387
AlgorithmImpl
Base class information.
Definition: simple.h:39
SymmetricCipherDocumentation::Decryption
SymmetricCipher Decryption
implements the SymmetricCipher interface
Definition: seckey.h:418
SameKeyLengthAs::MIN_KEYLENGTH
static const int MIN_KEYLENGTH
The minimum key length used by the algorithm provided as a constant.
Definition: seckey.h:222
AuthenticatedSymmetricCipher
Interface for authenticated encryption modes of operation.
Definition: cryptlib.h:1320
VariableKeyLength
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:165