Virgil Security Crypto library  2.6.3
Public Types | List of all members
virgil::crypto::foundation::VirgilHash Class Reference

Provides hashing (message digest) algorithms. More...

#include <VirgilHash.h>

Inheritance diagram for virgil::crypto::foundation::VirgilHash:
virgil::crypto::foundation::asn1::VirgilAsn1Compatible

Public Types

enum  Algorithm {
  Algorithm::MD5, Algorithm::SHA1, Algorithm::SHA224, Algorithm::SHA256,
  Algorithm::SHA384, Algorithm::SHA512
}
 Enumerates possible Hash algorithms. More...
 

Public Member Functions

Constructor / Destructor
 VirgilHash ()
 Create object with undefined algorithm. More...
 
 VirgilHash (Algorithm alg)
 Create object with specific algorithm type.
 
 VirgilHash (const std::string &name)
 Create object with given algorithm name. More...
 
 VirgilHash (const char *name)
 Create object with given algorithm name. More...
 
Info

Provide detail information about object.

std::string name () const
 Returns name of the hash function. More...
 
Algorithm algorithm () const
 Returns algorithm of the hash function. More...
 
int type () const
 Return underlying hash type. More...
 
size_t size () const
 Return size of the message digest output. More...
 
Immediate Hashing

This methods can be used to get the message hash immediately.

virgil::crypto::VirgilByteArray hash (const virgil::crypto::VirgilByteArray &data) const
 Produce hash. More...
 
Chain Hashing

This methods provide mechanism to hash long message, that can be splitted to a shorter chunks and be processed separately.

void start ()
 Initialize hashing for the new message hash.
 
void update (const virgil::crypto::VirgilByteArray &data)
 Update / process message hash. More...
 
virgil::crypto::VirgilByteArray finish ()
 Return final message hash. More...
 
HMAC Immediate Hashing

This methods can be used to get the message HMAC hash immediately.

virgil::crypto::VirgilByteArray hmac (const virgil::crypto::VirgilByteArray &key, const virgil::crypto::VirgilByteArray &data) const
 Produce HMAC hash. More...
 
HMAC Chain Hashing

This methods provide mechanism to get HMAC hash of the long message, that can be splitted to a shorter chunks and be processed separately.

void hmacStart (const virgil::crypto::VirgilByteArray &key)
 Initialize HMAC hashing for the new message hash. More...
 
void hmacReset ()
 Reset HMAC hashing for the new message hash.
 
void hmacUpdate (const virgil::crypto::VirgilByteArray &data)
 Update / process message HMAC hash. More...
 
virgil::crypto::VirgilByteArray hmacFinish ()
 Return final message HMAC hash. More...
 
VirgilAsn1Compatible implementation
size_t asn1Write (virgil::crypto::foundation::asn1::VirgilAsn1Writer &asn1Writer, size_t childWrittenBytes=0) const override
 Write object state to the writer. More...
 
void asn1Read (virgil::crypto::foundation::asn1::VirgilAsn1Reader &asn1Reader) override
 Read object state from the reader. More...
 
- Public Member Functions inherited from virgil::crypto::foundation::asn1::VirgilAsn1Compatible
virgil::crypto::VirgilByteArray toAsn1 () const
 Save object state to the ASN.1 structure.
 
void fromAsn1 (const virgil::crypto::VirgilByteArray &asn1)
 Restore object state from the ASN.1 structure.
 
virtual ~VirgilAsn1Compatible () noexcept
 Polymorphic destructor.
 

Additional Inherited Members

- Protected Member Functions inherited from virgil::crypto::foundation::asn1::VirgilAsn1Compatible
virtual void checkRequiredField (const VirgilByteArray &param) const
 If given parameter is empty exception will be thrown. More...
 

Detailed Description

Provides hashing (message digest) algorithms.

Member Enumeration Documentation

Enumerates possible Hash algorithms.

Enumerator
MD5 

Hash Algorithm: MD5.

SHA1 

Hash Algorithm: SHA1.

SHA224 

Hash Algorithm: SHA224.

SHA256 

Hash Algorithm: SHA256.

SHA384 

Hash Algorithm: SHA384.

SHA512 

