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

Public Member Functions | List of all members
HashTransformation Class Referenceabstract

Interface for hash functions and data processing part of MACs. More...

Inheritance diagram for HashTransformation:

## Public Member Functions
HashTransformation & | Ref ()
| Provides a reference to this object. More...
virtual void | Update (const byte *input, size_t length)=0
| Updates a hash with additional input. More...
virtual byte * | CreateUpdateSpace (size_t &size)
| Request space which can be written into by the caller. More...
virtual void | Final (byte *digest)
| Computes the hash of the current message. More...
virtual void | Restart ()
| Restart the hash. More...
virtual unsigned int | DigestSize () const =0
| Provides the digest size of the hash. More...
unsigned int | TagSize () const
| Provides the tag size of the hash. More...
virtual unsigned int | BlockSize () const
| Provides the block size of the compression function. More...
virtual unsigned int | OptimalBlockSize () const
| Provides the input block size most efficient for this hash. More...
virtual unsigned int | OptimalDataAlignment () const
| Provides input and output data alignment for optimal performance. More...
virtual void | CalculateDigest (byte *digest, const byte *input, size_t length)
| Updates the hash with additional input and computes the hash of the current message. More...
virtual bool | Verify (const byte *digest)
| Verifies the hash of the current message. More...
virtual bool | VerifyDigest (const byte *digest, const byte *input, size_t length)
| Updates the hash with additional input and verifies the hash of the current message. More...
virtual void | TruncatedFinal (byte *digest, size_t digestSize)=0
| Computes the hash of the current message. More...
virtual void | CalculateTruncatedDigest (byte *digest, size_t digestSize, const byte *input, size_t length)
| Updates the hash with additional input and computes the hash of the current message. More...
virtual bool | TruncatedVerify (const byte *digest, size_t digestLength)
| Verifies the hash of the current message. More...
virtual bool | VerifyTruncatedDigest (const byte *digest, size_t digestLength, const byte *input, size_t length)
| Updates the hash with additional input and verifies the hash of the current message. 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...
virtual std::string | AlgorithmProvider () const
| Retrieve the provider of this algorithm. More...
Public Member Functions inherited from Clonable
virtual Clonable * | Clone () const
| Copies this object. More...

## Detailed Description

Interface for hash functions and data processing part of MACs.

HashTransformation objects are stateful. They are created in an initial state, change state as Update() is called, and return to the initial state when Final() is called. This interface allows a large message to be hashed in pieces by calling Update() on each piece followed by calling Final().

See also
  HashFilter(), HashVerificationFilter()

Definition at line 1112 of file cryptlib.h.

## Member Function Documentation

## ◆ Ref()

HashTransformation& HashTransformation::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 1120 of file cryptlib.h.

## ◆ Update()

virtual void HashTransformation::Update | ( | const byte * | input,
|  | size_t | length
| ) |  |
| pure virtual

Updates a hash with additional input.

Parameters

  input | the additional input as a buffer
  length | the size of the buffer, in bytes

Implemented in ed25519_MessageAccumulator, LSH512_Base, LSH256_Base, PK_MessageAccumulatorBase, BLAKE2b, BLAKE2s, Poly1305TLS_Base, SipHash_Base< C, D, T_128bit >, SipHash_Base< 2, 4, false >, IteratedHashBase< word32, HashTransformation >, IteratedHashBase< T_HashWordType, HashTransformation >, IteratedHashBase< word32, MessageAuthenticationCode >, IteratedHashBase< word64, HashTransformation >, IteratedHashBase< word64, MessageAuthenticationCode >, Poly1305_Base< T >, CRC32C, Keccak, AuthenticatedSymmetricCipherBase, SHAKE, TruncatedHashTemplate< T >, SHA3, CMAC_Base, CRC32, DMAC_Base< T >, HMAC_Base, Weak::MD2, CBC_MAC_Base, Adler32, and NullHash.

## ◆ CreateUpdateSpace()

virtual byte* HashTransformation::CreateUpdateSpace | ( | size_t & | size | ) |
| inline virtual

Request space which can be written into by the caller.

Parameters

  size | the requested size of the buffer

The purpose of this method is to help avoid extra memory allocations.

