Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jvdsn
GitHub Repository: jvdsn/crypto-attacks
Path: blob/master/attacks/cbc_and_cbc_mac/etm_key_reuse.py
2589 views
1
def attack(encrypt_oracle, decrypt_oracle, iv, c, t):
2
"""
3
Uses a chosen-ciphertext attack to decrypt the ciphertext.
4
:param encrypt_oracle: the encryption oracle
5
:param decrypt_oracle: the decryption oracle
6
:param iv: the initialization vector
7
:param c: the ciphertext
8
:param t: the tag corresponding to the ciphertext
9
:return: the plaintext
10
"""
11
p_ = bytes(16) + iv + c
12
iv_, c_, t_ = encrypt_oracle(p_)
13
c__ = iv + c
14
p__ = decrypt_oracle(iv_, c__, c_[-32:-16])
15
return p__[16:]
16
17