Skip to content

Hashing

blake2b_256_hash(data: Union[str, bytes]) -> bytes

GP-0.7.2-section:I.3 (H) | Creates a Blake-SHA256 hash using the given data.

Parameters:

Name Type Description Default
data Union[str, bytes]
required

Returns:

Type Description
bytes hash
Source code in pyjamaz/hashing.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def blake2b_256_hash(data: Union[str, bytes]) -> bytes:
    """
    GP-0.7.2-section:I.3 (H) | Creates a Blake-SHA256 hash using the given data.

    Parameters
    ----------
    data: data to be hashed

    Returns
    -------
    bytes hash
    """
    if type(data) is str:
        data = bytes.fromhex(data[2:])
    return blake2b(data, digest_size=32).digest()

blake2b_128_hash(data: Union[str, bytes]) -> bytes

Creates a Blake-SHA128 hash using the given data.

Parameters:

Name Type Description Default
data Union[str, bytes]
required

Returns:

Type Description
bytes hash
Source code in pyjamaz/hashing.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def blake2b_128_hash(data: Union[str, bytes]) -> bytes:
    """
    Creates a Blake-SHA128 hash using the given data.

    Parameters
    ----------
    data: data to be hashed

    Returns
    -------
    bytes hash
    """
    if type(data) is str:
        data = bytes.fromhex(data[2:])
    return blake2b(data, digest_size=16).digest()

blake2b_64_hash(data: Union[str, bytes]) -> bytes

Creates a Blake-SHA64 hash using the given data.

Parameters:

Name Type Description Default
data Union[str, bytes]
required

Returns:

Type Description
bytes hash
Source code in pyjamaz/hashing.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def blake2b_64_hash(data: Union[str, bytes]) -> bytes:
    """
    Creates a Blake-SHA64 hash using the given data.
    Parameters
    ----------
    data: data to be hashed

    Returns
    -------
    bytes hash
    """
    if type(data) is str:
        data = bytes.fromhex(data[2:])
    return blake2b(data, digest_size=8).digest()

keccak_256_hash(data: Union[str, bytes]) -> bytes

GP-0.7.2-section:I.3 (H_K) | Creates a Keccak-SHA256 hash using the given data.

Parameters:

Name Type Description Default
data Union[str, bytes]
required

Returns:

Type Description
bytes hash
Source code in pyjamaz/hashing.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def keccak_256_hash(data: Union[str, bytes]) -> bytes:
    """
    GP-0.7.2-section:I.3 (H_K) | Creates a Keccak-SHA256 hash using the given data.

    Parameters
    ----------
    data: data to be hashed

    Returns
    -------
    bytes hash
    """
    if type(data) is str:
        data = bytes.fromhex(data[2:])
    k = keccak.new(digest_bits=256)
    k.update(data)

    return k.digest()