ethereum.crypto.hash
Cryptographic Hash Functions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. contents:: Table of Contents :backlinks: none :local:
Introduction
Cryptographic hashing functions.
Hash32
18 | Hash32 = Bytes32 |
---|
Hash64
19 | 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:
23 | """ |
---|---|
24 | Computes the keccak256 hash of the input `buffer`. |
25 |
|
26 | Parameters |
27 | ---------- |
28 | buffer : |
29 | Input for the hashing function. |
30 |
|
31 | Returns |
32 | ------- |
33 | hash : `ethereum.base_types.Hash32` |
34 | Output of the hash function. |
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) -> 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 | k = keccak.new(digest_bits=512) |
55 | return Hash64(k.update(buffer).digest()) |