Cryptographic hash functions take arbitrary binary strings as input,
and produce a random-like fixed-length output (called digest or hash value).
It is practically infeasible to derive the original input data
from the digest. In other words, the cryptographic hash function is one-way
(pre-image resistance).
Given the digest of one message, it is also practically infeasible
to find another message (second pre-image) with the same digest
(weak collision resistance).
Finally, it is infeasible to find two arbitrary messages with the
same digest (strong collision resistance).
Regardless of the hash algorithm, an n bits long digest is at most
as secure as a symmetric encryption algorithm keyed with n/2 bits
(birthday attack).
Hash functions can be simply used as integrity checks. In
combination with a public-key algorithm, you can implement a
digital signature.
Every time you want to hash a message, you have to create a new hash object
with the new() function in the relevant algorithm module (e.g.
Crypto.Hash.SHA256.new()).
A first piece of message to hash can be passed to new() with the data parameter:
Size of the digest in bytes, that is, the output
of the digest() method.
It does not exist for hash functions with variable digest output
(such as Crypto.Hash.SHAKE128).
This is also a module attribute.
block_size
The size of the message block in bytes, input to the compression
function. Only applicable for algorithms based on the Merkle-Damgard
construction (e.g. Crypto.Hash.SHA256).
This is also a module attribute.
oid
A string with the dotted representation of the ASN.1 OID
assigned to the hash algorithm.
A XOF is similar to a conventional cryptographic hash: it is
a one-way function that maps a piece of data of arbitrary size to
a random-like output. It provides some guarantees over
collision resistance, pre-image resistance, and second pre-image resistance.
Unlike a conventional hash, an application using a XOF can choose the length of the output.
For this reason, a XOF does not have a digest() method.
Instead, it has a read(N) method to extract the next N bytes of the output.