Crypto++  5.6.5
Free C++ class library of cryptographic schemes
Public Member Functions | List of all members
StreamTransformation Class Referenceabstract

Interface for the data processing portion of stream ciphers. More...

+ Inheritance diagram for StreamTransformation:

Public Member Functions

StreamTransformationRef ()
 Provides a reference to this object. More...
 
virtual unsigned int MandatoryBlockSize () const
 Provides the mandatory block size of the cipher. More...
 
virtual unsigned int OptimalBlockSize () const
 Provides the input block size most efficient for this cipher. More...
 
virtual unsigned int GetOptimalBlockSizeUsed () const
 Provides the number of bytes used in the current block when processing at optimal block size. More...
 
virtual unsigned int OptimalDataAlignment () const
 Provides input and output data alignment for optimal performance. More...
 
virtual void ProcessData (byte *outString, const byte *inString, size_t length)=0
 Encrypt or decrypt an array of bytes. More...
 
virtual size_t ProcessLastBlock (byte *outString, size_t outLength, const byte *inString, size_t inLength)
 Encrypt or decrypt the last block of data. More...
 
virtual unsigned int MinLastBlockSize () const
 Provides the size of the last block. More...
 
virtual bool IsLastBlockSpecial () const
 Determines if the last block receives special processing. More...
 
void ProcessString (byte *inoutString, size_t length)
 Encrypt or decrypt a string of bytes. More...
 
void ProcessString (byte *outString, const byte *inString, size_t length)
 Encrypt or decrypt a string of bytes. More...
 
byte ProcessByte (byte input)
 Encrypt or decrypt a byte. More...
 
virtual bool IsRandomAccess () const =0
 Determines whether the cipher supports random access. More...
 
virtual void Seek (lword pos)
 Seek to an absolute position. More...
 
virtual bool IsSelfInverting () const =0
 Determines whether the cipher is self-inverting. More...
 
virtual bool IsForwardTransformation () const =0
 Determines if the cipher is being operated in its forward direction. More...
 
- Public Member Functions inherited from Algorithm
 Algorithm (bool checkSelfTestStatus=true)
 Interface for all crypto algorithms. More...
 
virtual std::string AlgorithmName () const
 Provides the name of this algorithm. More...
 
- Public Member Functions inherited from Clonable
virtual ClonableClone () const
 Copies this object. More...
 

Detailed Description

Interface for the data processing portion of stream ciphers.

See also
StreamTransformationFilter()

Definition at line 908 of file cryptlib.h.

Member Function Documentation

◆ Ref()

StreamTransformation& StreamTransformation::Ref ( )
inline

Provides a reference to this object.

Returns
A reference to this object

Useful for passing a temporary object to a function that takes a non-const reference

Definition at line 916 of file cryptlib.h.

◆ MandatoryBlockSize()

virtual unsigned int StreamTransformation::MandatoryBlockSize ( ) const
inlinevirtual

Provides the mandatory block size of the cipher.

Returns
The block size of the cipher if input must be processed in blocks, 1 otherwise

Stream ciphers and some block ciphers modes of operation return 1. Modes that return 1 must be able to process a single byte at a time, like counter mode. If a mode of operation or block cipher cannot stream then it must not return 1.

When filters operate the mode or cipher, ProcessData will be called with a string of bytes that is determined by MandatoryBlockSize and OptimalBlockSize. When a policy is set, like 16-byte strings for a 16-byte block cipher, the filter will buffer bytes until the specified number of bytes is available to the object.

See also
ProcessData, ProcessLastBlock, MandatoryBlockSize, MinLastBlockSize, BlockPaddingSchemeDef, IsLastBlockSpecial

Reimplemented in BlockOrientedCipherModeBase.

Definition at line 928 of file cryptlib.h.

◆ OptimalBlockSize()

virtual unsigned int StreamTransformation::OptimalBlockSize ( ) const
inlinevirtual

Provides the input block size most efficient for this cipher.

Returns
The input block size that is most efficient for the cipher

The base class implementation returns MandatoryBlockSize().

Note
Optimal input length is n * OptimalBlockSize() - GetOptimalBlockSizeUsed() for any n > 0.

Reimplemented in AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, CTR_ModePolicy > >, and ECB_OneWay.

Definition at line 935 of file cryptlib.h.

