Crypto++ 8.5 Free C++ class library of cryptographic schemes

Public Types | Public Member Functions | List of all members
SimpleKeyingInterface Class Referenceabstract

Interface for algorithms that take byte strings as keys. More...

Inheritance diagram for SimpleKeyingInterface:

## Public Types
enum | IV_Requirement { UNIQUE_IV = 0, RANDOM_IV, UNPREDICTABLE_RANDOM_IV, INTERNALLY_GENERATED_IV, NOT_RESYNCHRONIZABLE }
| Secure IVs requirements as enumerated values. More...

## Public Member Functions
virtual size_t | MinKeyLength () const =0
| Returns smallest valid key length. More...
virtual size_t | MaxKeyLength () const =0
| Returns largest valid key length. More...
virtual size_t | DefaultKeyLength () const =0
| Returns default key length. More...
virtual size_t | GetValidKeyLength (size_t keylength) const =0
| Returns a valid key length for the algorithm. More...
virtual bool | IsValidKeyLength (size_t keylength) const
| Returns whether keylength is a valid key length. More...
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...
virtual IV_Requirement | IVRequirement () const =0
| Minimal requirement for secure IVs. More...
bool | IsResynchronizable () const
| Determines if the object can be resynchronized. More...
bool | CanUseRandomIVs () const
| Determines if the object can use random IVs. More...
bool | CanUsePredictableIVs () const
| Determines if the object can use random but possibly predictable IVs. More...
bool | CanUseStructuredIVs () const
| Determines if the object can use structured IVs. More...
virtual unsigned int | IVSize () const
| Returns length of the IV accepted by this object. More...
unsigned int | DefaultIVLength () const
| Provides the default size of an IV. More...
virtual unsigned int | MinIVLength () const
| Provides the minimum size of an IV. More...
virtual unsigned int | MaxIVLength () const
| Provides the maximum size of an IV. More...
virtual void | Resynchronize (const byte *iv, int ivLength=-1)
| Resynchronize with an IV. More...
virtual void | GetNextIV (RandomNumberGenerator &rng, byte *iv)
| Retrieves a secure IV for the next message. More...

## Detailed Description

Interface for algorithms that take byte strings as keys.

See also
  FixedKeyLength(), VariableKeyLength(), SameKeyLengthAs(), SimpleKeyingInterfaceImpl()

Definition at line 641 of file cryptlib.h.

## Member Enumeration Documentation

## ◆ IV_Requirement

enum SimpleKeyingInterface::IV_Requirement

Secure IVs requirements as enumerated values.

Provides secure IV requirements as a monotonically increasing enumerated values. Requirements can be compared using less than (<) and greater than (>). For example, `UNIQUE_IV < RANDOM_IV` and `UNPREDICTABLE_RANDOM_IV > RANDOM_IV`.

Objects that use SimpleKeyingInterface do not support an optional IV. That is, an IV must be present or it must be absent. If you wish to support an optional IV then provide two classes - one with an IV and one without an IV.

See also
  IsResynchronizable(), CanUseRandomIVs(), CanUsePredictableIVs(), CanUseStructuredIVs()

Enumerator
UNIQUE_IV | The IV must be unique.
RANDOM_IV | The IV must be random and possibly predictable.
UNPREDICTABLE_RANDOM_IV | The IV must be random and unpredictable.
INTERNALLY_GENERATED_IV | The IV is set by the object.
NOT_RESYNCHRONIZABLE | The object does not use an IV.

Definition at line 719 of file cryptlib.h.

## Member Function Documentation

## ◆ MinKeyLength()

virtual size_t SimpleKeyingInterface::MinKeyLength | ( |  | ) | const
| pure virtual

Returns smallest valid key length.

Returns
  the minimum key length, in bytes

Implemented in XChaCha20Poly1305_Base, XTS_ModeBase, SipHash_Base< C, D, T_128bit >, CipherModeBase, ChaCha20Poly1305_Base, GCM_Base, CCM_Base, and EAX_Base.

## ◆ MaxKeyLength()

virtual size_t SimpleKeyingInterface::MaxKeyLength | ( |  | ) | const
| pure virtual

Returns largest valid key length.

Returns
  the maximum key length, in bytes

Implemented in XChaCha20Poly1305_Base, XTS_ModeBase, CipherModeBase, SipHash_Base< C, D, T_128bit >, ChaCha20Poly1305_Base, GCM_Base, CCM_Base, and EAX_Base.

## ◆ DefaultKeyLength()

virtual size_t SimpleKeyingInterface::DefaultKeyLength | ( |  | ) | const
| pure virtual

Returns default key length.

Returns
  the default key length, in bytes

Implemented in XChaCha20Poly1305_Base, XTS_ModeBase, CipherModeBase, SipHash_Base< C, D, T_128bit >, ChaCha20Poly1305_Base, GCM_Base, CCM_Base, and EAX_Base.

## ◆ GetValidKeyLength()

virtual size_t SimpleKeyingInterface::GetValidKeyLength | ( | size_t | keylength | ) | const
| pure virtual

