Package Cryptodome :: Package Hash :: Module BLAKE2s :: Class BLAKE2s_Hash

Class BLAKE2s_Hash

object --+
         |
        BLAKE2s_Hash

Class that implements a BLAKE2s hash
Instance Methods
 
__init__(self, data, key, digest_bytes, update_after_digest)
Initialize a BLAKE2s hash object.
 
update(self, data)
Continue hashing of a message by consuming the next chunk of data.
 
digest(self)
Return the binary (non-printable) digest of the message that has been hashed so far.
 
hexdigest(self)
Return the printable digest of the message that has been hashed so far.
 
verify(self, mac_tag)
Verify that a given binary MAC (computed by another party) is valid.
 
hexverify(self, hex_mac_tag)
Verify that a given printable MAC (computed by another party) is valid.
 
new(self, **kwargs)
Return a new instance of a BLAKE2s hash object.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables
  block_size = 32
The internal block size of the hash algorithm in bytes.
Instance Variables
  digest_size
The size of the resulting hash in bytes.
Properties

Inherited from object: __class__

Method Details

__init__(self, data, key, digest_bytes, update_after_digest)
(Constructor)

 
Initialize a BLAKE2s hash object.
Overrides: object.__init__

update(self, data)

 

Continue hashing of a message by consuming the next chunk of data.

Repeated calls are equivalent to a single call with the concatenation of all the arguments. In other words:

>>> m.update(a); m.update(b)

is equivalent to:

>>> m.update(a+b)
Parameters:
  • data (byte string) - The next chunk of the message being hashed.

digest(self)

 

Return the binary (non-printable) digest of the message that has been hashed so far.

You cannot update the hash anymore after the first call to digest (or hexdigest).

Returns:
A byte string of digest_size bytes. It may contain non-ASCII characters, including null bytes.

hexdigest(self)

 

Return the printable digest of the message that has been hashed so far.

This method does not change the state of the hash object.

Returns:
A string of 2* digest_size characters. It contains only hexadecimal ASCII digits.

verify(self, mac_tag)

 
Verify that a given binary MAC (computed by another party) is valid.
Parameters:
  • mac_tag (byte string) - The expected MAC of the message.
Raises:
  • ValueError - if the MAC does not match. It means that the message has been tampered with or that the MAC key is incorrect.

hexverify(self, hex_mac_tag)

 
Verify that a given printable MAC (computed by another party) is valid.
Parameters:
  • hex_mac_tag (string) - The expected MAC of the message, as a hexadecimal string.
Raises:
  • ValueError - if the MAC does not match. It means that the message has been tampered with or that the MAC key is incorrect.