6 #ifndef CRYPTOPP_MODES_H 7 #define CRYPTOPP_MODES_H 17 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 18 # pragma GCC diagnostic push 19 # pragma GCC diagnostic ignored "-Wconversion" 20 # pragma GCC diagnostic ignored "-Wsign-conversion" 55 unsigned int IVSize()
const {
return BlockSize();}
61 this->m_cipher = &cipher;
62 this->ResizeBuffers();
68 this->m_cipher = &cipher;
69 this->ResizeBuffers();
70 this->SetFeedbackSize(feedbackSize);
80 if (!(feedbackSize == 0 || feedbackSize == BlockSize()))
81 throw InvalidArgument(
"CipherModeBase: feedback size cannot be specified for this cipher mode");
84 virtual void ResizeBuffers();
93 template <
class POLICY_INTERFACE>
96 unsigned int GetAlignment()
const {
return m_cipher->OptimalDataAlignment();}
100 template <
class POLICY_INTERFACE>
103 m_cipher->SetKey(key, length, params);
106 SetFeedbackSize(feedbackSize);
122 bool CanIterate()
const {
return m_feedbackSize == BlockSize();}
123 void Iterate(
byte *output,
const byte *input,
CipherDir dir,
size_t iterationCount);
124 void TransformRegister();
125 void CipherResynchronize(
const byte *iv,
size_t length);
126 void SetFeedbackSize(
unsigned int feedbackSize);
127 void ResizeBuffers();
133 inline void CopyOrZero(
void *dest,
const void *src,
size_t s)
154 void WriteKeystream(
byte *keystreamBuffer,
size_t iterationCount);
155 void CipherResynchronize(
byte *keystreamBuffer,
const byte *iv,
size_t length);
170 virtual void IncrementCounterBy256();
171 unsigned int GetAlignment()
const {
return m_cipher->OptimalDataAlignment();}
178 void CipherResynchronize(
byte *keystreamBuffer,
const byte *iv,
size_t length);
179 void SeekToIteration(
lword iterationCount);
190 void UncheckedSetKey(
const byte *key,
unsigned int length,
const NameValuePairs ¶ms);
199 virtual void ResizeBuffers();
214 unsigned int OptimalBlockSize()
const {
return BlockSize() * m_cipher->OptimalNumberOfParallelBlocks();}
215 void ProcessData(
byte *outString,
const byte *inString,
size_t length);
235 void ProcessData(
byte *outString,
const byte *inString,
size_t length);
247 void ProcessLastBlock(
byte *outString,
const byte *inString,
size_t length);
265 void ProcessData(
byte *outString,
const byte *inString,
size_t length);
268 virtual void ResizeBuffers();
279 void ProcessLastBlock(
byte *outString,
const byte *inString,
size_t length);
284 template <
class CIPHER,
class BASE>
289 {
return CIPHER::StaticAlgorithmName() +
"/" + BASE::StaticAlgorithmName();}
293 this->m_cipher = &this->m_object;
294 this->ResizeBuffers();
298 this->m_cipher = &this->m_object;
299 this->SetKey(key, length);
303 this->m_cipher = &this->m_object;
308 this->m_cipher = &this->m_object;
316 template <
class BASE>
322 {this->SetCipher(cipher);}
324 {this->SetCipherWithIV(cipher, iv, feedbackSize);}
327 {
return (this->m_cipher ? this->m_cipher->AlgorithmName() +
"/" : std::string(
"")) + BASE::StaticAlgorithmName();}
336 template <
class CIPHER>
354 template <
class CIPHER>
374 template <
class CIPHER>
394 template <
class CIPHER>
411 template <
class CIPHER>
429 template <
class CIPHER>
447 template <
class CIPHER>
475 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 476 # pragma GCC diagnostic pop bool IsSelfInverting() const
Determines whether the cipher is self-inverting.
Used to pass byte array input as part of a NameValuePairs object.
CipherModeFinalTemplate_ExternalCipher< CBC_CTS_Encryption > Encryption
CipherModeFinalTemplate_CipherHolder< typename CIPHER::Encryption, ConcretePolicyHolder< Empty, CFB_RequireFullDataBlocks< CFB_DecryptionTemplate< AbstractPolicyHolder< CFB_CipherAbstractPolicy, CFB_ModePolicy > > > > > Decryption
Standard names for retrieving values by name when working with NameValuePairs.
An invalid argument was detected.
CipherModeFinalTemplate_CipherHolder()
CipherModeFinalTemplate_ExternalCipher< ConcretePolicyHolder< Empty, CFB_RequireFullDataBlocks< CFB_EncryptionTemplate< AbstractPolicyHolder< CFB_CipherAbstractPolicy, CFB_ModePolicy > > > > > Encryption
void Resynchronize(const byte *iv, int length=-1)
Resynchronize with an IV.
Classes for working with NameValuePairs.
size_t GetValidKeyLength(size_t n) const
Returns a valid key length for the algorithm.
CipherModeFinalTemplate_CipherHolder< typename CIPHER::Decryption, ECB_OneWay > Decryption
Utility functions for the Crypto++ library.
#define CRYPTOPP_STATIC_CONSTEXPR
virtual ~BlockOrientedCipherModeBase()
CFB mode, external cipher, providing FIPS validated cryptography.
void SetCipherWithIV(BlockCipher &cipher, const byte *iv, int feedbackSize=0)
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
bool IsRandomAccess() const
Determines whether the cipher supports random access.
virtual void SetFeedbackSize(unsigned int feedbackSize)
CRYPTOPP_STATIC_CONSTEXPR const char *CRYPTOPP_API StaticAlgorithmName()
CRYPTOPP_STATIC_CONSTEXPR const char *CRYPTOPP_API StaticAlgorithmName()
CipherModeFinalTemplate_CipherHolder< typename CIPHER::Encryption, ConcretePolicyHolder< Empty, CFB_DecryptionTemplate< AbstractPolicyHolder< CFB_CipherAbstractPolicy, CFB_ModePolicy > > > > Decryption
virtual ~CipherModeBase()
void ThrowIfInvalidIV(const byte *iv)
Validates the IV.
CipherModeFinalTemplate_CipherHolder< typename CIPHER::Encryption, CBC_Encryption > Encryption
#define NAMESPACE_BEGIN(x)
CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher, const byte *iv, int feedbackSize=0)
#define CRYPTOPP_DLL_TEMPLATE_CLASS
bool CanIterate() const
Flag indicating iteration support.
void CopyOrZero(void *dest, const void *src, size_t s)
CipherDir
Specifies a direction for a cipher to operate.
CipherModeFinalTemplate_ExternalCipher()
size_t MinKeyLength() const
Returns smallest valid key length.
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()
void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length)
Base class for feedback based stream ciphers with SymmetricCipher interface.
virtual void ResizeBuffers()
unsigned int GetBytesPerIteration() const
Provides number of bytes operated upon during an iteration.
CipherModeFinalTemplate_ExternalCipher< ConcretePolicyHolder< Empty, AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, OFB_ModePolicy > > > > Encryption
Wirte the keystream to the output buffer, input is NULL.
CipherModeFinalTemplate_ExternalCipher< ConcretePolicyHolder< Empty, CFB_EncryptionTemplate< AbstractPolicyHolder< CFB_CipherAbstractPolicy, CFB_ModePolicy > > > > Encryption
CBC mode with ciphertext stealing.
CipherModeFinalTemplate_ExternalCipher< CBC_CTS_Decryption > Decryption
CTR block cipher mode of operation.
virtual ~CFB_ModePolicy()
CipherModeFinalTemplate_CipherHolder< typename CIPHER::Encryption, ConcretePolicyHolder< Empty, AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, OFB_ModePolicy > > > > Encryption
CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length)
unsigned int GetAlignment() const
Provides data alignment requirements.
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
Interface for one direction (encryption or decryption) of a block cipher.
CipherModeFinalTemplate_CipherHolder< typename CIPHER::Encryption, ECB_OneWay > Encryption
CipherModeFinalTemplate_CipherHolder< typename CIPHER::Decryption, CBC_Decryption > Decryption
unsigned int GetAlignment() const
OFB block cipher mode of operation.
CBC-CTS block cipher mode of operation decryption operation.
CipherModeFinalTemplate_CipherHolder< typename CIPHER::Encryption, ConcretePolicyHolder< Empty, AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, CTR_ModePolicy > > > > Encryption
Classes and functions for secure memory allocations.
virtual ~CBC_Decryption()
ECB block cipher mode of operation.
bool RequireAlignedInput() const
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
CipherModeFinalTemplate_ExternalCipher< ECB_OneWay > Encryption
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
Base class for feedback based stream ciphers in the reverse direction with SymmetricCipher interface...
Uses encapsulation to hide an object in derived classes.
void SetCipher(BlockCipher &cipher)
byte * GetRegisterBegin()
Access the feedback register.
CBC-CTS block cipher mode of operation encryption operation.
unsigned int GetBytesPerIteration() const
Provides number of bytes operated upon during an iteration.
virtual IV_Requirement IVRequirement() const =0
Minimal requirement for secure IVs.
unsigned int IVSize() const
Returns length of the IV accepted by this object.
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
Sets the key for this object without performing parameter validation.
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
unsigned int GetIterationsToBuffer() const
Provides buffer size based on iterations.
Block cipher mode of operation aggregate.
CipherModeFinalTemplate_CipherHolder< typename CIPHER::Encryption, CBC_CTS_Encryption > Encryption
CFB mode, external cipher.
CBC block cipher mode of operation default implementation.
bool IsResynchronizable() const
Determines if the object can be resynchronized.
std::string AlgorithmName() const
CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
virtual void Resynchronize(const byte *iv, int ivLength=-1)
Resynchronize with an IV.
size_t DefaultKeyLength() const
Returns default key length.
void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms=g_nullNameValuePairs)
Sets or reset the key of this object.
Block cipher mode of operation information.
CipherModeFinalTemplate_ExternalCipher< ConcretePolicyHolder< Empty, CFB_DecryptionTemplate< AbstractPolicyHolder< CFB_CipherAbstractPolicy, CFB_ModePolicy > > > > Decryption
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
void ThrowIfResynchronizable()
Validates the object.
Block cipher mode of operation default implementation.
ECB mode, external cipher.
static std::string CRYPTOPP_API StaticAlgorithmName()
CRYPTOPP_STATIC_CONSTEXPR const char *CRYPTOPP_API StaticAlgorithmName()
bool CanOperateKeystream() const
Flag indicating.
unsigned int MinLastBlockSize() const
Provides the size of the last block.
unsigned int OptimalBlockSize() const
Provides the input block size most efficient for this cipher.
Base class for feedback based stream ciphers in the forward direction with SymmetricCipher interface...
OFB block cipher mode of operation.
size_t MaxKeyLength() const
Returns largest valid key length.
CBC mode, external cipher.
CipherModeFinalTemplate_ExternalCipher< ConcretePolicyHolder< Empty, CFB_RequireFullDataBlocks< CFB_DecryptionTemplate< AbstractPolicyHolder< CFB_CipherAbstractPolicy, CFB_ModePolicy > > > > > Decryption
unsigned int GetBytesPerIteration() const
Provides number of bytes operated upon during an iteration.
#define CRYPTOPP_ASSERT(exp)
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
CipherModeFinalTemplate_ExternalCipher< CBC_Encryption > Encryption
CFB block cipher mode of operation.
CTR block cipher mode of operation.
CRYPTOPP_STATIC_CONSTEXPR const char *CRYPTOPP_API StaticAlgorithmName()
bool IsValidKeyLength(size_t n) const
Returns whether keylength is a valid key length.
OFB mode, external cipher.
CipherModeFinalTemplate_CipherHolder< typename CIPHER::Encryption, ConcretePolicyHolder< Empty, CFB_RequireFullDataBlocks< CFB_EncryptionTemplate< AbstractPolicyHolder< CFB_CipherAbstractPolicy, CFB_ModePolicy > > > > > Encryption
#define CRYPTOPP_NO_VTABLE
CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length, const byte *iv)
Classes for implementing stream ciphers.
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher...
AlignedSecByteBlock m_register
void WriteKeystream(byte *buffer, size_t iterationCount)
Generate the keystream.
IV_Requirement
Secure IVs requirements as enumerated values.
unsigned int m_feedbackSize
bool CipherIsRandomAccess() const
Flag indicating random access.
void SetStolenIV(byte *iv)
Block cipher mode of operation information.
CBC block cipher mode of operation decryption operation.
CipherModeFinalTemplate_CipherHolder< typename CIPHER::Decryption, CBC_CTS_Decryption > Decryption
CTR mode, external cipher.
unsigned int MinLastBlockSize() const
Provides the size of the last block.
CBC block cipher mode of operation encryption operation.
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
Sets the key for this object without performing parameter validation.
CipherModeFinalTemplate_CipherHolder< typename CIPHER::Encryption, ConcretePolicyHolder< Empty, CFB_EncryptionTemplate< AbstractPolicyHolder< CFB_CipherAbstractPolicy, CFB_ModePolicy > > > > Encryption
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
AlignedSecByteBlock m_temp
Block cipher mode of operation common operations.
KeystreamOperation
Keystream operation flags.
bool RequireAlignedInput() const
bool CipherIsRandomAccess() const
Flag indicating random access.
unsigned int MandatoryBlockSize() const
Provides the mandatory block size of the cipher.
unsigned int GetIterationsToBuffer() const
Provides buffer size based on iterations.
unsigned int MinLastBlockSize() const
Provides the size of the last block.
virtual ~CTR_ModePolicy()
CFB block cipher mode of operation.
CRYPTOPP_STATIC_CONSTEXPR const char *CRYPTOPP_API StaticAlgorithmName()
IV_Requirement IVRequirement() const
Minimal requirement for secure IVs.
CipherModeFinalTemplate_ExternalCipher< CBC_Decryption > Decryption
CRYPTOPP_STATIC_CONSTEXPR const char *CRYPTOPP_API StaticAlgorithmName()
Base class for additive stream ciphers with SymmetricCipher interface.
CipherModeFinalTemplate_ExternalCipher< ConcretePolicyHolder< Empty, AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, CTR_ModePolicy > > > > Encryption
CFB block cipher mode of operation providing FIPS validated cryptography.
unsigned int BlockSize() const
AlignedSecByteBlock m_counterArray
ECB block cipher mode of operation default implementation.
CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher)
Interface for retrieving values given their names.
CipherModeFinalTemplate_CipherHolder(const byte *key, size_t length, const byte *iv, int feedbackSize)
CBC mode with ciphertext stealing, external cipher.
Base class for identifying alogorithm.