Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jvdsn
GitHub Repository: jvdsn/crypto-attacks
Path: blob/master/attacks/cbc_mac/length_extension.py
2589 views
1
from Crypto.Util.strxor import strxor
2
3
4
def attack(m1, t1, m2, t2):
5
"""
6
Uses a length extension attack to forge a message and tag pair for CBC-MAC.
7
:param m1: the first message
8
:param t1: the tag of the first message
9
:param m2: the second message
10
:param t2: the tag of the second message
11
:return: a tuple containing a valid message and tag for CBC-MAC
12
"""
13
m3 = bytearray(m1)
14
m3 += strxor(t1, m2[:16])
15
for i in range(16, len(m2), 16):
16
m3 += m2[i:i + 16]
17
18
return m3, t2
19
20