Crypto++  5.6.3
Free C++ class library of cryptographic schemes
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
GCM_Base::GCTR Class Reference
+ Inheritance diagram for GCM_Base::GCTR:

Public Types

typedef AbstractPolicyHolder< AdditiveCipherAbstractPolicy, CTR_ModePolicy >::PolicyInterface PolicyInterface
 
enum  IV_Requirement {
  UNIQUE_IV = 0, RANDOM_IV, UNPREDICTABLE_RANDOM_IV, INTERNALLY_GENERATED_IV,
  NOT_RESYNCHRONIZABLE
}
 Provides IV requirements as an enumerated value. More...
 

Public Member Functions

std::string AlgorithmName () const
 
void GenerateBlock (byte *output, size_t size)
 Generate random array of bytes. More...
 
void ProcessData (byte *outString, const byte *inString, size_t length)
 
void Resynchronize (const byte *iv, int length=-1)
 
unsigned int OptimalBlockSize () const
 
unsigned int GetOptimalNextBlockSize () const
 
unsigned int OptimalDataAlignment () const
 
bool IsSelfInverting () const
 
bool IsForwardTransformation () const
 
bool IsRandomAccess () const
 
void Seek (lword position)
 
bool CipherIsRandomAccess () const
 
IV_Requirement IVRequirement () const
 returns the minimal requirement for secure IVs
 
size_t MinKeyLength () const
 Returns smallest valid key length in bytes.
 
size_t MaxKeyLength () const
 Returns largest valid key length in bytes.
 
size_t DefaultKeyLength () const
 Returns default (recommended) key length in bytes.
 
size_t GetValidKeyLength (size_t n) const
 
bool IsValidKeyLength (size_t n) const
 Returns whether keylength is a valid key length. More...
 
unsigned int IVSize () const
 Returns length of the IV accepted by this object. More...
 
void SetCipher (BlockCipher &cipher)
 
void SetCipherWithIV (BlockCipher &cipher, const byte *iv, int feedbackSize=0)
 
virtual void SetKey (const byte *key, size_t length, const NameValuePairs &params=g_nullNameValuePairs)
 Sets or reset the key of this object. More...
 
void SetKeyWithRounds (const byte *key, size_t length, int rounds)
 Sets or reset the key of this object. More...
 
void SetKeyWithIV (const byte *key, size_t length, const byte *iv, size_t ivLength)
 Sets or reset the key of this object. More...
 
void SetKeyWithIV (const byte *key, size_t length, const byte *iv)
 Sets or reset the key of this object. More...
 
bool IsResynchronizable () const
 returns whether the object can be resynchronized (i.e. supports initialization vectors) More...
 
bool CanUseRandomIVs () const
 returns whether the object can use random IVs (in addition to ones returned by GetNextIV)
 
bool CanUsePredictableIVs () const
 returns whether the object can use random but possibly predictable IVs (in addition to ones returned by GetNextIV)
 
bool CanUseStructuredIVs () const
 returns whether the object can use structured IVs, for example a counter (in addition to ones returned by GetNextIV)
 
unsigned int DefaultIVLength () const
 returns default length of IVs accepted by this object
 
virtual unsigned int MinIVLength () const
 returns minimal length of IVs accepted by this object
 
virtual unsigned int MaxIVLength () const
 returns maximal length of IVs accepted by this object
 
virtual void GetNextIV (RandomNumberGenerator &rng, byte *iv)
 Gets a secure IV for the next message. More...
 
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 GetOptimalBlockSizeUsed () const
 Provides the number of bytes used in the current block when processing at optimal block size. More...
 
virtual void ProcessLastBlock (byte *outString, const byte *inString, size_t length)
 Encrypt or decrypt the last block of data. More...
 
virtual unsigned int MinLastBlockSize () const
 returns the minimum size of the last block, 0 indicating the last block is not special
 
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 ClonableClone () const
 Copies this object. More...
 
virtual unsigned int GetOptimalBlockSize () const
 
virtual void IncorporateEntropy (const byte *input, size_t length)
 Update RNG state with additional unpredictable values. More...
 
virtual bool CanIncorporateEntropy () const
 Determines if a generator can accept additional entropy. More...
 
virtual byte GenerateByte ()
 Generate new random byte and return it. More...
 
virtual unsigned int GenerateBit ()
 Generate new random bit and return it. More...
 
virtual word32 GenerateWord32 (word32 min=0, word32 max=0xffffffffL)
 Generate a random 32 bit word in the range min to max, inclusive. More...
 
