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