size is an IN and OUT parameter and used as a hint. When the call is made, size is the requested size of the buffer. When the call returns, size is the size of the array returned to the caller.

The base class implementation sets size to 0 and returns NULL or nullptr.

Note
  Some objects, like ArraySink, cannot create a space because its fixed.

Reimplemented in IteratedHashBase< word32, HashTransformation >, IteratedHashBase< T_HashWordType, HashTransformation >, IteratedHashBase< word32, MessageAuthenticationCode >, IteratedHashBase< word64, HashTransformation >, and IteratedHashBase< word64, MessageAuthenticationCode >.

Definition at line 1135 of file cryptlib.h.

## ◆ Final()

virtual void HashTransformation::Final | ( | byte * | digest | ) |
| inline virtual

Computes the hash of the current message.

Parameters

  digest | a pointer to the buffer to receive the hash

Final() restarts the hash for a new message.

Precondition
  `COUNTOF(digest) <= DigestSize()` or `COUNTOF(digest) <= HASH::DIGESTSIZE` ensures the output byte buffer is large enough for the digest.

Definition at line 1142 of file cryptlib.h.

## ◆ Restart()

virtual void HashTransformation::Restart | ( |  | ) |
| inline virtual

Restart the hash.

Discards the current state, and restart for a new message

Reimplemented in BLAKE2b, ed25519_MessageAccumulator, BLAKE2s, Poly1305TLS_Base, LSH512_Base, IteratedHashBase< word32, HashTransformation >, IteratedHashBase< T_HashWordType, HashTransformation >, IteratedHashBase< word32, MessageAuthenticationCode >, IteratedHashBase< word64, HashTransformation >, IteratedHashBase< word64, MessageAuthenticationCode >, Poly1305_Base< T >, Keccak, AuthenticatedSymmetricCipherBase, LSH256_Base, SHAKE, SHA3, TruncatedHashTemplate< T >, and HMAC_Base.

Definition at line 1147 of file cryptlib.h.

## ◆ DigestSize()

virtual unsigned int HashTransformation::DigestSize | ( |  | ) | const
| pure virtual

Provides the digest size of the hash.

Returns
  the digest size of the hash.

Implemented in PK_MessageAccumulator, BLAKE2b, BLAKE2s, XChaCha20Poly1305_Base, IteratedHashWithStaticTransform< T_HashWordType, T_Endianness, T_BlockSize, T_StateSize, T_Transform, T_DigestSize, T_StateAligned >, Poly1305TLS_Base, LSH512_Base, Poly1305_Base< T >, ChaCha20Poly1305_Base, SipHash_Base< C, D, T_128bit >, CRC32C, GCM_Base, Keccak, Weak::PanamaHash< B >, CCM_Base, TruncatedHashTemplate< T >, EAX_Base, LSH256_Base, SHAKE, SHA3, CMAC_Base, VMAC_Base, CRC32, HMAC_Base, DMAC_Base< T >, Weak::MD2, CBC_MAC_Base, TTMAC_Base, Adler32, and NullHash.

## ◆ TagSize()

unsigned int HashTransformation::TagSize | ( |  | ) | const
| inline

Provides the tag size of the hash.

Returns
  the tag size of the hash.

Same as DigestSize().

Definition at line 1157 of file cryptlib.h.

## ◆ BlockSize()

virtual unsigned int HashTransformation::BlockSize | ( |  | ) | const
| inline virtual

Provides the block size of the compression function.

Returns
  block size of the compression function, in bytes

BlockSize() will return 0 if the hash is not block based or does not have an equivalent block size. For example, Keccak and SHA-3 do not have a block size, but they do have an equivalent block size called rate expressed as `r`.

Reimplemented in BLAKE2b, BLAKE2s, Poly1305TLS_Base, LSH512_Base, IteratedHash< T_HashWordType, T_Endianness, T_BlockSize, T_Base >, Keccak_Final< T_DigestSize >, SHAKE_Final< T_Strength >, SHA3_Final< T_DigestSize >, Poly1305_Base< T >, LSH256_Base, VMAC_Base, and Weak::MD2.

Definition at line 1165 of file cryptlib.h.

## ◆ OptimalBlockSize()

