def oracle(userdata: bytes) -> bytes: key = RANDOM_KEY prefix = b"comment1=cooking%20MCs;userdata=" postfix = b";comment2=%20like%20a%20pound%20of%20bacon" userdata = userdata.replace(b";", b"").replace(b"=", b"") plaintext = pkcs7(prefix + userdata + postfix) return encrypt_aes_cbc(key, iv=bytes(16), plaintext=plaintext)
def encryption_oracle(plaintext: bytes) -> bytes: plaintext = bytes(randrange(5, 11)) + plaintext + bytes(randrange(5, 11)) plaintext = pkcs7(plaintext) key = get_random_bytes(16) if randrange(2) == 0: iv = get_random_bytes(16) return encrypt_aes_cbc(key, iv, plaintext) cypher = AES.new(key, AES.MODE_ECB) return cypher.encrypt(plaintext)
def encryption_oracle(plaintext): plaintext = bytes(randrange(5, 11)) + plaintext + bytes(randrange(5, 11)) plaintext = pkcs7(plaintext, 16) key = bytes(getrandbits(8) for i in range(16)) if randrange(0,2) == 0: iv = bytes(getrandbits(8) for i in range(16)) cyphertext = encrypt_aes_cbc(plaintext, key, iv) #print("CBC") else: cypher = AES.new(key, AES.MODE_ECB) cyphertext = cypher.encrypt(plaintext) #print("ECB") return cyphertext
def cbc_oracle(plaintext = chose_plaintext(), k = RANDOM_KEY, iv = IV): return encrypt_aes_cbc(plaintext, k, iv)
def send_message(self, message: bytes) -> None: iv = get_random_bytes(16) cyphertext = encrypt_aes_cbc(self._aes_key(), iv, pkcs7(message)) self.peer.receive_message(cyphertext + iv)
def oracle(userdata, k = RANDOM_KEY): prefix = b'comment1=cooking%20MCs;userdata=' postfix = b';comment2=%20like%20a%20pound%20of%20bacon' userdata = userdata.replace(";", "").replace("=", "") plaintext = pkcs7(prefix + bytes(userdata, "ascii") + postfix) return encrypt_aes_cbc(plaintext, k, iv = bytes(16))
def bad_cbc_encryption(plaintext: bytes) -> bytes: key = RANDOM_KEY return encrypt_aes_cbc(key, iv=key, plaintext=pkcs7(plaintext))
def cbc_oracle() -> bytes: plaintext = pkcs7(choose_plaintext()) return encrypt_aes_cbc(RANDOM_KEY, IV, plaintext)
def cbc_oracle(plaintext: bytes) -> int: """CBC-mode compression orcle""" key = get_random_bytes(BLOCKSIZE) iv = get_random_bytes(BLOCKSIZE) return len( encrypt_aes_cbc(key, iv, pkcs7(compress(format_request(plaintext)))))
def cbc_mac(key: bytes, iv: bytes, message: bytes) -> bytes: assert len(message) % BLOCKSIZE == 0 ciphertext = encrypt_aes_cbc(key, iv, message) return ciphertext[-BLOCKSIZE:]