◆ GetOptimalBlockSizeUsed()

virtual unsigned int StreamTransformation::GetOptimalBlockSizeUsed ( ) const
inlinevirtual

Provides the number of bytes used in the current block when processing at optimal block size.

Returns
the number of bytes used in the current block when processing at the optimal block size

Definition at line 939 of file cryptlib.h.

◆ OptimalDataAlignment()

unsigned int StreamTransformation::OptimalDataAlignment ( ) const
virtual

Provides input and output data alignment for optimal performance.

Returns
the input data alignment that provides optimal performance

Reimplemented in AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, CTR_ModePolicy > >, CipherModeBase, GCM_Base, CCM_Base, and EAX_Base.

Definition at line 199 of file cryptlib.cpp.

◆ ProcessData()

virtual void StreamTransformation::ProcessData ( byte *  outString,
const byte *  inString,
size_t  length 
)
pure virtual

Encrypt or decrypt an array of bytes.

Parameters
outStringthe output byte buffer
inStringthe input byte buffer
lengththe size of the input and output byte buffers, in bytes

ProcessData is called with a string of bytes whose size depends on MandatoryBlockSize. Either inString == outString, or they must not overlap.

See also
ProcessData, ProcessLastBlock, MandatoryBlockSize, MinLastBlockSize, BlockPaddingSchemeDef, IsLastBlockSpecial

Implemented in AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, CTR_ModePolicy > >, CBC_Decryption, CBC_Encryption, ECB_OneWay, AuthenticatedSymmetricCipherBase, Weak::ARC4_Base, and PublicBlumBlumShub.

◆ ProcessLastBlock()

size_t StreamTransformation::ProcessLastBlock ( byte *  outString,
size_t  outLength,
const byte *  inString,
size_t  inLength 
)
virtual

Encrypt or decrypt the last block of data.

Parameters
outStringthe output byte buffer
outLengththe size of the output byte buffer, in bytes
inStringthe input byte buffer
inLengththe size of the input byte buffer, in bytes
Returns
the number of bytes used in outString

ProcessLastBlock is used when the last block of data is special and requires handling by the cipher. The current implementation provides an output buffer with a size inLength+2*MandatoryBlockSize(). The return value allows the cipher to expand cipher text during encryption or shrink plain text during decryption.

This member function is used by CBC-CTS and OCB modes.

See also
ProcessData, ProcessLastBlock, MandatoryBlockSize, MinLastBlockSize, BlockPaddingSchemeDef, IsLastBlockSpecial

Reimplemented in CBC_CTS_Decryption, and CBC_CTS_Encryption.

Definition at line 221 of file cryptlib.cpp.

◆ MinLastBlockSize()

virtual unsigned int StreamTransformation::MinLastBlockSize ( ) const
inlinevirtual

Provides the size of the last block.

Returns
the minimum size of the last block

MinLastBlockSize() returns the minimum size of the last block. 0 indicates the last block is not special.

MandatoryBlockSize() enlists one of two behaviors. First, if MandatoryBlockSize() returns 1, then the cipher can be streamed and ProcessData() is called with the tail bytes. Second, if MandatoryBlockSize() returns non-0, then the string of bytes is padded to MandatoryBlockSize() according to the padding mode. Then, ProcessData() is called with the padded string of bytes.

Some authenticated encryption modes are not expressed well with MandatoryBlockSize() and MinLastBlockSize(). For example, AES/OCB uses 16-byte blocks (MandatoryBlockSize = 16) and the last block requires special processing (MinLastBlockSize = 0). However, 0 is a valid last block size for OCB and the special processing is custom padding, and not standard PKCS padding. In response an unambiguous IsLastBlockSpecial() was added.

See also
ProcessData, ProcessLastBlock, MandatoryBlockSize, MinLastBlockSize, BlockPaddingSchemeDef, IsLastBlockSpecial

Reimplemented in CBC_CTS_Decryption, CBC_CTS_Encryption, and CBC_ModeBase.

Definition at line 983 of file cryptlib.h.

◆ IsLastBlockSpecial()

virtual bool StreamTransformation::IsLastBlockSpecial ( ) const
inlinevirtual

Determines if the last block receives special processing.

Returns
true if the last block reveives special processing, false otherwise.

