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