28 #ifndef CRYPTOPP_STRCIPHR_H 29 #define CRYPTOPP_STRCIPHR_H 33 #if CRYPTOPP_MSC_VERSION 34 # pragma warning(push) 35 # pragma warning(disable: 4127 4189) 45 template <class POLICY_INTERFACE, class BASE =
Empty>
57 virtual const POLICY_INTERFACE & GetPolicy()
const =0;
58 virtual POLICY_INTERFACE & AccessPolicy() =0;
65 template <
class POLICY,
class BASE,
class POLICY_INTERFACE =
typename BASE::PolicyInterface>
71 const POLICY_INTERFACE &
GetPolicy()
const {
return *
this;}
119 virtual unsigned int GetBytesPerIteration()
const =0;
129 virtual unsigned int GetIterationsToBuffer()
const =0;
158 virtual void CipherSetKey(
const NameValuePairs ¶ms,
const byte *key,
size_t length) =0;
170 virtual bool CipherIsRandomAccess()
const =0;
185 template <
typename WT,
unsigned int W,
unsigned int X = 1,
class BASE = AdditiveCipherAbstractPolicy>
191 #if !(CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X64) 192 unsigned int GetAlignment()
const {
return GetAlignmentOf<WordType>();}
225 #define CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, b, i, a) \ 226 PutWord(bool(x & OUTPUT_ALIGNED), b, output+i*sizeof(WordType), (x & INPUT_NULL) ? (a) : (a) ^ GetWord<WordType>(bool(x & INPUT_ALIGNED), b, input+i*sizeof(WordType))); 229 #define CRYPTOPP_KEYSTREAM_OUTPUT_XMM(x, i, a) {\ 230 __m128i t = (x & INPUT_NULL) ? a : _mm_xor_si128(a, (x & INPUT_ALIGNED) ? _mm_load_si128((__m128i *)input+i) : _mm_loadu_si128((__m128i *)input+i));\ 231 if (x & OUTPUT_ALIGNED) _mm_store_si128((__m128i *)output+i, t);\ 232 else _mm_storeu_si128((__m128i *)output+i, t);} 235 #define CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(x, y) \ 238 case WRITE_KEYSTREAM: \ 241 case XOR_KEYSTREAM: \ 245 case XOR_KEYSTREAM_INPUT_ALIGNED: \ 246 x(XOR_KEYSTREAM_INPUT_ALIGNED) \ 249 case XOR_KEYSTREAM_OUTPUT_ALIGNED: \ 250 x(XOR_KEYSTREAM_OUTPUT_ALIGNED) \ 253 case WRITE_KEYSTREAM_ALIGNED: \ 254 x(WRITE_KEYSTREAM_ALIGNED) \ 256 case XOR_KEYSTREAM_BOTH_ALIGNED: \ 257 x(XOR_KEYSTREAM_BOTH_ALIGNED) \ 266 template <
class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher> >
277 void GenerateBlock(
byte *output,
size_t size);
292 void ProcessData(
byte *outString,
const byte *inString,
size_t length);
297 void Resynchronize(
const byte *iv,
int length=-1);
332 void Seek(
lword position);
337 void UncheckedSetKey(
const byte *key,
unsigned int length,
const NameValuePairs ¶ms);
359 virtual unsigned int GetAlignment()
const =0;
364 virtual unsigned int GetBytesPerIteration()
const =0;
368 virtual byte * GetRegisterBegin() =0;
371 virtual void TransformRegister() =0;
391 virtual void CipherSetKey(
const NameValuePairs ¶ms,
const byte *key,
size_t length) =0;
405 template <
typename WT,
unsigned int W,
class BASE = CFB_CipherAbstractPolicy>
437 : m_output(output), m_input(input), m_dir(dir) {}
458 WordType ct = *(
const WordType *)m_input ^ registerWord;
460 *(WordType*)m_output = ct;
461 m_input +=
sizeof(WordType);
462 m_output +=
sizeof(WordType);
467 WordType ct = *(
const WordType *)m_input;
468 *(WordType*)m_output = registerWord ^ ct;
470 m_input +=
sizeof(WordType);
471 m_output +=
sizeof(WordType);
488 template <
class BASE>
505 void ProcessData(
byte *outString,
const byte *inString,
size_t length);
510 void Resynchronize(
const byte *iv,
int length=-1);
541 virtual void CombineMessageAndShiftRegister(
byte *output,
byte *reg,
const byte *message,
size_t length) =0;
543 void UncheckedSetKey(
const byte *key,
unsigned int length,
const NameValuePairs ¶ms);
551 template <
class BASE = AbstractPolicyHolder<CFB_CipherAbstractPolicy, SymmetricCipher> >
555 void CombineMessageAndShiftRegister(
byte *output,
byte *reg,
const byte *message,
size_t length);
561 template <
class BASE = AbstractPolicyHolder<CFB_CipherAbstractPolicy, SymmetricCipher> >
565 void CombineMessageAndShiftRegister(
byte *output,
byte *reg,
const byte *message,
size_t length);
571 template <
class BASE>
583 template <
class BASE,
class INFO = BASE>
596 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
602 {this->SetKey(key, length);}
609 {this->SetKeyWithIV(key, length, iv);}
618 #ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES 631 #if CRYPTOPP_MSC_VERSION 632 # pragma warning(pop) Base class for all exceptions thrown by the library.
Standard names for retrieving values by name when working with NameValuePairs.
virtual unsigned int GetOptimalBlockSize() const
Provides number of ideal bytes to process.
BASE::PolicyInterface PolicyInterface
bool NativeByteOrderIs(ByteOrder order)
Determines whether order follows native byte ordering.
Output buffer is aligned.
SymmetricCipherFinal(const byte *key)
Construct a stream cipher.
virtual ~ConcretePolicyHolder()
unsigned int GetBytesPerIteration() const
Provides number of bytes operated upon during an iteration.
Base class for feedback based stream ciphers.
Base class for additive stream ciphers.
virtual void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount)
Operates the keystream.
XOR the input buffer and keystream, write to the aligned output buffer.
#define NAMESPACE_BEGIN(x)
unsigned int GetBufferByteSize(const PolicyInterface &policy) const
bool IsForwardTransformation() const
#define CRYPTOPP_DLL_TEMPLATE_CLASS
XOR the input buffer and keystream, write to the output buffer.
CipherDir
Specifies a direction for a cipher to operate.
Abstract base classes that provide a uniform interface to this library.
Base class for feedback based stream ciphers with SymmetricCipher interface.
Some other error occurred not belonging to other categories.
Library configuration file.
Interface for random number generators.
Wirte the keystream to the output buffer, input is NULL.
Stream cipher policy object.
Interface for cloning objects.
unsigned int OptimalBlockSize() const
Provides number of ideal bytes to process.
virtual void WriteKeystream(byte *keystream, size_t iterationCount)
Generate the keystream.
Policy object for additive stream ciphers.
the cipher is performing encryption
byte * KeystreamBufferBegin()
Classes and functions for secure memory allocations.
virtual unsigned int GetAlignment() const
Provides data alignment requirements.
void TransformRegister()
Perform one iteration in the forward direction.
bool IsAlignedOn(const void *ptr, unsigned int alignment)
Determines whether ptr is aligned to a minimum value.
POLICY_INTERFACE PolicyInterface
Base class for feedback based stream ciphers in the reverse direction with SymmetricCipher interface...
unsigned int OptimalDataAlignment() const
Provides number of ideal data alignment.
POLICY_INTERFACE & AccessPolicy()
BASE::PolicyInterface PolicyInterface
A method was called which was not implemented.
RegisterOutput & operator()(WordType ®isterWord)
XOR feedback register with data.
virtual unsigned int GetBytesPerIteration() const =0
Provides number of bytes operated upon during an iteration.
Classes and functions for implementing secret key algorithms.
bool IsSelfInverting() const
Determines if the cipher is self inverting.
virtual void SeekToIteration(lword iterationCount)
Seeks to a random position in the stream.
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Base class for feedback based stream ciphers with a mandatory block size.
Policy object for feeback based stream ciphers.
byte * KeystreamBufferEnd()
bool CanIterate() const
Flag indicating iteration support.
bool IsForwardTransformation() const
unsigned int MandatoryBlockSize() const
unsigned int GetAlignment() const
Provides data alignment requirements.
virtual ~AdditiveCipherTemplate()
virtual ~AbstractPolicyHolder()
Base class for feedback based stream ciphers in the forward direction with SymmetricCipher interface...
#define CRYPTOPP_CONSTANT(x)
Clonable * Clone() const
Clone a SymmetricCipher.
SymmetricCipherFinal()
Construct a stream cipher.
virtual ~AdditiveCipherAbstractPolicy()
#define CRYPTOPP_ASSERT(exp)
virtual bool CanIterate() const
Flag indicating iteration support.
unsigned int OptimalBlockSize() const
Provides number of ideal bytes to process.
#define CRYPTOPP_NO_VTABLE
virtual unsigned int GetIterationsToBuffer() const =0
Provides buffer size based on iterations.
bool IsRandomAccess() const
Flag indicating random access.
XOR the aligned input buffer and keystream, write to the aligned output buffer.
unsigned int OptimalDataAlignment() const
Provides number of ideal data alignment.
uint8_t const size_t const size
SymmetricCipherFinal(const byte *key, size_t length, const byte *iv)
Construct a stream cipher.
unsigned int GetOptimalNextBlockSize() const
Provides number of ideal bytes to process.
#define CRYPTOPP_UNUSED(x)
unsigned int GetBytesPerIteration() const
Provides number of bytes operated upon during an iteration.
bool IsForwardTransformation() const
Determines if the cipher is a forward transformation.
virtual ~CFB_CipherAbstractPolicy()
virtual void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length)
Resynchronize the cipher.
virtual void Iterate(byte *output, const byte *input, CipherDir dir, size_t iterationCount)
Iterate the cipher.
virtual ~SymmetricCipherFinal()
virtual bool CanOperateKeystream() const
Flag indicating.
KeystreamOperation
Keystream operation flags.
bool IsSelfInverting() const
Determines if the cipher is self inverting.
SymmetricCipherFinal(const byte *key, size_t length)
Construct a stream cipher.
unsigned int GetIterationsToBuffer() const
Provides buffer size based on iterations.
virtual void CipherResynchronize(const byte *iv, size_t length)
Resynchronize the cipher.
bool IsRandomAccess() const
Flag indicating random access.
SymmetricCipher implementation.
Wirte the keystream to the aligned output buffer, input is NULL.
bool CanOperateKeystream() const
Flag indicating.
unsigned int GetOptimalNextBlockSize() const
Provides number of ideal bytes to process.
byte ByteReverse(byte value)
Reverses bytes in a 8-bit value.
Base class for additive stream ciphers with SymmetricCipher interface.
Access a stream cipher policy object.
XOR the aligned input buffer and keystream, write to the output buffer.
KeystreamOperationFlags
Keystream operation flags.
const POLICY_INTERFACE & GetPolicy() const
RegisterOutput(byte *output, const byte *input, CipherDir dir)
Interface for retrieving values given their names.
Base class for identifying alogorithm.