Crypto++  7.0
Free C++ class library of cryptographic schemes
modes.h
Go to the documentation of this file.
1 // modes.h - originally written and placed in the public domain by Wei Dai
2 
3 /// \file modes.h
4 /// \brief Classes for block cipher modes of operation
5 
6 #ifndef CRYPTOPP_MODES_H
7 #define CRYPTOPP_MODES_H
8 
9 #include "cryptlib.h"
10 #include "secblock.h"
11 #include "misc.h"
12 #include "strciphr.h"
13 #include "argnames.h"
14 #include "algparam.h"
15 
16 // Issue 340
17 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
18 # pragma GCC diagnostic push
19 # pragma GCC diagnostic ignored "-Wconversion"
20 # pragma GCC diagnostic ignored "-Wsign-conversion"
21 #endif
22 
23 #if CRYPTOPP_MSC_VERSION
24 # pragma warning(push)
25 # pragma warning(disable: 4231 4275)
26 # if (CRYPTOPP_MSC_VERSION >= 1400)
27 # pragma warning(disable: 6011 6386 28193)
28 # endif
29 #endif
30 
31 NAMESPACE_BEGIN(CryptoPP)
32 
33 /// \brief Block cipher mode of operation information
34 /// \details Each class derived from this one defines two types, Encryption and Decryption,
35 /// both of which implement the SymmetricCipher interface.
36 /// For each mode there are two classes, one of which is a template class,
37 /// and the other one has a name that ends in "_ExternalCipher".
38 /// The "external cipher" mode objects hold a reference to the underlying block cipher,
39 /// instead of holding an instance of it. The reference must be passed in to the constructor.
40 /// For the "cipher holder" classes, the CIPHER template parameter should be a class
41 /// derived from BlockCipherDocumentation, for example DES or AES.
42 /// \details See NIST SP 800-38A for definitions of these modes. See
43 /// AuthenticatedSymmetricCipherDocumentation for authenticated encryption modes.
45 {
46 };
47 
48 /// \brief Block cipher mode of operation information
49 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CipherModeBase : public SymmetricCipher
50 {
51 public:
52  virtual ~CipherModeBase() {}
53 
54  // Algorithm class
55  std::string AlgorithmProvider() const {
56  return m_cipher != NULLPTR ? m_cipher->AlgorithmProvider() : "C++";
57  }
58 
59  /// \brief Returns smallest valid key length
60  /// \returns the minimum key length, in bytes
61  size_t MinKeyLength() const {return m_cipher->MinKeyLength();}
62 
63  /// \brief Returns largest valid key length
64  /// \returns the maximum key length, in bytes
65  size_t MaxKeyLength() const {return m_cipher->MaxKeyLength();}
66 
67  /// \brief Returns default key length
68  /// \returns the default key length, in bytes
69  size_t DefaultKeyLength() const {return m_cipher->DefaultKeyLength();}
70 
71  /// \brief Returns a valid key length for the algorithm
72  /// \param keylength the size of the key, in bytes
73  /// \returns the valid key length, in bytes
74  /// \details keylength is provided in bytes, not bits. If keylength is less than MIN_KEYLENGTH,
75  /// then the function returns MIN_KEYLENGTH. If keylength is greater than MAX_KEYLENGTH,
76  /// then the function returns MAX_KEYLENGTH. if If keylength is a multiple of KEYLENGTH_MULTIPLE,
77  /// then keylength is returned. Otherwise, the function returns a \a lower multiple of
78  /// KEYLENGTH_MULTIPLE.
79  size_t GetValidKeyLength(size_t keylength) const {return m_cipher->GetValidKeyLength(keylength);}
80 
81  /// \brief Returns whether keylength is a valid key length
82  /// \param keylength the requested keylength
83  /// \return true if keylength is valid, false otherwise
84  /// \details Internally the function calls GetValidKeyLength()
85  bool IsValidKeyLength(size_t keylength) const {return m_cipher->IsValidKeyLength(keylength);}
86 
87  /// \brief Provides input and output data alignment for optimal performance.
88  /// \return the input data alignment that provides optimal performance
89  /// \sa GetAlignment() and OptimalBlockSize()
90  unsigned int OptimalDataAlignment() const {return m_cipher->OptimalDataAlignment();}
91 
92  /// \brief Returns length of the IV accepted by this object
93  /// \return the size of an IV, in bytes
94  /// \throws NotImplemented() if the object does not support resynchronization
95  /// \details The default implementation throws NotImplemented
96  unsigned int IVSize() const {return BlockSize();}
97 
98  /// \brief Minimal requirement for secure IVs
99  /// \return the secure IV requirement of the algorithm
100  virtual IV_Requirement IVRequirement() const =0;
101 
102  /// \brief Set external block cipher
103  /// \param cipher An external block cipher
104  /// \details The cipher should be keyed.
105  void SetCipher(BlockCipher &cipher)
106  {
107  this->ThrowIfResynchronizable();
108  this->m_cipher = &cipher;
109  this->ResizeBuffers();
110  }
111 
112  /// \brief Set external block cipher and IV
113  /// \param cipher An external block cipher
114  /// \param iv a byte array used to resynchronize the cipher
115  /// \param feedbackSize the feedback size, in bytes
116  /// \details The cipher should be keyed.
117  void SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize = 0)
118  {
119  this->ThrowIfInvalidIV(iv);
120  this->m_cipher = &cipher;
121  this->ResizeBuffers();
122  this->SetFeedbackSize(feedbackSize);
123  if (this->IsResynchronizable())
124  this->Resynchronize(iv);
125  }
126 
127 protected:
128  CipherModeBase() : m_cipher(NULLPTR) {}
129  inline unsigned int BlockSize() const
130  {
131  CRYPTOPP_ASSERT(m_register.size() > 0);
132  return static_cast<unsigned int>(m_register.size());
133  }
134  virtual void SetFeedbackSize(unsigned int feedbackSize)
135  {
136  if (!(feedbackSize == 0 || feedbackSize == BlockSize()))
137  throw InvalidArgument("CipherModeBase: feedback size cannot be specified for this cipher mode");
138  }
139 
140  virtual void ResizeBuffers();
141 
142  BlockCipher *m_cipher;
143  SecByteBlock m_register;
144 };
145 
146 /// \brief Block cipher mode of operation common operations
147 /// \tparam POLICY_INTERFACE common operations
148 template <class POLICY_INTERFACE>
149 class CRYPTOPP_NO_VTABLE ModePolicyCommonTemplate : public CipherModeBase, public POLICY_INTERFACE
150 {
151  unsigned int GetAlignment() const {return m_cipher->OptimalDataAlignment();}
152  void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
153 };
154 
155 template <class POLICY_INTERFACE>
156 void ModePolicyCommonTemplate<POLICY_INTERFACE>::CipherSetKey(const NameValuePairs &params, const byte *key, size_t length)
157 {
158  m_cipher->SetKey(key, length, params);
159  ResizeBuffers();
160  int feedbackSize = params.GetIntValueWithDefault(Name::FeedbackSize(), 0);
161  SetFeedbackSize(feedbackSize);
162 }
163 
164 /// \brief CFB block cipher mode of operation
165 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CFB_ModePolicy : public ModePolicyCommonTemplate<CFB_CipherAbstractPolicy>
166 {
167 public:
168  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CFB";}
169 
170  virtual ~CFB_ModePolicy() {}
171  CFB_ModePolicy() : m_feedbackSize(0) {}
173 
174 protected:
175  unsigned int GetBytesPerIteration() const {return m_feedbackSize;}
176  bool CanIterate() const {return m_feedbackSize == BlockSize();}
177  void Iterate(byte *output, const byte *input, CipherDir dir, size_t iterationCount);
178  void TransformRegister();
179  void CipherResynchronize(const byte *iv, size_t length);
180  void SetFeedbackSize(unsigned int feedbackSize);
181  void ResizeBuffers();
182  byte * GetRegisterBegin();
183 
184  SecByteBlock m_temp;
185  unsigned int m_feedbackSize;
186 };
187 
188 /// \brief Initialize a block of memory
189 /// \param dest the destination block of memory
190 /// \param dsize the size of the destination block, in bytes
191 /// \param src the source block of memory
192 /// \param ssize the size of the source block, in bytes
193 /// \details CopyOrZero copies ssize bytes from source to destination if
194 /// src is not NULL. If src is NULL then dest is zero'd. Bounds are not
195 /// checked at runtime. Debug builds assert if ssize exceeds dsize.
196 inline void CopyOrZero(void *dest, size_t dsize, const void *src, size_t ssize)
197 {
198  CRYPTOPP_ASSERT(dest);
199  CRYPTOPP_ASSERT(dsize >= ssize);
200 
201  if (src != NULLPTR)
202  memcpy_s(dest, dsize, src, ssize);
203  else
204  memset(dest, 0, dsize);
205 }
206 
207 /// \brief OFB block cipher mode of operation
208 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE OFB_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy>
209 {
210 public:
211  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "OFB";}
212 
213  bool CipherIsRandomAccess() const {return false;}
215 
216 protected:
217  unsigned int GetBytesPerIteration() const {return BlockSize();}
218  unsigned int GetIterationsToBuffer() const {return m_cipher->OptimalNumberOfParallelBlocks();}
219  void WriteKeystream(byte *keystreamBuffer, size_t iterationCount);
220  void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length);
221 };
222 
223 /// \brief CTR block cipher mode of operation
224 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CTR_ModePolicy : public ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy>
225 {
226 public:
227  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CTR";}
228 
229  virtual ~CTR_ModePolicy() {}
230  bool CipherIsRandomAccess() const {return true;}
232 
233 protected:
234  virtual void IncrementCounterBy256();
235  unsigned int GetAlignment() const {return m_cipher->OptimalDataAlignment();}
236  unsigned int GetBytesPerIteration() const {return BlockSize();}
237  unsigned int GetIterationsToBuffer() const {return m_cipher->OptimalNumberOfParallelBlocks();}
238  void WriteKeystream(byte *buffer, size_t iterationCount)
239  {OperateKeystream(WRITE_KEYSTREAM, buffer, NULLPTR, iterationCount);}
240  bool CanOperateKeystream() const {return true;}
241  void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
242  void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length);
243  void SeekToIteration(lword iterationCount);
244 
245  SecByteBlock m_counterArray;
246 };
247 
248 /// \brief Block cipher mode of operation default implementation
249 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public CipherModeBase
250 {
251 public:
252  virtual ~BlockOrientedCipherModeBase() {}
253  void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
254  unsigned int MandatoryBlockSize() const {return BlockSize();}
255  bool IsRandomAccess() const {return false;}
256  bool IsSelfInverting() const {return false;}
257  bool IsForwardTransformation() const {return m_cipher->IsForwardTransformation();}
258  void Resynchronize(const byte *iv, int length=-1) {memcpy_s(m_register, m_register.size(), iv, ThrowIfInvalidIVLength(length));}
259 
260 protected:
261  bool RequireAlignedInput() const {return true;}
262  virtual void ResizeBuffers();
263 
264  SecByteBlock m_buffer;
265 };
266 
267 /// \brief ECB block cipher mode of operation default implementation
268 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE ECB_OneWay : public BlockOrientedCipherModeBase
269 {
270 public:
271  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "ECB";}
272 
273  void SetKey(const byte *key, size_t length, const NameValuePairs &params = g_nullNameValuePairs)
274  {m_cipher->SetKey(key, length, params); BlockOrientedCipherModeBase::ResizeBuffers();}
276  unsigned int OptimalBlockSize() const {return static_cast<unsigned int>(BlockSize() * m_cipher->OptimalNumberOfParallelBlocks());}
277  void ProcessData(byte *outString, const byte *inString, size_t length);
278 };
279 
280 /// \brief CBC block cipher mode of operation default implementation
281 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_ModeBase : public BlockOrientedCipherModeBase
282 {
283 public:
284  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CBC";}
285 
287  bool RequireAlignedInput() const {return false;}
288  unsigned int MinLastBlockSize() const {return 0;}
289 };
290 
291 /// \brief CBC block cipher mode of operation encryption operation
292 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Encryption : public CBC_ModeBase
293 {
294 public:
295  void ProcessData(byte *outString, const byte *inString, size_t length);
296 };
297 
298 /// \brief CBC-CTS block cipher mode of operation encryption operation
299 /// \since Crypto++ 3.0
300 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Encryption : public CBC_Encryption
301 {
302 public:
303  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "CBC/CTS";}
304 
305  void SetStolenIV(byte *iv) {m_stolenIV = iv;}
306  unsigned int MinLastBlockSize() const {return BlockSize()+1;}
307  size_t ProcessLastBlock(byte *outString, size_t outLength, const byte *inString, size_t inLength);
308 
309 protected:
310  void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
311  {
312  CBC_Encryption::UncheckedSetKey(key, length, params);
313  m_stolenIV = params.GetValueWithDefault(Name::StolenIV(), static_cast<byte *>(NULLPTR));
314  }
315 
316  byte *m_stolenIV;
317 };
318 
319 /// \brief CBC block cipher mode of operation decryption operation
320 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_Decryption : public CBC_ModeBase
321 {
322 public:
323  virtual ~CBC_Decryption() {}
324  void ProcessData(byte *outString, const byte *inString, size_t length);
325 
326 protected:
327  virtual void ResizeBuffers();
328 
329  SecByteBlock m_temp;
330 };
331 
332 /// \brief CBC-CTS block cipher mode of operation decryption operation
333 /// \since Crypto++ 3.0
334 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Decryption : public CBC_Decryption
335 {
336 public:
337  unsigned int MinLastBlockSize() const {return BlockSize()+1;}
338  size_t ProcessLastBlock(byte *outString, size_t outLength, const byte *inString, size_t inLength);
339 };
340 
341 /// \brief Block cipher mode of operation aggregate
342 template <class CIPHER, class BASE>
343 class CipherModeFinalTemplate_CipherHolder : protected ObjectHolder<CIPHER>, public AlgorithmImpl<BASE, CipherModeFinalTemplate_CipherHolder<CIPHER, BASE> >
344 {
345 public:
346  /// \brief Provides the name of this algorithm
347  /// \return the standard algorithm name
348  /// \details The standard algorithm name can be a name like \a AES or \a AES/GCM. Some algorithms
349  /// do not have standard names yet. For example, there is no standard algorithm name for
350  /// Shoup's ECIES.
351  static std::string CRYPTOPP_API StaticAlgorithmName()
352  {return CIPHER::StaticAlgorithmName() + "/" + BASE::StaticAlgorithmName();}
353 
354  /// \brief Construct a CipherModeFinalTemplate
356  {
357  this->m_cipher = &this->m_object;
358  this->ResizeBuffers();
359  }
360 
361  /// \brief Construct a CipherModeFinalTemplate
362  /// \param key a byte array used to key the cipher
363  /// \details key must be at least DEFAULT_KEYLENGTH in length. Internally, the function calls
364  /// SimpleKeyingInterface::SetKey.
365  CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length)
366  {
367  this->m_cipher = &this->m_object;
368  this->SetKey(key, length);
369  }
370 
371  /// \brief Construct a CipherModeFinalTemplate
372  /// \param key a byte array used to key the cipher
373  /// \param iv a byte array used to resynchronize the cipher
374  /// \details key must be at least DEFAULT_KEYLENGTH in length. iv must be IVSize() or
375  /// BLOCKSIZE in length. Internally, the function calls SimpleKeyingInterface::SetKey.
376  CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length, const byte *iv)
377  {
378  this->m_cipher = &this->m_object;
379  this->SetKey(key, length, MakeParameters(Name::IV(), ConstByteArrayParameter(iv, this->m_cipher->BlockSize())));
380  }
381 
382  /// \brief Construct a CipherModeFinalTemplate
383  /// \param key a byte array used to key the cipher
384  /// \param iv a byte array used to resynchronize the cipher
385  /// \param feedbackSize the feedback size, in bytes
386  /// \details key must be at least DEFAULT_KEYLENGTH in length. iv must be IVSize() or
387  /// BLOCKSIZE in length. Internally, the function calls SimpleKeyingInterface::SetKey.
388  CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length, const byte *iv, int feedbackSize)
389  {
390  this->m_cipher = &this->m_object;
391  this->SetKey(key, length, MakeParameters(Name::IV(), ConstByteArrayParameter(iv, this->m_cipher->BlockSize()))(Name::FeedbackSize(), feedbackSize));
392  }
393 
394  // Algorithm class
395  std::string AlgorithmProvider() const {
396  return this->m_cipher->AlgorithmProvider();
397  }
398 };
399 
400 /// \tparam BASE CipherModeFinalTemplate_CipherHolder base class
401 /// \details Base class for external mode cipher combinations
402 template <class BASE>
404 {
405 public:
406  /// \brief Construct a default CipherModeFinalTemplate
407  /// \details The cipher is not keyed.
409 
410  /// \brief Construct a CipherModeFinalTemplate
411  /// \param cipher An external block cipher
412  /// \details The cipher should be keyed.
414  {this->SetCipher(cipher);}
415 
416  /// \brief Construct a CipherModeFinalTemplate
417  /// \param cipher An external block cipher
418  /// \param iv a byte array used to resynchronize the cipher
419  /// \param feedbackSize the feedback size, in bytes
420  /// \details The cipher should be keyed.
421  CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher, const byte *iv, int feedbackSize = 0)
422  {this->SetCipherWithIV(cipher, iv, feedbackSize);}
423 
424  /// \brief Provides the name of this algorithm
425  /// \return the standard algorithm name
426  /// \details The standard algorithm name can be a name like \a AES or \a AES/GCM. Some algorithms
427  /// do not have standard names yet. For example, there is no standard algorithm name for
428  /// Shoup's ECIES.
429  /// \note AlgorithmName is not universally implemented yet
430  std::string AlgorithmName() const
431  {return (this->m_cipher ? this->m_cipher->AlgorithmName() + "/" : std::string("")) + BASE::StaticAlgorithmName();}
432 
433  // Algorithm class
434  std::string AlgorithmProvider() const
435  {return this->m_cipher->AlgorithmProvider();}
436 };
437 
441 
442 /// \brief CFB block cipher mode of operation
443 /// \sa <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
444 /// on the Crypto++ wiki.
445 template <class CIPHER>
447 {
450 };
451 
452 /// \brief CFB mode, external cipher.
453 /// \sa <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
454 /// on the Crypto++ wiki.
456 {
459 };
460 
461 /// \brief CFB block cipher mode of operation providing FIPS validated cryptography.
462 /// \details Requires full block plaintext according to FIPS 800-38A
463 /// \sa <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
464 /// on the Crypto++ wiki.
465 template <class CIPHER>
467 {
470 };
471 
472 /// \brief CFB mode, external cipher, providing FIPS validated cryptography.
473 /// \details Requires full block plaintext according to FIPS 800-38A
474 /// \sa <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
475 /// on the Crypto++ wiki.
477 {
480 };
481 
483 
484 /// \brief OFB block cipher mode of operation
485 /// \sa <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
486 /// on the Crypto++ wiki.
487 template <class CIPHER>
489 {
491  typedef Encryption Decryption;
492 };
493 
494 /// \brief OFB mode, external cipher.
495 /// \sa <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
496 /// on the Crypto++ wiki.
498 {
500  typedef Encryption Decryption;
501 };
502 
505 
506 /// \brief CTR block cipher mode of operation
507 /// \sa <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
508 /// on the Crypto++ wiki.
509 template <class CIPHER>
511 {
513  typedef Encryption Decryption;
514 };
515 
516 /// \brief CTR mode, external cipher.
517 /// \sa <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
518 /// on the Crypto++ wiki.
520 {
522  typedef Encryption Decryption;
523 };
524 
525 /// \brief ECB block cipher mode of operation
526 /// \sa <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
527 /// on the Crypto++ wiki.
528 template <class CIPHER>
530 {
533 };
534 
535 CRYPTOPP_DLL_TEMPLATE_CLASS CipherModeFinalTemplate_ExternalCipher<ECB_OneWay>;
536 
537 /// \brief ECB mode, external cipher.
538 /// \sa <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
539 /// on the Crypto++ wiki.
541 {
543  typedef Encryption Decryption;
544 };
545 
546 /// \brief CBC block cipher mode of operation
547 /// \sa <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
548 /// on the Crypto++ wiki.
549 template <class CIPHER>
551 {
554 };
555 
558 
559 /// \brief CBC mode, external cipher
560 /// \sa <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
561 /// on the Crypto++ wiki.
563 {
566 };
567 
568 /// \brief CBC-CTS block cipher mode of operation
569 /// \sa <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
570 /// on the Crypto++ wiki.
571 /// \since Crypto++ 3.0
572 template <class CIPHER>
574 {
577 };
578 
581 
582 /// \brief CBC mode with ciphertext stealing, external cipher
583 /// \sa <A HREF="http://www.cryptopp.com/wiki/Modes_of_Operation">Modes of Operation</A>
584 /// on the Crypto++ wiki.
585 /// \since Crypto++ 3.0
587 {
590 };
591 
592 NAMESPACE_END
593 
594 // Issue 340
595 #if CRYPTOPP_MSC_VERSION
596 # pragma warning(pop)
597 #endif
598 
599 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
600 # pragma GCC diagnostic pop
601 #endif
602 
603 #endif
Used to pass byte array input as part of a NameValuePairs object.
Definition: algparam.h:20
int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
Definition: cryptlib.h:393
Standard names for retrieving values by name when working with NameValuePairs.
An invalid argument was detected.
Definition: cryptlib.h:200
const char * FeedbackSize()
int
Definition: argnames.h:25
CipherModeFinalTemplate_CipherHolder()
Construct a CipherModeFinalTemplate.
Definition: modes.h:355
void Resynchronize(const byte *iv, int length=-1)
Resynchronize with an IV.
Definition: modes.h:258
Classes for working with NameValuePairs.
virtual void ProcessData(byte *outString, const byte *inString, size_t length)=0
Encrypt or decrypt an array of bytes.
Utility functions for the Crypto++ library.
virtual void SetKey(const byte *key, size_t length, const NameValuePairs &params=g_nullNameValuePairs)
Sets or reset the key of this object.
Definition: cryptlib.cpp:64
size_t GetValidKeyLength(size_t keylength) const
Returns a valid key length for the algorithm.
Definition: modes.h:79
CFB mode, external cipher, providing FIPS validated cryptography.
Definition: modes.h:476
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition: modes.h:257
void SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize=0)
Set external block cipher and IV.
Definition: modes.h:117
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
Definition: cryptlib.h:361
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
Definition: modes.h:231
virtual size_t ProcessLastBlock(byte *outString, size_t outLength, const byte *inString, size_t inLength)
Encrypt or decrypt the last block of data.
Definition: cryptlib.cpp:223
CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher, const byte *iv, int feedbackSize=0)
Construct a CipherModeFinalTemplate.
Definition: modes.h:421
CipherDir
Specifies a direction for a cipher to operate.
Definition: cryptlib.h:121
CipherModeFinalTemplate_ExternalCipher()
Construct a default CipherModeFinalTemplate.
Definition: modes.h:408
Abstract base classes that provide a uniform interface to this library.
void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
Bounds checking replacement for memcpy()
Definition: misc.h:439
Base class for feedback based stream ciphers with SymmetricCipher interface.
Definition: strciphr.h:541
The object does not use an IV.
Definition: cryptlib.h:705
void CopyOrZero(void *dest, size_t dsize, const void *src, size_t ssize)
Initialize a block of memory.
Definition: modes.h:196
Wirte the keystream to the output buffer, input is NULL.
Definition: strciphr.h:90
SecBlock<byte> typedef.
Definition: secblock.h:822
static std::string StaticAlgorithmName()
Provides the name of this algorithm.
Definition: modes.h:351
CBC-CTS block cipher mode of operation.
Definition: modes.h:573
bool CipherIsRandomAccess() const
Flag indicating random access.
Definition: modes.h:230
size_t MinKeyLength() const
Returns smallest valid key length.
Definition: modes.h:61
CTR block cipher mode of operation.
Definition: modes.h:510
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: modes.h:430
CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length)
Construct a CipherModeFinalTemplate.
Definition: modes.h:365
unsigned int OptimalBlockSize() const
Provides the input block size most efficient for this cipher.
Definition: modes.h:276
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1252
const char * StolenIV()
byte *
Definition: argnames.h:22
OFB block cipher mode of operation.
Definition: modes.h:208
CBC-CTS block cipher mode of operation decryption operation.
Definition: modes.h:334
size_t MaxKeyLength() const
Returns largest valid key length.
Definition: modes.h:65
Classes and functions for secure memory allocations.
ECB block cipher mode of operation.
Definition: modes.h:529
Base class for feedback based stream ciphers in the reverse direction with SymmetricCipher interface...
Definition: strciphr.h:631
Uses encapsulation to hide an object in derived classes.
Definition: misc.h:217
void SetCipher(BlockCipher &cipher)
Set external block cipher.
Definition: modes.h:105
CBC-CTS block cipher mode of operation encryption operation.
Definition: modes.h:300
virtual IV_Requirement IVRequirement() const =0
Minimal requirement for secure IVs.
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition: algparam.h:502
Block cipher mode of operation aggregate.
Definition: modes.h:343
CFB mode, external cipher.
Definition: modes.h:455
CBC block cipher mode of operation default implementation.
Definition: modes.h:281
bool IsSelfInverting() const
Determines whether the cipher is self-inverting.
Definition: modes.h:256
unsigned int MinLastBlockSize() const
Provides the size of the last block.
Definition: modes.h:337
virtual void Resynchronize(const byte *iv, int ivLength=-1)
Resynchronize with an IV.
Definition: cryptlib.h:759
std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition: modes.h:55
void SetKey(const byte *key, size_t length, const NameValuePairs &params=g_nullNameValuePairs)
Sets or reset the key of this object.
Definition: modes.h:273
Block cipher mode of operation information.
Definition: modes.h:44
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Definition: cryptlib.h:1260
unsigned int MandatoryBlockSize() const
Provides the mandatory block size of the cipher.
Definition: modes.h:254
Block cipher mode of operation default implementation.
Definition: modes.h:249
ECB mode, external cipher.
Definition: modes.h:540
unsigned int MinLastBlockSize() const
Provides the size of the last block.
Definition: modes.h:306
size_t DefaultKeyLength() const
Returns default key length.
Definition: modes.h:69
Base class for feedback based stream ciphers in the forward direction with SymmetricCipher interface...
Definition: strciphr.h:622
OFB block cipher mode of operation.
Definition: modes.h:488
CBC mode, external cipher.
Definition: modes.h:562
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Definition: trap.h:60
const char * BlockSize()
int, in bytes
Definition: argnames.h:27
CFB block cipher mode of operation.
Definition: modes.h:446
CTR block cipher mode of operation.
Definition: modes.h:224
OFB mode, external cipher.
Definition: modes.h:497
CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length, const byte *iv)
Construct a CipherModeFinalTemplate.
Definition: modes.h:376
const char * IV()
ConstByteArrayParameter, also accepts const byte * for backwards compatibility.
Definition: argnames.h:21
Classes for implementing stream ciphers.
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher...
Definition: seckey.h:436
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: modes.h:90
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
Definition: modes.h:172
const NameValuePairs g_nullNameValuePairs
An empty set of name-value pairs.
Definition: cryptlib.h:495
IV_Requirement
Secure IVs requirements as enumerated values.
Definition: cryptlib.h:695
Block cipher mode of operation information.
Definition: modes.h:49
CBC block cipher mode of operation decryption operation.
Definition: modes.h:320
CTR mode, external cipher.
Definition: modes.h:519
unsigned int MinLastBlockSize() const
Provides the size of the last block.
Definition: modes.h:288
CBC block cipher mode of operation encryption operation.
Definition: modes.h:292
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
Sets the key for this object without performing parameter validation.
Definition: modes.cpp:172
Block cipher mode of operation common operations.
Definition: modes.h:149
KeystreamOperation
Keystream operation flags.
Definition: strciphr.h:88
Crypto++ library namespace.
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
Definition: modes.h:275
The IV must be random and unpredictable.
Definition: cryptlib.h:701
unsigned int IVSize() const
Returns length of the IV accepted by this object.
Definition: modes.h:96
bool IsResynchronizable() const
Determines if the object can be resynchronized.
Definition: cryptlib.h:716
bool CipherIsRandomAccess() const
Flag indicating random access.
Definition: modes.h:213
CFB block cipher mode of operation.
Definition: modes.h:165
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
Definition: modes.h:286
bool IsValidKeyLength(size_t keylength) const
Returns whether keylength is a valid key length.
Definition: modes.h:85
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
Definition: modes.h:214
Base class for additive stream ciphers with SymmetricCipher interface.
Definition: strciphr.h:288
CFB block cipher mode of operation providing FIPS validated cryptography.
Definition: modes.h:466
ECB block cipher mode of operation default implementation.
Definition: modes.h:268
CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher)
Construct a CipherModeFinalTemplate.
Definition: modes.h:413
The IV must be unique.
Definition: cryptlib.h:697
bool IsRandomAccess() const
Determines whether the cipher supports random access.
Definition: modes.h:255
Interface for retrieving values given their names.
Definition: cryptlib.h:291
CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length, const byte *iv, int feedbackSize)
Construct a CipherModeFinalTemplate.
Definition: modes.h:388
The IV must be random and possibly predictable.
Definition: cryptlib.h:699
CBC block cipher mode of operation.
Definition: modes.h:550
CBC mode with ciphertext stealing, external cipher.
Definition: modes.h:586
Base class information.
Definition: simple.h:36