virtual void GenerateIntoBufferedTransformation (BufferedTransformation &target, const std::string &channel, lword length)
 Generate random bytes into a BufferedTransformation. More...
 
virtual void DiscardBytes (size_t n)
 Generate and discard n bytes. More...
 
template<class IT >
void Shuffle (IT begin, IT end)
 Randomly shuffle the specified array. More...
 

Static Public Member Functions

static const char * StaticAlgorithmName ()
 

Protected Member Functions

void IncrementCounterBy256 ()
 
const typename AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, CTR_ModePolicy > >::PolicyInterfaceGetPolicy () const
 
typename AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, CTR_ModePolicy > >::PolicyInterfaceAccessPolicy ()
 
void UncheckedSetKey (const byte *key, unsigned int length, const NameValuePairs &params)
 
unsigned int GetBufferByteSize (const PolicyInterface &policy) const
 
byte * KeystreamBufferBegin ()
 
byte * KeystreamBufferEnd ()
 
unsigned int GetAlignment () const
 
unsigned int GetBytesPerIteration () const
 
unsigned int GetIterationsToBuffer () const
 
void WriteKeystream (byte *buffer, size_t iterationCount)
 
bool CanOperateKeystream () const
 
void OperateKeystream (KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount)
 
void CipherResynchronize (byte *keystreamBuffer, const byte *iv, size_t length)
 
void SeekToIteration (lword iterationCount)
 
unsigned int BlockSize () const
 
virtual void SetFeedbackSize (unsigned int feedbackSize)
 
virtual void ResizeBuffers ()
 
const AlgorithmGetAlgorithm () const
 Returns the base class Algorithm. More...
 
void ThrowIfInvalidKeyLength (size_t length)
 Validates the key length. More...
 
void ThrowIfResynchronizable ()
 Validates the object. More...
 
void ThrowIfInvalidIV (const byte *iv)
 Validates the IV. More...
 
size_t ThrowIfInvalidIVLength (int length)
 Validates the IV length. More...
 
const byte * GetIVAndThrowIfInvalid (const NameValuePairs &params, size_t &size)
 retrieves and validates the IV More...
 
void AssertValidKeyLength (size_t length) const
 Validates the key length. More...
 

Protected Attributes

SecByteBlock m_buffer
 
size_t m_leftOver
 
AlignedSecByteBlock m_counterArray
 
BlockCipherm_cipher
 
AlignedSecByteBlock m_register
 

Detailed Description

Definition at line 71 of file gcm.h.

Member Enumeration Documentation

Provides IV requirements as an enumerated value.

Enumerator
UNIQUE_IV 

The IV must be unique.

RANDOM_IV 

The IV must be random.

UNPREDICTABLE_RANDOM_IV 

The IV must be unpredictable.

INTERNALLY_GENERATED_IV 

The IV is set by the object.

NOT_RESYNCHRONIZABLE 

The object does not use an IV.

Definition at line 536 of file cryptlib.h.

Member Function Documentation

void AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, CTR_ModePolicy > >::GenerateBlock ( byte *  output,
size_t  size 
)
virtualinherited

Generate random array of bytes.

Parameters
outputthe byte buffer
sizethe length of the buffer, in bytes
Note
A derived generator must override either GenerateBlock or GenerateIntoBufferedTransformation. They can override both, or have one call the other.

Reimplemented from RandomNumberGenerator.

size_t CipherModeBase::GetValidKeyLength ( size_t  n) const
inlinevirtualinherited
Returns
the smallest valid key length in bytes that is greater than or equal to min(n, GetMaxKeyLength())

Implements SimpleKeyingInterface.

Definition at line 40 of file modes.h.

bool CipherModeBase::IsValidKeyLength ( size_t  keylength) const
inlinevirtualinherited

Returns whether keylength is a valid key length.

Internally the function calls GetValidKeyLength()

Reimplemented from SimpleKeyingInterface.

Definition at line 41 of file modes.h.

unsigned int CipherModeBase::IVSize ( ) const
inlinevirtualinherited

Returns length of the IV accepted by this object.

The default implementation throws NotImplemented

Reimplemented from SimpleKeyingInterface.

Definition at line 45 of file modes.h.

References Name::BlockSize().

const Algorithm& SymmetricCipher::GetAlgorithm ( ) const
inlineprotectedvirtualinherited

Returns the base class Algorithm.

Returns
the base class Algorithm

Implements SimpleKeyingInterface.

Definition at line 924 of file cryptlib.h.

void SimpleKeyingInterface::SetKey ( const byte *  key,
size_t  length,
const NameValuePairs params = g_nullNameValuePairs 
)
virtualinherited

