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

SHA-256 hash. More...

#include <tsSHA256.h>

Inheritance diagram for ts::SHA256:
Collaboration diagram for ts::SHA256:

Public Member Functions

 SHA256 ()
 Constructor.
 
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).
 

Static Public Attributes

static constexpr size_t HASH_SIZE = 256/8
 SHA-256 hash size in bytes (256 bits).
 

Protected Member Functions

virtual void getAlgorithm (::BCRYPT_ALG_HANDLE &algo, size_t &length) const override
 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

SHA-256 hash.

Member Function Documentation

◆ getAlgorithm()

virtual void ts::SHA256::getAlgorithm ( ::BCRYPT_ALG_HANDLE &  algo,
size_t &  length 
) const
overrideprotectedvirtual

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 from ts::Hash.

◆ name()

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

Algorithm name (informational only).

Returns
The algorithm name.

◆ hashSize()

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

Size in bytes of the resulting hash.

Returns
The size in bytes of the resulting hash.

◆ init()

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

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 
)
virtualinherited

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 
)
virtualinherited

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 
)
inherited

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 
)
inherited

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.

◆ referenceContext()

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

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: