ethereum.crypto.hash

Cryptographic Hash Functions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. contents:: Table of Contents :backlinks: none :local:

Introduction

Cryptographic hashing functions.

Hash32

19
Hash32 = Bytes32

Hash64

20
Hash64 = Bytes64

keccak256

Computes the keccak256 hash of the input buffer.

Parameters

buffer : Input for the hashing function.

Returns

hash : ethereum.base_types.Hash32 Output of the hash function.

def keccak256(buffer: Bytes) -> Hash32:
24
    """
25
    Computes the keccak256 hash of the input `buffer`.
26
27
    Parameters
28
    ----------
29
    buffer :
30
        Input for the hashing function.
31
32
    Returns
33
    -------
34
    hash : `ethereum.base_types.Hash32`
35
        Output of the hash function.
36
    """
37
    k = keccak.new(digest_bits=256)
38
    return Hash32(k.update(buffer).digest())

keccak512

Computes the keccak512 hash of the input buffer.

Parameters

buffer : Input for the hashing function.

Returns

hash : ethereum.base_types.Hash32 Output of the hash function.

def keccak512(buffer: Bytes) -> Hash64:
42
    """
43
    Computes the keccak512 hash of the input `buffer`.
44
45
    Parameters
46
    ----------
47
    buffer :
48
        Input for the hashing function.
49
50
    Returns
51
    -------
52
    hash : `ethereum.base_types.Hash32`
53
        Output of the hash function.
54
    """
55
    k = keccak.new(digest_bits=512)
56
    return Hash64(k.update(buffer).digest())