virtual unsigned int HashTransformation::OptimalBlockSize | ( |  | ) | const
| inline virtual

Provides the input block size most efficient for this hash.

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

The base class implementation returns MandatoryBlockSize().

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

Reimplemented in SipHash_Base< C, D, T_128bit >, CMAC_Base, and HMAC_Base.

Definition at line 1172 of file cryptlib.h.

## ◆ OptimalDataAlignment()

virtual unsigned int HashTransformation::OptimalDataAlignment | ( |  | ) | const
| virtual

Provides input and output data alignment for optimal performance.

Returns
  the input data alignment that provides optimal performance

See also
  GetAlignment() and OptimalBlockSize()

Reimplemented in BLAKE2b, BLAKE2s, XChaCha20Poly1305_Base, LSH512_Base, SipHash_Base< C, D, T_128bit >, Keccak, ChaCha20Poly1305_Base, GCM_Base, LSH256_Base, SHAKE, SHA3, CCM_Base, VMAC_Base, CMAC_Base, and EAX_Base.

## ◆ CalculateDigest()

virtual void HashTransformation::CalculateDigest | ( | byte * | digest,
|  | const byte * | input,
|  | size_t | length
| ) |  |
| inline virtual

Updates the hash with additional input and computes the hash of the current message.

Parameters

  digest | a pointer to the buffer to receive the hash
  input | the additional input as a buffer
  length | the size of the buffer, in bytes

Use this if your input is in one piece and you don't want to call Update() and Final() separately

CalculateDigest() restarts the hash for the next message.

Precondition
  `COUNTOF(digest) == DigestSize()` or `COUNTOF(digest) == HASH::DIGESTSIZE` ensures the output byte buffer is a valid size.

Definition at line 1188 of file cryptlib.h.

## ◆ Verify()

virtual bool HashTransformation::Verify | ( | const byte * | digest | ) |
| inline virtual

Verifies the hash of the current message.

Parameters

  digest | a pointer to the buffer of an existing hash

Returns
  `true` if the existing hash matches the computed hash, `false` otherwise

Exceptions

  InvalidArgument() | if the existing hash's size exceeds DigestSize()

Verify() performs a bitwise compare on the buffers using VerifyBufsEqual(), which is a constant time comparison function. digestLength cannot exceed DigestSize().

Verify() restarts the hash for the next message.

Precondition
  `COUNTOF(digest) == DigestSize()` or `COUNTOF(digest) == HASH::DIGESTSIZE` ensures the input byte buffer is a valid size.

Definition at line 1200 of file cryptlib.h.

## ◆ VerifyDigest()

virtual bool HashTransformation::VerifyDigest | ( | const byte * | digest,
|  | const byte * | input,
|  | size_t | length
| ) |  |
| inline virtual

Updates the hash with additional input and verifies the hash of the current message.

Parameters

  digest | a pointer to the buffer of an existing hash
  input | the additional input as a buffer
  length | the size of the buffer, in bytes

Returns
  `true` if the existing hash matches the computed hash, `false` otherwise

Exceptions

  InvalidArgument() | if the existing hash's size exceeds DigestSize()

Use this if your input is in one piece and you don't want to call Update() and Verify() separately

VerifyDigest() performs a bitwise compare on the buffers using VerifyBufsEqual(), which is a constant time comparison function.

VerifyDigest() restarts the hash for the next message.

Precondition
  `COUNTOF(digest) == DigestSize()` or `COUNTOF(digest) == HASH::DIGESTSIZE` ensures the output byte buffer is a valid size.

Definition at line 1216 of file cryptlib.h.

## ◆ TruncatedFinal()

virtual void HashTransformation::TruncatedFinal | ( | byte * | digest,
|  | size_t | digestSize
| ) |  |
| pure virtual

Computes the hash of the current message.

Parameters

  digest | a pointer to the buffer to receive the hash
  digestSize | the size of the truncated digest, in bytes

TruncatedFinal() calls Final() and then copies digestSize bytes to digest. The hash is restarted the hash for the next message.

Precondition
  `COUNTOF(digest) <= DigestSize()` or `COUNTOF(digest) <= HASH::DIGESTSIZE` ensures the output byte buffer is a valid size.