Returns a valid key length for the algorithm.

Parameters

  keylength | the size of the key, in bytes

Returns
  the valid key length, in bytes

keylength is provided in bytes, not bits. If keylength is less than MIN_KEYLENGTH, then the function returns MIN_KEYLENGTH. If keylength is greater than MAX_KEYLENGTH, then the function returns MAX_KEYLENGTH. if If keylength is a multiple of KEYLENGTH_MULTIPLE, then keylength is returned. Otherwise, the function returns a lower multiple of KEYLENGTH_MULTIPLE.

Implemented in XChaCha20Poly1305_Base, XTS_ModeBase, ChaCha20Poly1305_Base, GCM_Base, EAX_Base, SimpleKeyingInterfaceImpl< TTMAC_Base, TTMAC_Base >, SimpleKeyingInterfaceImpl< HMAC_Base, HMAC< T > >, SimpleKeyingInterfaceImpl< MessageAuthenticationCode, BLAKE2s_Info >, SimpleKeyingInterfaceImpl< MessageAuthenticationCode, BLAKE2b_Info >, SimpleKeyingInterfaceImpl< Poly1305_Base< T >, Poly1305_Base< T > >, SimpleKeyingInterfaceImpl< HMAC_Base, HMAC< H > >, SimpleKeyingInterfaceImpl< HMAC_Base, HMAC< SHA256 > >, SimpleKeyingInterfaceImpl< Poly1305TLS_Base, Poly1305TLS_Base >, SimpleKeyingInterfaceImpl< CMAC_Base, CMAC< T > >, SimpleKeyingInterfaceImpl< DMAC_Base< T >, DMAC_Base< T > >, SimpleKeyingInterfaceImpl< CBC_MAC_Base, CBC_MAC< T > >, SimpleKeyingInterfaceImpl< BlockCipher, BTEA_Info >, SimpleKeyingInterfaceImpl< VMAC_Base, SameKeyLengthAs< T_BlockCipher, SimpleKeyingInterface::UNIQUE_IV, T_BlockCipher::BLOCKSIZE > >, SimpleKeyingInterfaceImpl< CMAC_Base, CMAC< T_BlockCipher > >, CipherModeBase, SipHash_Base< C, D, T_128bit >, SipHash_Base< 2, 4, false >, and CCM_Base.

## ◆ IsValidKeyLength()

virtual bool SimpleKeyingInterface::IsValidKeyLength | ( | size_t | keylength | ) | const
| inline virtual

Returns whether keylength is a valid key length.

Parameters

  keylength | the requested keylength

Returns
  true if keylength is valid, false otherwise

Internally the function calls GetValidKeyLength()

Reimplemented in XChaCha20Poly1305_Base, ChaCha20Poly1305_Base, GCM_Base, EAX_Base, CipherModeBase, XTS_ModeBase, and CCM_Base.

Definition at line 672 of file cryptlib.h.

## ◆ SetKey()

virtual void SimpleKeyingInterface::SetKey | ( | const byte * | key,
|  | size_t | length,
|  | const NameValuePairs & | params = `g_nullNameValuePairs`
| ) |  |
| virtual

Sets or reset the key of this object.

Parameters

  key | the key to use when keying the object
  length | the size of the key, in bytes
  params | additional initialization parameters to configure this object

Reimplemented in AuthenticatedSymmetricCipherBase, ECB_OneWay, and XTS_ModeBase.

## ◆ SetKeyWithRounds()

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

Sets or reset the key of this object.

Parameters

  key | the key to use when keying the object
  length | the size of the key, in bytes
  rounds | the number of rounds to apply the transformation function, if applicable

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

## ◆ SetKeyWithIV() [1/2]

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

Sets or reset the key of this object.

Parameters

  key | the key to use when keying the object
  length | the size of the key, in bytes
  iv | the initialization vector to use when keying the object
  ivLength | the size of the iv, in bytes

SetKeyWithIV() calls SetKey() with a NameValuePairs that only specifies IV. The IV is a byte buffer with size ivLength. ivLength is an integer parameter, and `-1` means use IVSize().

## ◆ SetKeyWithIV() [2/2]

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

Sets or reset the key of this object.

Parameters

  key | the key to use when keying the object
  length | the size of the key, in bytes
  iv | the initialization vector to use when keying the object

SetKeyWithIV() calls SetKey() with a NameValuePairs() object that only specifies iv. iv is a byte buffer, and it must have a size IVSize().

Definition at line 708 of file cryptlib.h.

## ◆ IVRequirement()

virtual IV_Requirement SimpleKeyingInterface::IVRequirement | ( |  | ) | const
| pure virtual

Minimal requirement for secure IVs.

Returns
  the secure IV requirement of the algorithm

Implemented in CipherModeBase, CBC_ModeBase, ECB_OneWay, CTR_ModePolicy, OFB_ModePolicy, XChaCha20Poly1305_Base, CFB_ModePolicy, XTS_ModeBase, SipHash_Base< C, D, T_128bit >, ChaCha20Poly1305_Base, GCM_Base, CCM_Base, and EAX_Base.