Some authenticated encryption modes are not expressed well with MandatoryBlockSize() and MinLastBlockSize(). For example, AES/OCB uses 16-byte blocks (MandatoryBlockSize = 16) and the last block requires special processing (MinLastBlockSize = 0). However, 0 is a valid last block size for OCB and the special processing is custom padding, and not standard PKCS padding. In response an unambiguous IsLastBlockSpecial() was added.

When IsLastBlockSpecial() returns false nothing special happens. All the former rules and behaviors apply. This is the default behavior of IsLastBlockSpecial().

When IsLastBlockSpecial() returns true four things happen. First, MinLastBlockSize = 0 means 0 is a valid block size that should be processed. Second, standard block cipher padding is not applied. Third, the caller supplies an outString is larger than inString by 2*MandatoryBlockSize(). That is, there's a reserve available when processing the last block. Fourth, the cipher is responsible for finalization like custom padding. The cipher will tell the library how many bytes were processed or used by returning the appropriate value from ProcessLastBlock().

The return value of ProcessLastBlock() indicates how many bytes were written to outString. A filter pipelining data will send outString and up to outLength to an AttachedTransformation() for additional processing. Below is an example of the code used in StreamTransformationFilter::LastPut.

  if (m_cipher.IsLastBlockSpecial())
  {
    size_t reserve = 2*m_cipher.MandatoryBlockSize();
    space = HelpCreatePutSpace(*AttachedTransformation(), DEFAULT_CHANNEL, length+reserve);
    length = m_cipher.ProcessLastBlock(space, length+reserve, inString, length);
    AttachedTransformation()->Put(space, length);
    return;
  }
See also
ProcessData, ProcessLastBlock, MandatoryBlockSize, MinLastBlockSize, BlockPaddingSchemeDef, IsLastBlockSpecial
Since
Crypto++ 6.0

Definition at line 1016 of file cryptlib.h.

◆ ProcessString() [1/2]

void StreamTransformation::ProcessString ( byte *  inoutString,
size_t  length 
)
inline

Encrypt or decrypt a string of bytes.

Parameters
inoutStringthe string to process
lengththe size of the inoutString, in bytes

Internally, the base class implementation calls ProcessData().

Definition at line 1022 of file cryptlib.h.

◆ ProcessString() [2/2]

void StreamTransformation::ProcessString ( byte *  outString,
const byte *  inString,
size_t  length 
)
inline

Encrypt or decrypt a string of bytes.

Parameters
outStringthe output string to process
inStringthe input string to process
lengththe size of the input and output strings, in bytes

Internally, the base class implementation calls ProcessData().

Definition at line 1030 of file cryptlib.h.

◆ ProcessByte()

byte StreamTransformation::ProcessByte ( byte  input)
inline

Encrypt or decrypt a byte.

Parameters
inputthe input byte to process

Internally, the base class implementation calls ProcessData() with a size of 1.

Definition at line 1036 of file cryptlib.h.

◆ IsRandomAccess()

virtual bool StreamTransformation::IsRandomAccess ( ) const
pure virtual

Determines whether the cipher supports random access.

Returns
true if the cipher supports random access, false otherwise

Implemented in AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, CTR_ModePolicy > >, BlockOrientedCipherModeBase, BlumBlumShub, AuthenticatedSymmetricCipherBase, and Weak::ARC4_Base.

◆ Seek()

virtual void StreamTransformation::Seek ( lword  pos)
inlinevirtual

Seek to an absolute position.

Parameters
posposition to seek
Exceptions
NotImplemented

The base class implementation throws NotImplemented. The function asserts IsRandomAccess() in debug builds.

Reimplemented in AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, CTR_ModePolicy > >, and BlumBlumShub.

Definition at line 1048 of file cryptlib.h.

◆ IsSelfInverting()

virtual bool StreamTransformation::IsSelfInverting ( ) const
pure virtual

Determines whether the cipher is self-inverting.

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

IsSelfInverting determines whether this transformation is self-inverting (e.g. xor with a keystream).

Implemented in AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, CTR_ModePolicy > >, BlockOrientedCipherModeBase, AuthenticatedSymmetricCipherBase, Weak::ARC4_Base, and PublicBlumBlumShub.

◆ IsForwardTransformation()

virtual bool StreamTransformation::IsForwardTransformation ( ) const
pure virtual

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