Implemented in Poly1305TLS_Base, Poly1305_Base< T >, VMAC_Base, CMAC_Base, DMAC_Base< T >, HMAC_Base, CBC_MAC_Base, TTMAC_Base, AuthenticatedSymmetricCipherBase, BLAKE2b, BLAKE2s, LSH512_Base, Keccak, CRC32C, Weak::PanamaHash< B >, Weak::PanamaHash< LittleEndian >, LSH256_Base, SHAKE, SHA3, Whirlpool, CRC32, Weak::MD2, Adler32, PK_MessageAccumulator, IteratedHashBase< word32, HashTransformation >, IteratedHashBase< T_HashWordType, HashTransformation >, IteratedHashBase< word32, MessageAuthenticationCode >, IteratedHashBase< word64, HashTransformation >, IteratedHashBase< word64, MessageAuthenticationCode >, SipHash_Base< C, D, T_128bit >, SipHash_Base< 2, 4, false >, Tiger, TruncatedHashTemplate< T >, and NullHash.

## ◆ CalculateTruncatedDigest()

virtual void HashTransformation::CalculateTruncatedDigest | ( | byte * | digest,
|  | size_t | digestSize,
|  | const byte * | input,
|  | size_t | length
| ) |  |
| inline virtual

Updates the hash with additional input and computes the hash of the current message.

Parameters

  digest | a pointer to the buffer to receive the hash
  digestSize | the length of the truncated hash, in bytes
  input | the additional input as a buffer
  length | the size of the buffer, in bytes

Use this if your input is in one piece and you don't want to call Update() and CalculateDigest() separately.

CalculateTruncatedDigest() restarts the hash for the next message.

Precondition
  `digestSize <= DigestSize()` or `digestSize <= HASH::DIGESTSIZE` ensures the output byte buffer is a valid size.

Definition at line 1238 of file cryptlib.h.

## ◆ TruncatedVerify()

virtual bool HashTransformation::TruncatedVerify | ( | const byte * | digest,
|  | size_t | digestLength
| ) |  |
| virtual

Verifies the hash of the current message.

Parameters

  digest | a pointer to the buffer of an existing hash
  digestLength | the size of the truncated hash, in bytes

Returns
  `true` if the existing hash matches the computed hash, `false` otherwise

Exceptions

  InvalidArgument() | if digestLength exceeds DigestSize()

TruncatedVerify() is a truncated version of Verify(). It can operate on a buffer smaller than DigestSize(). However, digestLength cannot exceed DigestSize().

Verify() performs a bitwise compare on the buffers using VerifyBufsEqual(), which is a constant time comparison function. digestLength cannot exceed DigestSize().

TruncatedVerify() restarts the hash for the next message.

Precondition
  `digestLength <= DigestSize()` or `digestLength <= HASH::DIGESTSIZE` ensures the input byte buffer is a valid size.

Reimplemented in TruncatedHashTemplate< T >, and NullHash.

## ◆ VerifyTruncatedDigest()

virtual bool HashTransformation::VerifyTruncatedDigest | ( | const byte * | digest,
|  | size_t | digestLength,
|  | const byte * | input,
|  | size_t | length
| ) |  |
| inline virtual

Updates the hash with additional input and verifies the hash of the current message.

Parameters

  digest | a pointer to the buffer of an existing hash
  digestLength | the size of the truncated hash, in bytes
  input | the additional input as a buffer
  length | the size of the buffer, in bytes

Returns
  `true` if the existing hash matches the computed hash, `false` otherwise

Exceptions

  InvalidArgument() | if digestLength exceeds DigestSize()

Use this if your input is in one piece and you don't want to call Update() and TruncatedVerify() separately.

VerifyTruncatedDigest() is a truncated version of VerifyDigest(). It can operate on a buffer smaller than DigestSize(). However, digestLength cannot exceed DigestSize().

VerifyTruncatedDigest() restarts the hash for the next message.

Precondition
  `digestLength <= DigestSize()` or `digestLength <= HASH::DIGESTSIZE` ensures the input byte buffer is a valid size.

Definition at line 1269 of file cryptlib.h.

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

- cryptlib.h