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