Security Scol plugin
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
AdditiveCipherTemplate< BASE > Class Template Reference

Base class for additive stream ciphers with SymmetricCipher interface. More...

#include <strciphr.h>

Inheritance diagram for AdditiveCipherTemplate< BASE >:
AbstractPolicyHolder< POLICY_INTERFACE, BASE > RandomNumberGenerator Empty Algorithm Clonable ConcretePolicyHolder< ChaChaTLS_Policy, AdditiveCipherTemplate<> > ConcretePolicyHolder< XChaCha20_Policy, AdditiveCipherTemplate<> > SimpleKeyingInterfaceImpl< ConcretePolicyHolder< ChaChaTLS_Policy, AdditiveCipherTemplate<> >, ChaChaTLS_Info > SimpleKeyingInterfaceImpl< ConcretePolicyHolder< XChaCha20_Policy, AdditiveCipherTemplate<> >, XChaCha20_Info > AlgorithmImpl< SimpleKeyingInterfaceImpl< ConcretePolicyHolder< ChaChaTLS_Policy, AdditiveCipherTemplate<> >, ChaChaTLS_Info >, ChaChaTLS_Info > AlgorithmImpl< SimpleKeyingInterfaceImpl< ConcretePolicyHolder< XChaCha20_Policy, AdditiveCipherTemplate<> >, XChaCha20_Info >, XChaCha20_Info >

Public Types

typedef BASE::PolicyInterface PolicyInterface
 
- Public Types inherited from AbstractPolicyHolder< POLICY_INTERFACE, BASE >
typedef POLICY_INTERFACE PolicyInterface
 

Public Member Functions

void GenerateBlock (byte *output, size_t size)
 Generate random array of bytes.
 
void ProcessData (byte *outString, const byte *inString, size_t length)
 Apply keystream to data.
 
void Resynchronize (const byte *iv, int length=-1)
 Resynchronize the cipher.
 
unsigned int OptimalBlockSize () const
 Provides number of ideal bytes to process.
 
unsigned int GetOptimalNextBlockSize () const
 Provides number of ideal bytes to process.
 
unsigned int OptimalDataAlignment () const
 Provides number of ideal data alignment.
 
bool IsSelfInverting () const
 Determines if the cipher is self inverting.
 
bool IsForwardTransformation () const
 Determines if the cipher is a forward transformation.
 
bool IsRandomAccess () const
 Flag indicating random access.
 
void Seek (lword position)
 Seeks to a random position in the stream.
 
std::string AlgorithmProvider () const
 Retrieve the provider of this algorithm.
 
- Public Member Functions inherited from RandomNumberGenerator
virtual void IncorporateEntropy (const byte *input, size_t length)
 Update RNG state with additional unpredictable values.
 
virtual bool CanIncorporateEntropy () const
 Determines if a generator can accept additional entropy.
 
virtual byte GenerateByte ()
 Generate new random byte and return it.
 
virtual unsigned int GenerateBit ()
 Generate new random bit and return it.
 
virtual word32 GenerateWord32 (word32 min=0, word32 max=0xffffffffUL)
 Generate a random 32 bit word in the range min to max, inclusive.
 
virtual void GenerateIntoBufferedTransformation (BufferedTransformation &target, const std::string &channel, lword length)
 Generate random bytes into a BufferedTransformation.
 
virtual void DiscardBytes (size_t n)
 Generate and discard n bytes.
 
template<class IT >
void Shuffle (IT begin, IT end)
 Randomly shuffle the specified array.
 
- Public Member Functions inherited from Algorithm
 Algorithm (bool checkSelfTestStatus=true)
 Interface for all crypto algorithms.
 
virtual std::string AlgorithmName () const
 Provides the name of this algorithm.
 
- Public Member Functions inherited from Clonable
virtual ClonableClone () const
 Copies this object.
 

Protected Member Functions

void UncheckedSetKey (const byte *key, unsigned int length, const NameValuePairs &params)
 
