Beispiel #1
0
def produce(txt):
    # Random 16 bytes.
    key = rbytes.count(16)

    # Append and prepend some random bytes to the input txt.
    before_count = random.randrange(5, 11)
    after_count  = random.randrange(5, 11)
    before = rbytes.count(before_count)
    after = rbytes.count(after_count)
    plain = before + txt + after

    # Pad the plaintext to a blocksize of 16.
    plain = pad.pkcs7(plain, 16)

    # Choose a mode to use.
    mode = 'ecb' if random.randrange(0, 2) == 0 else 'cbc'

    # Now do the encryption.
    if mode == 'ecb':
        cipher = aes.encrypt_ecb(plain, key)
    elif mode == 'cbc':
        random_iv = rbytes.count(16)
        cipher = aes.encrypt_cbc(plain, key, iv=random_iv)

    return cipher
Beispiel #2
0
def encryption_oracle(m):
    key = gen_key()
    prefix = os.urandom(random.randint(5, 10))
    suffix = os.urandom(random.randint(5, 10))

    pt = prefix + m + suffix

    #use ECB half the time and CBC the other half
    if ord(os.urandom(1)) % 2:
        print 'ECB'
        return aes.encrypt_ecb(pt, key)
    else:
        print 'CBC'
        iv = os.urandom(16)
        #don't return iv (otherwise length will give difference away
        return aes.encrypt_cbc(pt, key, iv)[16:]
Beispiel #3
0
def encryption_oracle_cbc(m):
    iv = os.urandom(16)
    return aes.encrypt_cbc(m + secret, key, iv)[16:]
Beispiel #4
0
def get_ciphertext():
	iv = os.urandom(16)
	return aes.encrypt_cbc(random.choice(pts), key, iv)
Beispiel #5
0
def oracle():
    #this value does not matter (as long as it's long enough)
    userdata = 'bs' * 48
    ct = aes.encrypt_cbc(urllib.quote(userdata), key, key)
    #iv = key ==> don't send iv
    return ct[16:]
Beispiel #6
0
def send_ct(con, msg, key):
    '''sends <len> <aes cbc encrypted msg>'''
    iv = urandom(16)
    return send_len_payload(con, aes.encrypt_cbc(msg, key, iv))
Beispiel #7
0
def oracle(userdate):
	iv = os.urandom(16)
	return aes.encrypt_cbc(prefix + urllib.quote(userdate) + sufix, key, iv)
Beispiel #8
0
def cbc_mac_tag(m, k, iv):
    return aes.encrypt_cbc(m, k, iv)[-16:]