def md_hash(message): h = initial_state M = length_padding(message) for i in range(len(M) // BLOCK_SIZE): Mi = util.get_ith_block(M, i, BLOCK_SIZE) h = util.ecb_encrypt(Mi, util.padding(h, BLOCK_SIZE))[0:STATE_LEN] return binascii.hexlify(h)
def md_hash(message, state_len = STATE_LEN, H = None): # initial state h = b''.join([util.int_to_bytes((37*i + 42) % 256) for i in range(state_len)]) if not H: H = h M = util.padding(message, AES_BLOCK_SIZE) for i in range(len(M)//AES_BLOCK_SIZE): Mi = util.get_ith_block(M, i, AES_BLOCK_SIZE) H = util.ecb_encrypt(Mi, util.padding(H, AES_BLOCK_SIZE))[0:state_len] return binascii.hexlify(H)
def ecb_cbc_oracle(data): prefix = util.random_byte_string(random.randint(5, 10)) suffix = util.random_byte_string(random.randint(5, 10)) key = util.random_byte_string(16) data = util.padding(prefix + data + suffix, 16) mode = random.randint(0, 1) if mode == 1: return util.ecb_encrypt(data, key), mode else: iv = util.random_byte_string(16) return util.cbc_encrypt(data, key, iv), mode
def ecb_encrypt_surround(chosen): key = b'\x01\x1f\x89\x94\x85{\x8e\xa4\xfa\x8e\xc9\xc3{\x1dz\x06' prefix = b'\xc0NF\x87\xd69\xb7\x11n\\\xd5H\x0c\xee\xe6\xd2\xe9k\xdc\xb9^\x7fk\xff\xectG2gRx\xb2Y5\xd7\xf2}\xecM\xee&\xc7' secret = 'Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBqdXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK' secret = util.base64.b64decode(secret) return util.ecb_encrypt(util.padding(prefix + chosen + secret, 16), key)
def ecb_encrypt_prepend(prefix): key = b'\x01\x1f\x89\x94\x85{\x8e\xa4\xfa\x8e\xc9\xc3{\x1dz\x06' data = 'Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBqdXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK' data = base64.b64decode(data) return util.ecb_encrypt(util.padding(prefix + data, 16), key)
def encrypt_profile_for(email): plaintext = encode_profile(profile_for(email)).encode('utf-8') return util.ecb_encrypt(util.padding(plaintext, 16), PROFILE_KEY)
def md_hash_instrumented(M, H=initial_state): for i in range(len(M) // BLOCK_SIZE): Mi = util.get_ith_block(M, i, BLOCK_SIZE) H = util.ecb_encrypt(Mi, util.padding(H, BLOCK_SIZE))[0:STATE_LEN] return binascii.hexlify(H)