Hash functions

class pyflocker.ciphers.backends.cryptography_.Hash.Hash(name: str, data: bytes | None = None, *, digest_size: int | None = None, _copy: Hash | None = None)[source]

Bases: BaseHash

property digest_size: int

The size of the digest produced by the hashing object, measured in bytes. If the hash has a variable output size, this output size must be chosen when the hashing object is created, and this attribute must contain the selected size. Therefore, None is not a legal value for this attribute.

Returns:

Digest size as integer.

property block_size: int

An integer value or NotImplemented; the internal block size of the hash algorithm in bytes. The block size is used by the HMAC module to pad the secret key to digest_size or to hash the secret key if it is longer than digest_size. If no HMAC algorithm is standardized for the hash algorithm, returns NotImplemented instead.

Returns:

An integer if block size is available, otherwise NotImplemented.

See also

PEP 452 – API for Cryptographic Hash Functions v2.0, https://www.python.org/dev/peps/pep-0452

property name: str

Name of the hash function.

property oid: str

The ASN.1 Object ID.

update(data: bytes) None[source]

Hash string into the current state of the hashing object. update() can be called any number of times during a hashing object’s lifetime.

Parameters:

data – The chunk of message being hashed.

Raises:

AlreadyFinalized – Raised if digest() or hexdigest() has been called.

digest() bytes[source]

Return the hash value of this hashing object as a string containing 8-bit data. The object is not altered in any way by this function; you can continue updating the object after calling this function.

Returns:

Digest as binary form.

copy() Hash[source]

Return a separate copy of this hashing object. An update to this copy won’t affect the original object.

Returns:

A copy of hash function.

Raises:

AlreadyFinalized – This is raised if the method is called after calling digest() method.

new(data: bytes | None = None, *, digest_size: int | None = None) Hash[source]

Create a fresh hash object.

pyflocker.ciphers.backends.cryptography_.Hash.algorithms_available() set[str][source]

Return the names of the available hash algorithms.

pyflocker.ciphers.backends.cryptography_.Hash.new(name: str, data: bytes = b'', *, digest_size: int | None = None, **kwargs: Any) Hash[source]

Instantiate a hash object.

Parameters:
  • name – The name of the hash function.

  • data – The initial chunk of message to feed to hash.

Keyword Arguments:

digest_size – The length of the digest size. Must be supplied if the hash function supports it.

Raises:
  • KeyError – If name is not a hash function name.

  • ValueError – If digest_size is required but not provided.