Crypto++  8.6
Free C++ class library of cryptographic schemes
Classes | Macros | Enumerations | Variables
strciphr.h File Reference

Classes for implementing stream ciphers. More...

Go to the source code of this file.

Classes

class  AbstractPolicyHolder< POLICY_INTERFACE, BASE >
 Access a stream cipher policy object. More...
 
class  ConcretePolicyHolder< POLICY, BASE, POLICY_INTERFACE >
 Stream cipher policy object. More...
 
struct  AdditiveCipherAbstractPolicy
 Policy object for additive stream ciphers. More...
 
struct  AdditiveCipherConcretePolicy< WT, W, X, BASE >
 Base class for additive stream ciphers. More...
 
class  AdditiveCipherTemplate< BASE >
 Base class for additive stream ciphers with SymmetricCipher interface. More...
 
class  CFB_CipherAbstractPolicy
 Policy object for feeback based stream ciphers. More...
 
struct  CFB_CipherConcretePolicy< WT, W, BASE >
 Base class for feedback based stream ciphers. More...
 
struct  CFB_CipherConcretePolicy< WT, W, BASE >::RegisterOutput< B >
 Provides alternate access to a feedback register. More...
 
class  CFB_CipherTemplate< BASE >
 Base class for feedback based stream ciphers with SymmetricCipher interface. More...
 
class  CFB_EncryptionTemplate< BASE >
 Base class for feedback based stream ciphers in the forward direction with SymmetricCipher interface. More...
 
class  CFB_DecryptionTemplate< BASE >
 Base class for feedback based stream ciphers in the reverse direction with SymmetricCipher interface. More...
 
class  CFB_RequireFullDataBlocks< BASE >
 Base class for feedback based stream ciphers with a mandatory block size. More...
 
class  SymmetricCipherFinal< BASE, INFO >
 SymmetricCipher implementation. More...
 

Macros

#define CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, b, i, a)   PutWord(((x & OUTPUT_ALIGNED) != 0), b, output+i*sizeof(WordType), (x & INPUT_NULL) ? (a) : (a) ^ GetWord<WordType>(((x & INPUT_ALIGNED) != 0), b, input+i*sizeof(WordType)));
 Helper macro to implement OperateKeystream. More...
 
#define CRYPTOPP_KEYSTREAM_OUTPUT_XMM(x, i, a)
 Helper macro to implement OperateKeystream. More...
 
#define CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(x, y)
 Helper macro to implement OperateKeystream. More...
 

Enumerations

enum  KeystreamOperationFlags { OUTPUT_ALIGNED =1, INPUT_ALIGNED =2, INPUT_NULL = 4 }
 Keystream operation flags. More...
 
enum  KeystreamOperation {
  WRITE_KEYSTREAM = INPUT_NULL, WRITE_KEYSTREAM_ALIGNED = INPUT_NULL | OUTPUT_ALIGNED, XOR_KEYSTREAM = 0, XOR_KEYSTREAM_INPUT_ALIGNED = INPUT_ALIGNED,
  XOR_KEYSTREAM_OUTPUT_ALIGNED = OUTPUT_ALIGNED, XOR_KEYSTREAM_BOTH_ALIGNED = OUTPUT_ALIGNED | INPUT_ALIGNED
}
 Keystream operation flags. More...
 

Variables

 AbstractPolicyHolder< AdditiveCipherAbstractPolicy, SymmetricCipher >
 
 AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, SymmetricCipher > >
 
 CFB_CipherTemplate< AbstractPolicyHolder< CFB_CipherAbstractPolicy, SymmetricCipher > >
 
 CFB_EncryptionTemplate< AbstractPolicyHolder< CFB_CipherAbstractPolicy, SymmetricCipher > >
 
 CFB_DecryptionTemplate< AbstractPolicyHolder< CFB_CipherAbstractPolicy, SymmetricCipher > >
 

Detailed Description

Classes for implementing stream ciphers.

This file contains helper classes for implementing stream ciphers. All this infrastructure may look very complex compared to what's in Crypto++ 4.x, but stream ciphers implementations now support a lot of new functionality, including better performance (minimizing copying), resetting of keys and IVs, and methods to query which features are supported by a cipher.

Here's an explanation of these classes. The word "policy" is used here to mean a class with a set of methods that must be implemented by individual stream cipher implementations. This is usually much simpler than the full stream cipher API, which is implemented by either AdditiveCipherTemplate or CFB_CipherTemplate using the policy. So for example, an implementation of SEAL only needs to implement the AdditiveCipherAbstractPolicy interface (since it's an additive cipher, i.e., it xors a keystream into the plaintext). See this line in seal.h:

    typedef SymmetricCipherFinal<ConcretePolicyHolder<SEAL_Policy<B>, AdditiveCipherTemplate<> > > Encryption;

AdditiveCipherTemplate and CFB_CipherTemplate are designed so that they don't need to take a policy class as a template parameter (although this is allowed), so that their code is not duplicated for each new cipher. Instead they each get a reference to an abstract policy interface by calling AccessPolicy() on itself, so AccessPolicy() must be overridden to return the actual policy reference. This is done by the ConcretePolicyHolder class. Finally, SymmetricCipherFinal implements the constructors and other functions that must be implemented by the most derived class.

