def hash_chain(message: bytes) -> bytes:
"""Mix several hash functions to distribute trust.
This construction remains secure in case a weakness is discovered
in one of the hash functions (e.g. insecure algorithm that is not
unpredictable or that has weak preimage resistance, or if the
algorithm is badly implemented).
In case where the implementation is malicious, this construction
forces stateless implementations -- that try to compromise mixing
phase -- to guess it's position in the construction, which will
eventually lead to key state mismatch and thus detection.
"""
d1 = sha3_256(blake2s(sha256(message)))
d2 = sha3_256(sha256(blake2s(message)))
d3 = blake2s(sha3_256(sha256(message)))
d4 = blake2s(sha256(sha3_256(message)))
d5 = sha256(blake2s(sha3_256(message)))
d6 = sha256(sha3_256(blake2s(message)))
d7 = sha3_256(message)
d8 = blake2s(message)
d9 = sha256(message)
# Mixing phase
x1 = xor(d1, d2)
x2 = xor(x1, d3)
x3 = xor(x2, d4)
x4 = xor(x3, d5)
x5 = xor(x4, d6)
x6 = xor(x5, d7)
x7 = xor(x6, d8)
x8 = xor(x7, d9)
return x8
评论列表
文章目录