Hash Algorithm: SHA512.

Constructor & Destructor Documentation

virgil::crypto::foundation::VirgilHash::VirgilHash ( )

Create object with undefined algorithm.

Warning
SHOULD be used in conjunction with VirgilAsn1Compatible interface, i.e. VirgilHash hash; hash.fromAsn1(asn1);
virgil::crypto::foundation::VirgilHash::VirgilHash ( const std::string &  name)
explicit

Create object with given algorithm name.

Note
Names SHOULD be the identical to the VirgilHash::Algorithm enumeration.
virgil::crypto::foundation::VirgilHash::VirgilHash ( const char *  name)
explicit

Create object with given algorithm name.

Note
Names SHOULD be the identical to the VirgilHash::Algorithm enumeration.

Member Function Documentation

Algorithm virgil::crypto::foundation::VirgilHash::algorithm ( ) const

Returns algorithm of the hash function.

Returns
Algorithm of the hash function.
void virgil::crypto::foundation::VirgilHash::asn1Read ( virgil::crypto::foundation::asn1::VirgilAsn1Reader asn1Reader)
overridevirtual

Read object state from the reader.

Parameters
asn1Readerreader payloaded with ASN.1 to be read.

Implements virgil::crypto::foundation::asn1::VirgilAsn1Compatible.

size_t virgil::crypto::foundation::VirgilHash::asn1Write ( virgil::crypto::foundation::asn1::VirgilAsn1Writer asn1Writer,
size_t  childWrittenBytes = 0 
) const
overridevirtual

Write object state to the writer.

Parameters
asn1Writerwriter that should be payloaded by subclasses.
childWrittenBytescount of bytes that was written by subclasses.
Returns
Writen bytes count.

Implements virgil::crypto::foundation::asn1::VirgilAsn1Compatible.

virgil::crypto::VirgilByteArray virgil::crypto::foundation::VirgilHash::finish ( )

Return final message hash.

Returns
Message hash processed by series of update() method.
See also
start()
update()
virgil::crypto::VirgilByteArray virgil::crypto::foundation::VirgilHash::hash ( const virgil::crypto::VirgilByteArray data) const

Produce hash.

Process the given message immediately and return it's hash.

Parameters
data- message to be hashed.
Returns
Hash of the given message.
virgil::crypto::VirgilByteArray virgil::crypto::foundation::VirgilHash::hmac ( const virgil::crypto::VirgilByteArray key,
const virgil::crypto::VirgilByteArray data 
) const

Produce HMAC hash.

Process the given message immediately and return it's HMAC hash.

Parameters
key- secret key.
data- message to be hashed.
Returns
HMAC hash of the given message.
virgil::crypto::VirgilByteArray virgil::crypto::foundation::VirgilHash::hmacFinish ( )

Return final message HMAC hash.

Returns
Message HMAC hash processed by series of hmacUpdate() method.
See also
hmacStart()
hmacReset()
hmacUpdate()
void virgil::crypto::foundation::VirgilHash::hmacStart ( const virgil::crypto::VirgilByteArray key)

Initialize HMAC hashing for the new message hash.

Parameters
key- secret key.
void virgil::crypto::foundation::VirgilHash::hmacUpdate ( const virgil::crypto::VirgilByteArray data)

Update / process message HMAC hash.

This method MUST be used after hmacStart() or hmacReset() methods only. This method MAY be called multiple times to process long message splitted to a shorter chunks.

Parameters
data- message to be hashed.
See also
hmacStart()
hmacReset()
std::string virgil::crypto::foundation::VirgilHash::name ( ) const

Returns name of the hash function.

Returns
Name of the hash function.
size_t virgil::crypto::foundation::VirgilHash::size ( ) const

Return size of the message digest output.

Returns
Size in octets.
int virgil::crypto::foundation::VirgilHash::type ( ) const

Return underlying hash type.

Note
Used for internal purposes only
void virgil::crypto::foundation::VirgilHash::update ( const virgil::crypto::VirgilByteArray data)

Update / process message hash.

This method MUST be used after start() method only. This method MAY be called multiple times to process long message splitted to a shorter chunks.

Parameters
data- message to be hashed.
See also
start()

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