Definition in file strciphr.h.

Macro Definition Documentation

◆ CRYPTOPP_KEYSTREAM_OUTPUT_WORD

#define CRYPTOPP_KEYSTREAM_OUTPUT_WORD (   x,
  b,
  i,
 
)    PutWord(((x & OUTPUT_ALIGNED) != 0), b, output+i*sizeof(WordType), (x & INPUT_NULL) ? (a) : (a) ^ GetWord<WordType>(((x & INPUT_ALIGNED) != 0), b, input+i*sizeof(WordType)));

Helper macro to implement OperateKeystream.

Parameters
xKeystreamOperation mask
bEndian order
iindex in output buffer
avalue to output

Definition at line 253 of file strciphr.h.

◆ CRYPTOPP_KEYSTREAM_OUTPUT_XMM

#define CRYPTOPP_KEYSTREAM_OUTPUT_XMM (   x,
  i,
 
)
Value:
{\
__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));\
if (x & OUTPUT_ALIGNED) _mm_store_si128((__m128i *)output+i, t);\
else _mm_storeu_si128((__m128i *)output+i, t);}

Helper macro to implement OperateKeystream.

Parameters
xKeystreamOperation mask
iindex in output buffer
avalue to output

Definition at line 260 of file strciphr.h.

◆ CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH

#define CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH (   x,
 
)
Value:
switch (operation) \
{ \
break; \
case XOR_KEYSTREAM: \
input += y; \
break; \
input += y; \
break; \
input += y; \
break; \
break; \
input += y; \
break; \
} \
output += y;

Helper macro to implement OperateKeystream.

Definition at line 266 of file strciphr.h.

Enumeration Type Documentation

◆ KeystreamOperationFlags

Keystream operation flags.

See also
AdditiveCipherAbstractPolicy::GetBytesPerIteration(), AdditiveCipherAbstractPolicy::GetOptimalBlockSize() and AdditiveCipherAbstractPolicy::GetAlignment()
Enumerator
OUTPUT_ALIGNED 

Output buffer is aligned.

INPUT_ALIGNED 

Input buffer is aligned.

INPUT_NULL 

Input buffer is NULL.

Definition at line 76 of file strciphr.h.

◆ KeystreamOperation

Keystream operation flags.

See also
AdditiveCipherAbstractPolicy::GetBytesPerIteration(), AdditiveCipherAbstractPolicy::GetOptimalBlockSize() and AdditiveCipherAbstractPolicy::GetAlignment()
Enumerator
WRITE_KEYSTREAM 

Wirte the keystream to the output buffer, input is NULL.

WRITE_KEYSTREAM_ALIGNED 

Wirte the keystream to the aligned output buffer, input is NULL.

XOR_KEYSTREAM 

XOR the input buffer and keystream, write to the output buffer.

XOR_KEYSTREAM_INPUT_ALIGNED 

XOR the aligned input buffer and keystream, write to the output buffer.

XOR_KEYSTREAM_OUTPUT_ALIGNED 

XOR the input buffer and keystream, write to the aligned output buffer.

XOR_KEYSTREAM_BOTH_ALIGNED 

XOR the aligned input buffer and keystream, write to the aligned output buffer.

Definition at line 88 of file strciphr.h.

XOR_KEYSTREAM_BOTH_ALIGNED
@ XOR_KEYSTREAM_BOTH_ALIGNED
XOR the aligned input buffer and keystream, write to the aligned output buffer.
Definition: strciphr.h:100
INPUT_ALIGNED
@ INPUT_ALIGNED
Input buffer is aligned.
Definition: strciphr.h:80
XOR_KEYSTREAM_INPUT_ALIGNED
@ XOR_KEYSTREAM_INPUT_ALIGNED
XOR the aligned input buffer and keystream, write to the output buffer.
Definition: strciphr.h:96
XOR_KEYSTREAM
@ XOR_KEYSTREAM
XOR the input buffer and keystream, write to the output buffer.
Definition: strciphr.h:94
WRITE_KEYSTREAM
@ WRITE_KEYSTREAM
Wirte the keystream to the output buffer, input is NULL.
Definition: strciphr.h:90
INPUT_NULL
@ INPUT_NULL
Input buffer is NULL.
Definition: strciphr.h:82
OUTPUT_ALIGNED
@ OUTPUT_ALIGNED
Output buffer is aligned.
Definition: strciphr.h:78
EnumToInt
#define EnumToInt(v)
Integer value.
Definition: misc.h:502
XOR_KEYSTREAM_OUTPUT_ALIGNED
@ XOR_KEYSTREAM_OUTPUT_ALIGNED
XOR the input buffer and keystream, write to the aligned output buffer.
Definition: strciphr.h:98
WRITE_KEYSTREAM_ALIGNED
@ WRITE_KEYSTREAM_ALIGNED
Wirte the keystream to the aligned output buffer, input is NULL.
Definition: strciphr.h:92