## ◆ IsResynchronizable()

bool SimpleKeyingInterface::IsResynchronizable | ( |  | ) | const
| inline

Determines if the object can be resynchronized.

Returns
  true if the object can be resynchronized (i.e. supports initialization vectors), false otherwise

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

## ◆ CanUseRandomIVs()

bool SimpleKeyingInterface::CanUseRandomIVs | ( |  | ) | const
| inline

Determines if the object can use random IVs.

Returns
  true if the object can use random IVs (in addition to ones returned by GetNextIV), false otherwise

Definition at line 744 of file cryptlib.h.

## ◆ CanUsePredictableIVs()

bool SimpleKeyingInterface::CanUsePredictableIVs | ( |  | ) | const
| inline

Determines if the object can use random but possibly predictable IVs.

Returns
  true if the object can use random but possibly predictable IVs (in addition to ones returned by GetNextIV), false otherwise

Definition at line 749 of file cryptlib.h.

## ◆ CanUseStructuredIVs()

bool SimpleKeyingInterface::CanUseStructuredIVs | ( |  | ) | const
| inline

Determines if the object can use structured IVs.

Returns
  true if the object can use structured IVs, false otherwise

CanUseStructuredIVs() indicates whether the object can use structured IVs; for example a counter (in addition to ones returned by GetNextIV).

Definition at line 755 of file cryptlib.h.

## ◆ IVSize()

virtual unsigned int SimpleKeyingInterface::IVSize | ( |  | ) | const
| inline virtual

Returns length of the IV accepted by this object.

Returns
  the size of an IV, in bytes

Exceptions

  NotImplemented() | if the object does not support resynchronization

The default implementation throws NotImplemented

Reimplemented in XChaCha20Poly1305_Base, CipherModeBase, SipHash_Base< C, D, T_128bit >, ChaCha20Poly1305_Base, GCM_Base, CCM_Base, EAX_Base, and VMAC_Base.

Definition at line 761 of file cryptlib.h.

## ◆ DefaultIVLength()

unsigned int SimpleKeyingInterface::DefaultIVLength | ( |  | ) | const
| inline

Provides the default size of an IV.

Returns
  default length of IVs accepted by this object, in bytes

Definition at line 766 of file cryptlib.h.

## ◆ MinIVLength()

virtual unsigned int SimpleKeyingInterface::MinIVLength | ( |  | ) | const
| inline virtual

Provides the minimum size of an IV.

Returns
  minimal length of IVs accepted by this object, in bytes

Exceptions

  NotImplemented() | if the object does not support resynchronization

Reimplemented in XChaCha20Poly1305_Base, ChaCha20Poly1305_Base, GCM_Base, CCM_Base, EAX_Base, and VMAC_Base.

Definition at line 771 of file cryptlib.h.

## ◆ MaxIVLength()

virtual unsigned int SimpleKeyingInterface::MaxIVLength | ( |  | ) | const
| inline virtual

Provides the maximum size of an IV.

Returns
  maximal length of IVs accepted by this object, in bytes

Exceptions

  NotImplemented() | if the object does not support resynchronization

Reimplemented in XChaCha20Poly1305_Base, ChaCha20Poly1305_Base, GCM_Base, CCM_Base, and EAX_Base.

Definition at line 776 of file cryptlib.h.

## ◆ Resynchronize()

virtual void SimpleKeyingInterface::Resynchronize | ( | const byte * | iv,
|  | int | ivLength = `-1`
| ) |  |
| inline virtual

Resynchronize with an IV.

Parameters

  iv | the initialization vector
  ivLength | the size of the initialization vector, in bytes

Resynchronize() resynchronizes with an IV provided by the caller. `ivLength=-1` means use IVSize().

Exceptions

  NotImplemented() | if the object does not support resynchronization

Reimplemented in VMAC_Base, CFB_CipherTemplate< AbstractPolicyHolder< CFB_CipherAbstractPolicy, SymmetricCipher > >, AdditiveCipherTemplate< BASE >, AdditiveCipherTemplate< AbstractPolicyHolder< AdditiveCipherAbstractPolicy, CTR_ModePolicy > >, BlockOrientedCipherModeBase, AuthenticatedSymmetricCipherBase, XTS_ModeBase, and Poly1305_Base< T >.

Definition at line 783 of file cryptlib.h.

## ◆ GetNextIV()

virtual void SimpleKeyingInterface::GetNextIV | ( | RandomNumberGenerator & | rng,
|  | byte * | iv
| ) |  |
| virtual

Retrieves a secure IV for the next message.

Parameters

  rng | a RandomNumberGenerator to produce keying material
  iv | a block of bytes to receive the IV

The IV must be at least IVSize() in length.

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.

Internally, the base class implementation calls RandomNumberGenerator's GenerateBlock()

Note
  This method is not implemented on decryption objects.

Reimplemented in Poly1305_Base< T >, and VMAC_Base.

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

- cryptlib.h