Sets or reset the key of this object.

Parameters
keythe key to use when keying the object
lengththe size of the key, in bytes
paramsadditional initialization parameters that cannot be passed directly through the constructor

Reimplemented in ECB_OneWay, and AuthenticatedSymmetricCipherBase.

Definition at line 100 of file cryptlib.cpp.

References SimpleKeyingInterface::ThrowIfInvalidKeyLength(), and SimpleKeyingInterface::UncheckedSetKey().

Referenced by HKDF< T >::DeriveKey(), RandomPool::GenerateIntoBufferedTransformation(), SimpleKeyingInterface::SetKeyWithIV(), SimpleKeyingInterface::SetKeyWithRounds(), CMAC_Base::UncheckedSetKey(), CBC_MAC_Base::UncheckedSetKey(), VMAC_Base::UncheckedSetKey(), and BlockOrientedCipherModeBase::UncheckedSetKey().

void SimpleKeyingInterface::SetKeyWithRounds ( const byte *  key,
size_t  length,
int  rounds 
)
inherited

Sets or reset the key of this object.

Parameters
keythe key to use when keying the object
lengththe size of the key, in bytes
roundsthe number of rounds to apply the transformation function, if applicable

SetKeyWithRounds calls SetKey with an NameValuePairs object that just specifies rounds. rounds is an integer parameter, and -1 means use the default number of rounds.

Definition at line 106 of file cryptlib.cpp.

References MakeParameters(), Name::Rounds(), and SimpleKeyingInterface::SetKey().

void SimpleKeyingInterface::SetKeyWithIV ( const byte *  key,
size_t  length,
const byte *  iv,
size_t  ivLength 
)
inherited

Sets or reset the key of this object.

Parameters
keythe key to use when keying the object
lengththe size of the key, in bytes
ivthe intiialization vector to use when keying the object
ivLengththe size of the iv, in bytes

SetKeyWithIV calls SetKey with an NameValuePairs object that just specifies iv. iv is a byte array with size ivLength.

Definition at line 111 of file cryptlib.cpp.

References Name::IV(), MakeParameters(), and SimpleKeyingInterface::SetKey().

void SimpleKeyingInterface::SetKeyWithIV ( const byte *  key,
size_t  length,
const byte *  iv 
)
inlineinherited

Sets or reset the key of this object.

Parameters
keythe key to use when keying the object
lengththe size of the key, in bytes
ivthe intiialization vector to use when keying the object

SetKeyWithIV calls SetKey with an NameValuePairs object that just specifies iv. iv is a byte array, and it must have a size IVSize.

Definition at line 532 of file cryptlib.h.

bool SimpleKeyingInterface::IsResynchronizable ( ) const
inlineinherited

returns whether the object can be resynchronized (i.e. supports initialization vectors)

If this function returns true, and no IV is passed to SetKey() and CanUseStructuredIVs()==true, an IV of all 0's will be assumed.

Definition at line 554 of file cryptlib.h.

Referenced by SimpleKeyingInterface::ThrowIfResynchronizable(), and BlockOrientedCipherModeBase::UncheckedSetKey().

void SimpleKeyingInterface::GetNextIV ( RandomNumberGenerator rng,
byte *  iv 
)
virtualinherited

Gets a secure IV for the next message.

Parameters
rnga RandomNumberGenerator to produce keying material
iva block of bytes to receive the IV

This method should be called after you finish encrypting one message and are ready to start the next one. After calling it, you must call SetKey() or Resynchronize() before using this object again.

key must be at least IVSize() in length.

Note
This method is not implemented on decryption objects.

Reimplemented in VMAC_Base.

Definition at line 176 of file cryptlib.cpp.

References RandomNumberGenerator::GenerateBlock(), and SimpleKeyingInterface::IVSize().

Referenced by VMAC_Base::GetNextIV().

void SimpleKeyingInterface::ThrowIfInvalidKeyLength ( size_t  length)
protectedinherited

Validates the key length.

Parameters
lengththe size of the keying material, in bytes
Exceptions
InvalidKeyLengthif the key length is invalid

Definition at line 116 of file cryptlib.cpp.

References SimpleKeyingInterface::GetAlgorithm(), and SimpleKeyingInterface::IsValidKeyLength().

Referenced by SimpleKeyingInterface::SetKey().

void SimpleKeyingInterface::ThrowIfResynchronizable ( )
protectedinherited

Validates the object.

Exceptions
InvalidArgumentif the IV is present

