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