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) 49 template <
class POLICY_INTERFACE,
class BASE = Empty>
53 typedef POLICY_INTERFACE PolicyInterface;
57 virtual const POLICY_INTERFACE & GetPolicy()
const =0;
58 virtual POLICY_INTERFACE & AccessPolicy() =0;
65 template <
class POLICY,
class BASE,
class POLICY_INTERFACE = CPP_TYPENAME BASE::PolicyInterface>
69 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 73 const POLICY_INTERFACE & GetPolicy()
const {
return *
this;}
74 POLICY_INTERFACE & AccessPolicy() {
return *
this;}
121 virtual unsigned int GetBytesPerIteration()
const =0;
131 virtual unsigned int GetIterationsToBuffer()
const =0;
154 {CRYPTOPP_UNUSED(operation); CRYPTOPP_UNUSED(output); CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(iterationCount); assert(
false);}
160 virtual void CipherSetKey(
const NameValuePairs ¶ms,
const byte *key,
size_t length) =0;
167 {CRYPTOPP_UNUSED(keystreamBuffer); CRYPTOPP_UNUSED(iv); CRYPTOPP_UNUSED(length);
throw NotImplemented(
"SimpleKeyingInterface: this object doesn't support resynchronization");}
172 virtual bool CipherIsRandomAccess()
const =0;
178 {CRYPTOPP_UNUSED(iterationCount); assert(!CipherIsRandomAccess());
throw NotImplemented(
"StreamTransformation: this object doesn't support random access");}
187 template <
typename WT,
unsigned int W,
unsigned int X = 1,
class BASE = AdditiveCipherAbstractPolicy>
191 CRYPTOPP_CONSTANT(BYTES_PER_ITERATION =
sizeof(WordType) * W)
193 #if !(CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X64) 223 virtual void OperateKeystream(
KeystreamOperation operation, byte *output,
const byte *input,
size_t iterationCount) =0;
227 #define CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, b, i, a) \ 228 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))); 231 #define CRYPTOPP_KEYSTREAM_OUTPUT_XMM(x, i, a) {\ 232 __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));\ 233 if (x & OUTPUT_ALIGNED) _mm_store_si128((__m128i *)output+i, t);\ 234 else _mm_storeu_si128((__m128i *)output+i, t);} 237 #define CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(x, y) \ 240 case WRITE_KEYSTREAM: \ 243 case XOR_KEYSTREAM: \ 247 case XOR_KEYSTREAM_INPUT_ALIGNED: \ 248 x(XOR_KEYSTREAM_INPUT_ALIGNED) \ 251 case XOR_KEYSTREAM_OUTPUT_ALIGNED: \ 252 x(XOR_KEYSTREAM_OUTPUT_ALIGNED) \ 255 case WRITE_KEYSTREAM_ALIGNED: \ 256 x(WRITE_KEYSTREAM_ALIGNED) \ 258 case XOR_KEYSTREAM_BOTH_ALIGNED: \ 259 x(XOR_KEYSTREAM_BOTH_ALIGNED) \ 268 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);
341 inline byte * KeystreamBufferBegin() {
return this->m_buffer.data();}
342 inline byte * KeystreamBufferEnd() {
return (this->m_buffer.data() + this->m_buffer.size());}
359 virtual unsigned int GetAlignment()
const =0;
364 virtual unsigned int GetBytesPerIteration()
const =0;
368 virtual byte * GetRegisterBegin() =0;
371 virtual void TransformRegister() =0;
383 virtual void Iterate(byte *output,
const byte *input,
CipherDir dir,
size_t iterationCount)
384 {CRYPTOPP_UNUSED(output); CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(dir); CRYPTOPP_UNUSED(iterationCount);
391 virtual void CipherSetKey(
const NameValuePairs ¶ms,
const byte *key,
size_t length) =0;
397 {CRYPTOPP_UNUSED(iv); CRYPTOPP_UNUSED(length);
throw NotImplemented(
"SimpleKeyingInterface: this object doesn't support resynchronization");}
405 template <
typename WT,
unsigned int W,
class BASE = CFB_CipherAbstractPolicy>
437 : m_output(output), m_input(input), m_dir(dir) {}
444 assert(IsAligned<WordType>(m_output));
445 assert(IsAligned<WordType>(m_input));
453 assert(m_output == NULL);
456 WordType ct = *(
const WordType *)m_input ^ registerWord;
458 *(WordType*)m_output = ct;
459 m_input +=
sizeof(WordType);
460 m_output +=
sizeof(WordType);
465 WordType ct = *(
const WordType *)m_input;
466 *(WordType*)m_output = registerWord ^ ct;
468 m_input +=
sizeof(WordType);
469 m_output +=
sizeof(WordType);
486 template <
class BASE>
503 void ProcessData(byte *outString,
const byte *inString,
size_t length);
508 void Resynchronize(
const byte *iv,
int length=-1);
536 typedef typename BASE::PolicyInterface PolicyInterface;
539 virtual void CombineMessageAndShiftRegister(byte *output, byte *reg,
const byte *message,
size_t length) =0;
541 void UncheckedSetKey(
const byte *key,
unsigned int length,
const NameValuePairs ¶ms);
549 template <
class BASE = AbstractPolicyHolder<CFB_CipherAbstractPolicy, SymmetricCipher> >
552 bool IsForwardTransformation()
const {
return true;}
553 void CombineMessageAndShiftRegister(byte *output, byte *reg,
const byte *message,
size_t length);
559 template <
class BASE = AbstractPolicyHolder<CFB_CipherAbstractPolicy, SymmetricCipher> >
562 bool IsForwardTransformation()
const {
return false;}
563 void CombineMessageAndShiftRegister(byte *output, byte *reg,
const byte *message,
size_t length);
569 template <
class BASE>
573 unsigned int MandatoryBlockSize()
const {
return this->OptimalBlockSize();}
581 template <
class BASE,
class INFO = BASE>
592 {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
598 {this->SetKey(key, length);}
605 {this->SetKeyWithIV(key, length, iv);}
614 #ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES 615 #include "strciphr.cpp" 627 #if CRYPTOPP_MSC_VERSION 628 # pragma warning(pop) Base class for all exceptions thrown by the library.
unsigned int GetOptimalNextBlockSize() const
Provides number of ideal bytes to process.
Standard names for retrieving values by name when working with NameValuePairs.
bool CanOperateKeystream() const
Flag indicating.
bool NativeByteOrderIs(ByteOrder order)
Determines whether order follows native byte ordering.
Output buffer is aligned.
SymmetricCipherFinal(const byte *key)
Construct a stream cipher.
unsigned int OptimalBlockSize() const
Provides number of ideal bytes to process.
bool IsRandomAccess() const
Flag indicating random access.
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.
unsigned int GetOptimalNextBlockSize() const
Provides number of ideal bytes to process.
XOR the input buffer and keystream, write to the aligned output buffer.
unsigned int GetBytesPerIteration() const
Provides number of bytes operated upon during an iteration.
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.
unsigned int OptimalDataAlignment() const
Provides number of ideal data alignment.
Some other error occurred not belonging to other categories.
Library configuration file.
virtual unsigned int GetOptimalBlockSize() const
Provides number of ideal bytes to process.
Interface for random number generators.
unsigned int GetAlignment() const
Provides data alignment requirements.
Wirte the keystream to the output buffer, input is NULL.
Stream cipher policy object.
virtual bool CanOperateKeystream() const
Flag indicating.
Interface for cloning objects.
virtual void WriteKeystream(byte *keystream, size_t iterationCount)
Generate the keystream.
Policy object for additive stream ciphers.
the cipher is performing encryption
Classes and functions for secure memory allocations.
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.
Base class for feedback based stream ciphers in the reverse direction with SymmetricCipher interface...
bool IsSelfInverting() const
Determines if the cipher is self inverting.
unsigned int GetBytesPerIteration() const
Provides number of bytes operated upon during an iteration.
A method was called which was not implemented.
virtual unsigned int GetAlignment() const
Provides data alignment requirements.
bool CanIterate() const
Flag indicating iteration support.
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.
virtual void SeekToIteration(lword iterationCount)
Seeks to a random position in the stream.
unsigned int OptimalBlockSize() const
Provides number of ideal bytes to process.
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.
Base class for feedback based stream ciphers in the forward direction with SymmetricCipher interface...
SymmetricCipherFinal()
Construct a stream cipher.
bool IsSelfInverting() const
Determines if the cipher is self inverting.
bool IsRandomAccess() const
Flag indicating random access.
virtual unsigned int GetIterationsToBuffer() const =0
Provides buffer size based on iterations.
unsigned int OptimalDataAlignment() const
Provides number of ideal data alignment.
XOR the aligned input buffer and keystream, write to the aligned output buffer.
virtual bool CanIterate() const
Flag indicating iteration support.
SymmetricCipherFinal(const byte *key, size_t length, const byte *iv)
Construct a stream cipher.
Clonable * Clone() const
Clone a SymmetricCipher.
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.
unsigned int GetAlignment() const
Provides data alignment requirements.
KeystreamOperation
Keystream operation flags.
SymmetricCipherFinal(const byte *key, size_t length)
Construct a stream cipher.
virtual void CipherResynchronize(const byte *iv, size_t length)
Resynchronize the cipher.
Crypto++ library namespace.
bool IsForwardTransformation() const
Determines if the cipher is a forward transformation.
SymmetricCipher implementation.
Wirte the keystream to the aligned output buffer, input is NULL.
unsigned int GetIterationsToBuffer() const
Provides buffer size based on iterations.
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.
Interface for retrieving values given their names.
Base class for identifying alogorithm.