Internally, the default implementation calls IsResynchronizable() and throws InvalidArgument if the function returns true.

Note
called when no IV is passed

Definition at line 122 of file cryptlib.cpp.

References SimpleKeyingInterface::GetAlgorithm(), and SimpleKeyingInterface::IsResynchronizable().

Referenced by SimpleKeyingInterface::GetIVAndThrowIfInvalid().

void SimpleKeyingInterface::ThrowIfInvalidIV ( const byte *  iv)
protectedinherited

Validates the IV.

Parameters
ivthe IV with a length of IVSize, in bytes
Exceptions
InvalidArgumenton failure

Internally, the default implementation checks the iv. If iv is not NULL, then the function succeeds. If iv is NULL, then IVRequirement is checked against UNPREDICTABLE_RANDOM_IV. If IVRequirement is UNPREDICTABLE_RANDOM_IV, then then the function succeeds. Otherwise, an exception is thrown.

Definition at line 128 of file cryptlib.cpp.

References SimpleKeyingInterface::GetAlgorithm(), SimpleKeyingInterface::IVRequirement(), and SimpleKeyingInterface::UNPREDICTABLE_RANDOM_IV.

Referenced by SimpleKeyingInterface::GetIVAndThrowIfInvalid().

size_t SimpleKeyingInterface::ThrowIfInvalidIVLength ( int  length)
protectedinherited
const byte * SimpleKeyingInterface::GetIVAndThrowIfInvalid ( const NameValuePairs params,
size_t &  size 
)
protectedinherited

retrieves and validates the IV

Parameters
paramsNameValuePairs with the IV supplied as a ConstByteArrayParameter
sizethe length of the IV, in bytes
Returns
a pointer to the first byte of the IV
Exceptions
InvalidArgumentif the number of rounds are invalid

Definition at line 146 of file cryptlib.cpp.

References NameValuePairs::GetValue(), Name::IV(), SimpleKeyingInterface::IVSize(), SimpleKeyingInterface::ThrowIfInvalidIV(), SimpleKeyingInterface::ThrowIfInvalidIVLength(), and SimpleKeyingInterface::ThrowIfResynchronizable().

Referenced by AuthenticatedSymmetricCipherBase::SetKey(), VMAC_Base::UncheckedSetKey(), and BlockOrientedCipherModeBase::UncheckedSetKey().

void SimpleKeyingInterface::AssertValidKeyLength ( size_t  length) const
inlineprotectedinherited

Validates the key length.

Parameters
lengththe size of the keying material, in bytes

Definition at line 635 of file cryptlib.h.

StreamTransformation& StreamTransformation::Ref ( )
inlineinherited

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 737 of file cryptlib.h.

virtual unsigned int StreamTransformation::MandatoryBlockSize ( ) const
inlinevirtualinherited

Provides the mandatory block size of the cipher.

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

Reimplemented in BlockOrientedCipherModeBase.

Definition at line 741 of file cryptlib.h.

Referenced by StreamTransformation::ProcessLastBlock(), and StreamTransformationFilter::StreamTransformationFilter().

virtual unsigned int StreamTransformation::GetOptimalBlockSizeUsed ( ) const
inlinevirtualinherited

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 751 of file cryptlib.h.

void StreamTransformation::ProcessLastBlock ( byte *  outString,
const byte *  inString,
size_t  length 
)
virtualinherited

Encrypt or decrypt the last block of data.

Parameters
outStringthe output byte buffer
inStringthe input byte buffer
lengththe size of the input and output byte buffers, in bytes ProcessLastBlock is used when the last block of data is special. Currently the only use of this function is CBC-CTS mode.

Reimplemented in CBC_CTS_Decryption, and CBC_CTS_Encryption.

Definition at line 234 of file cryptlib.cpp.

References Algorithm::AlgorithmName(), StreamTransformation::MandatoryBlockSize(), StreamTransformation::MinLastBlockSize(), and StreamTransformation::ProcessData().

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

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 779 of file cryptlib.h.

Referenced by AuthenticatedSymmetricCipher::DecryptAndVerify(), and AuthenticatedSymmetricCipher::EncryptAndAuthenticate().

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

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 787 of file cryptlib.h.

byte StreamTransformation::ProcessByte ( byte  input)
inlineinherited

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 793 of file cryptlib.h.

virtual Clonable* Clonable::Clone ( ) const
inlinevirtualinherited

Copies this object.

Returns
a copy of this object
Exceptions
NotImplemented
Note
this is not implemented by most classes
See also
NotCopyable

Definition at line 445 of file cryptlib.h.

