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.
评论列表
文章目录