ch54.py 文件源码

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

项目:matasano 作者: shainer 项目源码 文件源码
def MerkleDamgard(message, state, stateLen):
    """Applies an arbitrary Merkle-Damgard construction to the message.

    The default state length and initial state are those used all over
    this program.
    """
    newState = state
    # The state length we use is shorter than what AES wants for the keys.
    newState = padPKCS7(newState)

    for i in range(GetNumBlocks(message)):
        cipher = AES.new(newState, AES.MODE_ECB)
        newState = cipher.encrypt(GetBlock(message, i))

        # This would be a really bad idea to do in practice, if we are
        # actually using AES or an algorithm that requires keys of
        # a certain size. It's needed here because the hash and
        # the key needs to be the same for the challenge to work, and
        # the hash we return has 2 bytes.
        newState = padPKCS7(newState[:stateLen])

    return newState[:stateLen]

# Generates the initial 2**k states of the tree at random. We make
# all of them different with each other.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号