ch53.py 文件源码

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

项目:matasano 作者: shainer 项目源码 文件源码
def CBCMacWithStates(message, iv):
    """Computes the CBC-MAC of a message given the IV.

    Returns a tuple with the hash and a list of tuples; the first
    element is the block index and the second is the intermediate state
    associated with that block, as a byte string.

    It is expected that this returns the same hash as CBC-MAC above
    given the same inputs.
    """
    M_states = []

    paddedMessage = padPKCS7(message)
    intermediateMessage = b''
    currentState = iv

    for bIndex in range(GetNumBlocks(paddedMessage)):
        intermediateMessage = GetBlock(paddedMessage, bIndex)

        cipher = AES.new(b'YELLOW SUBMARINE', AES.MODE_CBC, currentState)
        currentState = cipher.encrypt(intermediateMessage)
        currentState = currentState[-AES.block_size:]
        M_states.append( ( bIndex, currentState ) )

    return currentState, M_states
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号