Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jvdsn
GitHub Repository: jvdsn/crypto-attacks
Path: blob/master/attacks/cbc_and_cbc_mac/mte_key_reuse.py
2589 views
1
def attack(decrypt_oracle, iv, c, encrypted_zeroes):
2
"""
3
Uses a chosen-ciphertext attack to decrypt the ciphertext.
4
Prior knowledge of E_k(0^16) is required for this attack to work.
5
:param decrypt_oracle: the decryption oracle
6
:param iv: the initialization vector
7
:param c: the ciphertext
8
:param encrypted_zeroes: a full zero block encrypted using the key
9
:return: the plaintext
10
"""
11
c_ = iv + c[:-16] + encrypted_zeroes
12
p_ = decrypt_oracle(bytes(16), c_)
13
return p_[16:]
14
15