crypto.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:tfc 作者: maqp 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号