virtual void RandomNumberGenerator::IncorporateEntropy ( const byte *  input,
size_t  length 
)
inlinevirtualinherited

Update RNG state with additional unpredictable values.

Parameters
inputthe entropy to add to the generator
lengththe size of the input buffer
Exceptions
NotImplemented

A generator may or may not accept additional entropy. Call CanIncorporateEntropy to test for the ability to use additional entropy.

If a derived class does not override IncorporateEntropy, then the base class throws NotImplemented.

Reimplemented in RDSEED, AutoSeededX917RNG< BLOCK_CIPHER >, RDRAND, and RandomPool.

Definition at line 997 of file cryptlib.h.

Referenced by RandomNumberSink::Put2(), and DL_SignerBase< SCHEME_OPTIONS::Element >::SignAndRestart().

virtual bool RandomNumberGenerator::CanIncorporateEntropy ( ) const
inlinevirtualinherited

Determines if a generator can accept additional entropy.

Returns
true if IncorporateEntropy is implemented

Reimplemented in AutoSeededX917RNG< BLOCK_CIPHER >, and RandomPool.

Definition at line 1005 of file cryptlib.h.

Referenced by DL_SignerBase< SCHEME_OPTIONS::Element >::SignAndRestart().

byte RandomNumberGenerator::GenerateByte ( )
virtualinherited

Generate new random byte and return it.

default implementation is to call GenerateBlock() with one byte

Reimplemented in PublicBlumBlumShub.

Definition at line 281 of file cryptlib.cpp.

References RandomNumberGenerator::GenerateBlock().

Referenced by RandomNumberGenerator::GenerateBit().

unsigned int RandomNumberGenerator::GenerateBit ( )
virtualinherited

Generate new random bit and return it.

Returns
a random bit

The default implementation calls GenerateByte() and return its lowest bit.

Reimplemented in PublicBlumBlumShub.

Definition at line 276 of file cryptlib.cpp.

References RandomNumberGenerator::GenerateByte().

word32 RandomNumberGenerator::GenerateWord32 ( word32  min = 0,
word32  max = 0xffffffffL 
)
virtualinherited

Generate a random 32 bit word in the range min to max, inclusive.

Parameters
minthe lower bound of the range
maxthe upper bound of the range
Returns
a random 32-bit word

The default implementation calls Crop on the difference between max and min, and then returns the result added to min.

Reimplemented in MersenneTwister< K, M, N, F, S >.

Definition at line 288 of file cryptlib.cpp.

References BitPrecision(), Crop(), and RandomNumberGenerator::GenerateBlock().

void RandomNumberGenerator::GenerateIntoBufferedTransformation ( BufferedTransformation target,
const std::string &  channel,
lword  length 
)
virtualinherited

Generate random bytes into a BufferedTransformation.

Parameters
targetthe BufferedTransformation object which receives the bytes
channelthe channel on which the bytes should be pumped
lengththe number of bytes to generate

The default implementation calls GenerateBlock() and pumps the result into the DEFAULT_CHANNEL of the target.

Note
A derived generator must override either GenerateBlock or GenerateIntoBufferedTransformation. They can override both, or have one call the other.

Reimplemented in AutoSeededX917RNG< BLOCK_CIPHER >, X917RNG, and RandomPool.

Definition at line 334 of file cryptlib.cpp.

References BufferedTransformation::ChannelPut(), RandomNumberGenerator::GenerateBlock(), SecBlock< T, A >::size(), and UnsignedMin().

Referenced by RandomNumberGenerator::DiscardBytes(), RandomNumberGenerator::GenerateBlock(), AutoSeededX917RNG< BLOCK_CIPHER >::GenerateIntoBufferedTransformation(), and RandomNumberStore::TransferTo2().

void RandomNumberGenerator::DiscardBytes ( size_t  n)
virtualinherited

Generate and discard n bytes.

Parameters
nthe number of bytes to generate and discard

Reimplemented in RDSEED, MersenneTwister< K, M, N, F, S >, RDRAND, and Weak::ARC4_Base.

Definition at line 329 of file cryptlib.cpp.

References RandomNumberGenerator::GenerateIntoBufferedTransformation(), and TheBitBucket().

template<class IT >
void RandomNumberGenerator::Shuffle ( IT  begin,
IT  end 
)
inlineinherited

Randomly shuffle the specified array.

Parameters
beginan iterator to the first element in the array
endan iterator beyond the last element in the array

The resulting permutation is uniformly distributed.

Definition at line 1049 of file cryptlib.h.


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