# B.remove_assignments, # [ B.compute_const_expressions, size ], # B.drop_print, # [ B.reduce_assignments, 'main', 'main_end' ], [B.dump, 'all.bytecode'], # B.research_reverse, # [ B.reverse_ops, reverse_num ], [B.no_reverse, reverse_num], ) reverse = d['reverse'] code = d['code'] scalar = B.deep_copy(code) reverse_str = B.thread_code(reverse, [B.dump, 'reverse.bytecode'], [O.gen_to_str, '$code', args]) B.global_vars['reverse'] = reverse_str scalar_str = B.thread_code(scalar, [B.dump, 'scalar.bytecode'], [O.gen_to_str, '$code', args]) B.global_vars['scalar'] = scalar_str B.thread_code( code, # B.reuse_variables, # B.vectorize,
code = B.get_code_full('xtea') # values from "unholy" task in BKP CTF 2016 key = [0x74616877, 0x696f6773, 0x6e6f676e, 0x65726568] # Computation forward encrypt = B.thread_code( code, [B.override_state, key], B.replace_state_with_const, [ B.interpret, # values from "unholy" task in BKP CTF 2016 [1129335618, 1752909396], [2990080719, 722035088] ]) # B.dump(encrypt, 'forward.bytecode') # Computation backwards decrypt = B.reverse_full(B.deep_copy(encrypt)) B.thread_code( decrypt, [ B.interpret, # values from "unholy" task in BKP CTF 2016 [2990080719, 722035088], [1129335618, 1752909396] ])
# [ B.unpack_const_subscripts, 'k' ], # B.remove_assignments, # B.compute_const_expressions, # B.drop_print, # [ B.reduce_assignments, 'main', 'main_end' ], [ B.dump, 'all.bytecode' ], # B.research_reverse, # [ B.reverse_ops, reverse_num ], [ B.no_reverse, reverse_num ], ) reverse = d['reverse'] code = d['code'] scalar = B.deep_copy(code) reverse_str = B.thread_code( reverse, [ B.dump, 'reverse.bytecode' ], [ O.gen_to_str, '$code', args ] ) B.global_vars['reverse'] = reverse_str scalar_str = B.thread_code( scalar, [ B.dump, 'scalar.bytecode' ], [ O.gen_to_str, '$code', args ] ) B.global_vars['scalar'] = scalar_str B.thread_code( code, # B.reuse_variables,
def gen_raw_format(c_template, algo_file, tests, tag=None, special1=None, special2=None, special0=None, reverse_num=0, algo_override=None): c_code = U.load_code_template(c_template) args = {} # # %% extract that from code # size = 4 # endianity = 'be' algo_name = algo_file algo_upper = algo_name.upper() algo_code = B.get_code_full(algo_override or algo_file, **args) d = algo_code if special0: d = B.thread_code(d, *special0) interface = B.get_interface(d) size = interface['size'] endianity = interface['endianity'] inputs = interface['inputs'] outputs = interface['outputs'] print interface if not tag: tag = '$' + algo_upper + '$' vs = { 'fmt_struct_name': 'raw1_' + algo_name, 'format_name': fmt_name_raw(algo_name), 'algo_name': 'dk ' + algo_upper, 'tag': tag, 'plaintext_length': (inputs - 2) * size - 1, 'binary_form_size': outputs * size, 'tests': tests } O.apply_bs_size(bs_size) U.setup_vars(vs) # Optimizations and code generation interleave = 1 B.global_vars['batch_size'] = 1 # reverse_num = 7 B.global_vars['interleave'] = interleave B.global_vars['reverse_num'] = reverse_num B.global_vars['vectorize'] = 1 d = B.thread_code(d, B.replace_state_with_const) if special1: d = B.thread_code(d, *special1) d = B.thread_code( d, B.remove_assignments, [B.compute_const_expressions, size], [B.no_reverse, reverse_num], ) reverse = d['reverse'] code = d['code'] scalar = B.deep_copy(code) reverse_str = B.thread_code(reverse, [B.dump, 'reverse.bytecode'], [O.gen_to_str, '$code', args]) B.global_vars['reverse'] = reverse_str scalar_str = B.thread_code(scalar, [B.dump, 'scalar.bytecode'], [O.gen_to_str, '$code', args]) B.global_vars['scalar'] = scalar_str out_file = fmt_file(vs['format_name']) d = B.thread_code(code, B.vectorize) if special2: d = B.thread_code(d, *special2) d = B.thread_code(d, B.use_define_for_some, [B.interleave, interleave], [O.gen, out_file, c_code, args, B.global_vars])