Skip to content
🎉 Welcome! Enjoy your reading, and I hope you will learn something new.

Message Authentication Code (MAC)

A message authentication code (MAC), sometimes known as an authentication tag, is a short piece of information used for authenticating and integrity-checking a message.

Attacks

CBC-MAC Forgery

length_extension.py

Length Extension

length_extension.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# https://github.com/jvdsn/crypto-attacks/blob/master/attacks/cbc_mac/length_extension.py

from Crypto.Util.strxor import strxor


def attack(m1, t1, m2, t2):
    """
    Uses a length extension attack to forge a message and tag pair for CBC-MAC.
    :param m1: the first message
    :param t1: the tag of the first message
    :param m2: the second message
    :param t2: the tag of the second message
    :return: a tuple containing a valid message and tag for CBC-MAC
    """
    m3 = bytearray(m1)
    m3 += strxor(t1, m2[:16])
    for i in range(16, len(m2), 16):
        m3 += m2[i:i + 16]

    return m3, t2

Resources

Last updated on