ethereum.crypto.hash
Cryptographic Hash Functions.
.. contents:: Table of Contents :backlinks: none :local:
Introduction
Cryptographic hashing functions.
Hash32
| 17 | Hash32 = Bytes32 |
|---|
Hash64
| 18 | 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 | bytearray) -> Hash32:
| 22 | """ |
|---|---|
| 23 | Computes the keccak256 hash of the input `buffer`. |
| 24 | |
| 25 | Parameters |
| 26 | ---------- |
| 27 | buffer : |
| 28 | Input for the hashing function. |
| 29 | |
| 30 | Returns |
| 31 | ------- |
| 32 | hash : `ethereum.base_types.Hash32` |
| 33 | Output of the hash function. |
| 34 | |
| 35 | """ |
| 36 | k = keccak.new(digest_bits=256) |
| 37 | 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 | bytearray) -> Hash64:
| 41 | """ |
|---|---|
| 42 | Computes the keccak512 hash of the input `buffer`. |
| 43 | |
| 44 | Parameters |
| 45 | ---------- |
| 46 | buffer : |
| 47 | Input for the hashing function. |
| 48 | |
| 49 | Returns |
| 50 | ------- |
| 51 | hash : `ethereum.base_types.Hash32` |
| 52 | Output of the hash function. |
| 53 | |
| 54 | """ |
| 55 | k = keccak.new(digest_bits=512) |
| 56 | return Hash64(k.update(buffer).digest()) |