def extend_message(message, extension, init, key_len): ''' Length based extension attack on a md4 keyed authentication code Arguments: message: Original message extension: Message to append init: list of md4 init variables key_len: length of key ''' original_len = key_len + len(message) glue_padding = get_glue_padding(original_len) original_len += len(glue_padding) new_message = message + glue_padding + extension new_hash = md4(extension, init, original_len).hexdigest() return (new_message, new_hash)
def mac(self, text): return md4(self.key + text).hexdigest()