The Blake2 Implementation

Module Contents

Classes

Blake2

Implementation of the BLAKE2 cryptographic hashing algorithm.

Blake2b

The Blake2b flavor (64-bits) of Blake2.

Functions

spit_le_to_uint

Extracts 8 byte words from a given data.

Module Details

spit_le_to_uint

spit_le_to_uint(data: bytes, start: int, num_words: int)List[ethereum.base_types.Uint]

Extracts 8 byte words from a given data.

Parameters
  • data – The data in bytes from which the words need to be extracted

  • start – Position to start the extraction

  • num_words – The number of words to be extracted

def spit_le_to_uint(data: bytes, start: int, num_words: int) -> List[Uint]:
    words = []
    for i in range(num_words):
        start_position = start + (i * 8)
        words.append(
            Uint.from_le_bytes(data[start_position : start_position + 8])
        )

    return words

Blake2

Implementation of the BLAKE2 cryptographic hashing algorithm.

Please refer the following document for details: https://datatracker.ietf.org/doc/html/rfc7693

class Blake2
w :int
mask_bits :int
word_format :str
R1 :int
R2 :int
R3 :int
R4 :int
sigma :Tuple = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0,...
IV :Tuple = [7640891576956012808, 13503953896175478587, 4354685564936845355, 11912009170470909681,...
property max_wordint

Largest value for a given Blake2 flavor.

property w_R1int

(w - R1) value for a given Blake2 flavor. Used in the function G

property w_R2int

(w - R2) value for a given Blake2 flavor. Used in the function G

property w_R3int

(w - R3) value for a given Blake2 flavor. Used in the function G

property w_R4int

(w - R4) value for a given Blake2 flavor. Used in the function G

property sigma_lenint

Length of the sigma parameter.

get_blake2_parameters(data: bytes)Tuple

Extract the parameters required in the Blake2 compression function from the provided bytes data.

Parameters

data – The bytes data that has been passed in the message.

G(v: List, a: int, b: int, c: int, d: int, x: int, y: int)List

The mixing function used in Blake2 https://datatracker.ietf.org/doc/html/rfc7693#section-3.1

Parameters
  • v – The working vector to be mixed.

  • a – Indexes within v of the words to be mixed.

  • b – Indexes within v of the words to be mixed.

  • c – Indexes within v of the words to be mixed.

  • d – Indexes within v of the words to be mixed.

  • x – The two input words for the mixing.

  • y – The two input words for the mixing.

compress(num_rounds: ethereum.base_types.Uint, h: List[ethereum.base_types.Uint], m: List[ethereum.base_types.Uint], t_0: ethereum.base_types.Uint, t_1: ethereum.base_types.Uint, f: bool)bytes

‘F Compression’ from section 3.2 of RFC 7693: https://tools.ietf.org/html/rfc7693#section-3.2

Parameters
  • num_rounds – The number of rounds. A 32-bit unsigned big-endian word

  • h – The state vector. 8 unsigned 64-bit little-endian words

  • m – The message block vector. 16 unsigned 64-bit little-endian words

  • t_0 – Offset counters. 2 unsigned 64-bit little-endian words

  • t_1 – Offset counters. 2 unsigned 64-bit little-endian words

  • f – The final block indicator flag. An 8-bit word

Blake2b

The Blake2b flavor (64-bits) of Blake2. This version is used in the pre-compiled contract.

class Blake2b

Bases: Blake2

w :int = 64
mask_bits :int = 18446744073709551615
word_format :str = Q
R1 :int = 32
R2 :int = 24
R3 :int = 16
R4 :int = 63