unsigned int GetBufferByteSize (const PolicyInterface &policy) const
 
byteKeystreamBufferBegin ()
 
byteKeystreamBufferEnd ()
 
- Protected Member Functions inherited from AbstractPolicyHolder< POLICY_INTERFACE, BASE >
virtual const POLICY_INTERFACE & GetPolicy () const =0
 
virtual POLICY_INTERFACE & AccessPolicy ()=0
 

Protected Attributes

AlignedSecByteBlock m_buffer
 
size_t m_leftOver
 

Detailed Description

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
class AdditiveCipherTemplate< BASE >

Base class for additive stream ciphers with SymmetricCipher interface.

Template Parameters
BASEAbstractPolicyHolder base class

Definition at line 297 of file strciphr.h.

Member Typedef Documentation

◆ PolicyInterface

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
typedef BASE::PolicyInterface AdditiveCipherTemplate< BASE >::PolicyInterface

Definition at line 387 of file strciphr.h.

Constructor & Destructor Documentation

◆ ~AdditiveCipherTemplate()

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
virtual AdditiveCipherTemplate< BASE >::~AdditiveCipherTemplate ( )
inlinevirtual

Definition at line 300 of file strciphr.h.

◆ AdditiveCipherTemplate()

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
AdditiveCipherTemplate< BASE >::AdditiveCipherTemplate ( )
inline

Definition at line 301 of file strciphr.h.

Member Function Documentation

◆ AlgorithmProvider()

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
std::string AdditiveCipherTemplate< BASE >::AlgorithmProvider ( ) const
inlinevirtual

Retrieve the provider of this algorithm.

Returns
the algorithm provider

The algorithm provider can be a name like "C++", "SSE", "NEON", "AESNI", "ARMv8" and "Power8". C++ is standard C++ code. Other labels, like SSE, usually indicate a specialized implementation using instructions from a higher instruction set architecture (ISA). Future labels may include external hardware like a hardware security module (HSM).

Generally speaking Wei Dai's original IA-32 ASM code falls under "SSE2". Labels like "SSSE3" and "SSE4.1" follow after Wei's code and use intrinsics instead of ASM.

Algorithms which combine different instructions or ISAs provide the dominant one. For example on x86 AES/GCM returns "AESNI" rather than "CLMUL" or "AES+SSE4.1" or "AES+CLMUL" or "AES+SSE4.1+CLMUL".

Note
Provider is not universally implemented yet.

Reimplemented from Algorithm.

Definition at line 385 of file strciphr.h.

◆ GenerateBlock()

template<class S >
void AdditiveCipherTemplate< S >::GenerateBlock ( byte output,
size_t  size 
)
virtual

Generate random array of bytes.

Parameters
outputthe byte buffer
sizethe length of the buffer, in bytes

All generated values are uniformly distributed over the range specified within the constraints of a particular generator.

Reimplemented from RandomNumberGenerator.

Definition at line 45 of file strciphr.cpp.

◆ GetBufferByteSize()

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
unsigned int AdditiveCipherTemplate< BASE >::GetBufferByteSize ( const PolicyInterface &  policy) const
inlineprotected

Definition at line 392 of file strciphr.h.

◆ GetOptimalNextBlockSize()

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
unsigned int AdditiveCipherTemplate< BASE >::GetOptimalNextBlockSize ( ) const
inline

Provides number of ideal bytes to process.

Returns
the ideal number of bytes to process

Internally, the default implementation returns remaining unprocessed bytes

See also
GetBytesPerIteration() and OptimalBlockSize()

Definition at line 346 of file strciphr.h.

◆ IsForwardTransformation()

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
bool AdditiveCipherTemplate< BASE >::IsForwardTransformation ( ) const
inline

Determines if the cipher is a forward transformation.

Returns
true if the stream cipher is a forward transformation, false otherwise

Definition at line 359 of file strciphr.h.

