Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
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
Exemple #4
0
def cbc_oracle(plaintext = chose_plaintext(), k = RANDOM_KEY, iv = IV):
    return encrypt_aes_cbc(plaintext, k, iv)
Exemple #5
0
 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)
Exemple #6
0
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))
Exemple #7
0
def bad_cbc_encryption(plaintext: bytes) -> bytes:
    key = RANDOM_KEY
    return encrypt_aes_cbc(key, iv=key, plaintext=pkcs7(plaintext))
Exemple #8
0
def cbc_oracle() -> bytes:
    plaintext = pkcs7(choose_plaintext())
    return encrypt_aes_cbc(RANDOM_KEY, IV, plaintext)
Exemple #9
0
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)))))
Exemple #10
0
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:]