TSDuck v3.40-4034
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::Hash Class Reference

Base class for all hash functions. More...

#include <tsHash.h>

Inheritance diagram for ts::Hash:

Public Member Functions

virtual ~Hash ()
 Virtual destructor.
 
virtual bool add (const void *data, size_t size)
 Add some part of the message to hash.
 
virtual bool getHash (void *hash, size_t bufsize, size_t *retsize=nullptr)
 Get the resulting hash value.
 
bool hash (const void *data, size_t data_size, ByteBlock &hash)
 Compute a hash in one operation.
 
bool hash (const void *data, size_t data_size, void *hash, size_t hash_maxsize, size_t *hash_retsize=nullptr)
 Compute a hash in one operation.
 
size_t hashSize () const
 Size in bytes of the resulting hash.
 
virtual bool init ()
 Reinitialize the computation of the hash.
 
UString name () const
 Algorithm name (informational only).
 

Protected Member Functions

 Hash (const UChar *name, size_t hash_size)
 Constructor for subclasses.
 
virtual void getAlgorithm (::BCRYPT_ALG_HANDLE &algo, size_t &length) const
 Get the algorithm handle and subobject size, when the subclass uses Microsoft BCrypt library.
 
virtual const EVP_MD_CTX * referenceContext () const
 Get reference hash context, when the subclass uses OpenSSL.
 

Detailed Description

Base class for all hash functions.

Constructor & Destructor Documentation

◆ Hash()

ts::Hash::Hash ( const UChar name,
size_t  hash_size 
)
protected

Constructor for subclasses.

Parameters
[in]nameAlgorithm name.
[in]hash_sizeSize in bytes of the hash value.

Member Function Documentation

◆ name()

UString ts::Hash::name ( ) const
inline

Algorithm name (informational only).

Returns
The algorithm name.

◆ hashSize()

size_t ts::Hash::hashSize ( ) const
inline

Size in bytes of the resulting hash.

Returns
The size in bytes of the resulting hash.

◆ init()

virtual bool ts::Hash::init ( )
virtual

Reinitialize the computation of the hash.

Returns
True on success, false on error.

◆ add()

virtual bool ts::Hash::add ( const void *  data,
size_t  size 
)
virtual

Add some part of the message to hash.

Can be called several times.

Parameters
[in]dataAddress of message part.
[in]sizeSize in bytes of message part.
Returns
True on success, false on error.

◆ getHash()

virtual bool ts::Hash::getHash ( void *  hash,
size_t  bufsize,
size_t *  retsize = nullptr 
)
virtual

Get the resulting hash value.

Parameters
[out]hashAddress of returned hash buffer.
[in]bufsizeSize in bytes of hash buffer.
[out]retsizeAddress of an integer receiving the actual returned hash size. Can be a null pointer (ignored).
Returns
True on success, false on error.

◆ hash() [1/2]

bool ts::Hash::hash ( const void *  data,
size_t  data_size,
void *  hash,
size_t  hash_maxsize,
size_t *  hash_retsize = nullptr 
)

Compute a hash in one operation.

Same in init() + add() + getHash().

Parameters
[in]dataAddress of message to hash.
[in]data_sizeSize in bytes of message to hash.
[out]hashAddress of returned hash buffer.
[in]hash_maxsizeSize in bytes of hash buffer.
[out]hash_retsizeAddress of an integer receiving the actual returned hash size. Can be a null pointer (ignored).
Returns
True on success, false on error.

◆ hash() [2/2]

bool ts::Hash::hash ( const void *  data,
size_t  data_size,
ByteBlock hash 
)

Compute a hash in one operation.

Same in init() + add() + getHash().

Parameters
[in]dataAddress of message to hash.
[in]data_sizeSize in bytes of message to hash.
[out]hashReturned hash buffer.
Returns
True on success, false on error.

◆ getAlgorithm()

virtual void ts::Hash::getAlgorithm ( ::BCRYPT_ALG_HANDLE &  algo,
size_t &  length 
) const
protectedvirtual

Get the algorithm handle and subobject size, when the subclass uses Microsoft BCrypt library.

Parameters
[out]algoHandle to hash algorithm.
[out]lengthLength in bytes of the subobject to allocate.

Reimplemented in ts::SHA1, ts::SHA256, and ts::SHA512.

◆ referenceContext()

virtual const EVP_MD_CTX * ts::Hash::referenceContext ( ) const
protectedvirtual

Get reference hash context, when the subclass uses OpenSSL.

Returns
Reference EVP hash context. To be copied into each new hash object.

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