◆ IsRandomAccess()

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
bool AdditiveCipherTemplate< BASE >::IsRandomAccess ( ) const
inline

Flag indicating random access.

Returns
true if the cipher is seekable, false otherwise
See also
Seek()

Definition at line 364 of file strciphr.h.

◆ IsSelfInverting()

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
bool AdditiveCipherTemplate< BASE >::IsSelfInverting ( ) const
inline

Determines if the cipher is self inverting.

Returns
true if the stream cipher is self inverting, false otherwise

Definition at line 355 of file strciphr.h.

◆ KeystreamBufferBegin()

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
byte * AdditiveCipherTemplate< BASE >::KeystreamBufferBegin ( )
inlineprotected

Definition at line 394 of file strciphr.h.

◆ KeystreamBufferEnd()

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
byte * AdditiveCipherTemplate< BASE >::KeystreamBufferEnd ( )
inlineprotected

Definition at line 395 of file strciphr.h.

◆ OptimalBlockSize()

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
unsigned int AdditiveCipherTemplate< BASE >::OptimalBlockSize ( ) const
inline

Provides number of ideal bytes to process.

Returns
the ideal number of bytes to process

Internally, the default implementation returns GetBytesPerIteration()

See also
GetBytesPerIteration() and GetOptimalNextBlockSize()

Definition at line 340 of file strciphr.h.

◆ OptimalDataAlignment()

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
unsigned int AdditiveCipherTemplate< BASE >::OptimalDataAlignment ( ) const
inline

Provides number of ideal data alignment.

Returns
the ideal data alignment, in bytes
See also
GetAlignment() and OptimalBlockSize()

Definition at line 351 of file strciphr.h.

◆ ProcessData()

template<class S >
void AdditiveCipherTemplate< S >::ProcessData ( byte outString,
const byte inString,
size_t  length 
)

Apply keystream to data.

Parameters
outStringa buffer to write the transformed data
inStringa buffer to read the data
lengththe size of the buffers, in bytes

This is the primary method to operate a stream cipher. For example:

    size_t size = 30;
    byte plain[size] = "Do or do not; there is no try";
    byte cipher[size];
    ...
    ChaCha20 chacha(key, keySize);
    chacha.ProcessData(cipher, plain, size);

You should use distinct buffers for inString and outString. If the buffers are the same, then the data will be copied to an internal buffer to avoid GCC alias violations. The internal copy will impact performance.

See also
Issue 1088, 36% loss of performance with AES, Issue 1010, HIGHT cipher troubles with FileSource

Definition at line 91 of file strciphr.cpp.

◆ Resynchronize()

template<class S >
void AdditiveCipherTemplate< S >::Resynchronize ( const byte iv,
int  length = -1 
)

Resynchronize the cipher.

Parameters
iva byte array used to resynchronize the cipher
lengththe size of the IV array

Definition at line 159 of file strciphr.cpp.

◆ Seek()

template<class BASE >
void AdditiveCipherTemplate< BASE >::Seek ( lword  position)

Seeks to a random position in the stream.

Parameters
positionthe absolute position in the stream
See also
IsRandomAccess()

Definition at line 168 of file strciphr.cpp.

◆ UncheckedSetKey()

template<class S >
void AdditiveCipherTemplate< S >::UncheckedSetKey ( const byte key,
unsigned int  length,
const NameValuePairs params 
)
protected

Definition at line 28 of file strciphr.cpp.

Member Data Documentation

◆ m_buffer

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
AlignedSecByteBlock AdditiveCipherTemplate< BASE >::m_buffer
protected

Definition at line 397 of file strciphr.h.

◆ m_leftOver

template<class BASE = AbstractPolicyHolder<AdditiveCipherAbstractPolicy, SymmetricCipher>>
size_t AdditiveCipherTemplate< BASE >::m_leftOver
protected

Definition at line 398 of file strciphr.h.


The documentation for this class was generated from the following files: