Beispiel #1
0
U.setup_vars(vs)

# Optimizations and code generation

code = B.get_code_full(algo_file, **args)

interleave = 1

B.global_vars['batch_size'] = 1

B.global_vars['interleave'] = interleave

# B.global_vars['vectorize'] = 1

d = B.thread_code(code, B.replace_state_with_const, [B.dump, 'pure.bytecode'],
                  [B.bitslice, 64, size], B.expand_bs_andnot,
                  [B.dump, 'bs.bytecode'],
                  [O.gen, c_code, args, B.global_vars])

# p1, p2 = B.thread_code( code,
#     B.replace_state_with_const,
#     [ B.dump, 'pure.bytecode' ],
#     [ B.bitslice, 64, size ],
#     B.expand_bs_andnot,
#     [ B.dump, 'bs.bytecode' ],
#     [ B.split_bitslice, 20000 ]
# )

# p1code = B.thread_code( p1,
#     [ O.gen_to_str, '$code', args ]
# )
# B.global_vars['part1code'] = p1code
Beispiel #2
0
d = B.thread_code(
    B.get_code_full(algo_file, **args),

    # [ B.interpret, [0x80 << 56] + [0] * 14 + [1] ],
    # B.my_exit,

    # [ B.interpret, [0x61626380 << 32] + [0] * 14 + [1] ],
    # B.my_exit,
    B.replace_state_with_const,
    [B.dump, 'pure.bytecode'],
    # [ B.bitslice, 64, size ],
    # [ B.unroll_cycle_const_range, 'setupW' ],
    # [ B.unroll_cycle_const_range_partly, 'setupW', 16 ],
    # [ B.unroll_cycle_const_range_partly, 'main', 40 ],

    # [ B.unroll_cycle_const_range_partly, 'main', 2 ],

    # [ B.unroll_cycle_const_range, 'main' ],

    # 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],
)
#       [ 0x657069786f697080, 0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000038 ],
#       [ 0xf342aae82952db35, 0xb8e02c30115e3dee, 0xd3d80fdfdadacab3, 0x36f0ba51ac54e297, 0x291fa1d6b201d69a, 0x2bd77e2535280f17, 0xa54fa1e527abc6e2, 0xeddba79ad3be11c0 ]],
#     B.my_exit,
# )

d = B.thread_code( code,
    [ B.dump, 'test.bytecode' ],
    B.replace_state_with_const,
    [ B.dump, 'pure.bytecode' ],
    # [ B.bitslice, 64, size ],
    # [ B.unroll_cycle_const_range, 'setupW' ],
    # [ B.unroll_cycle_const_range_partly, 'setupW', 16 ],
    # [ B.unroll_cycle_const_range_partly, 'main', 40 ],

    [ B.unroll_cycle_const_range, 'main' ],
    [ B.unpack_const_subscripts, 'k' ],
    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)
B.global_vars['interleave'] = interleave
B.global_vars['reverse_num'] =  reverse_num

B.global_vars['vectorize'] = 1

d = B.thread_code( B.get_code_full(algo_file, **args),
    B.replace_state_with_const,
    [ B.dump, 'pure.bytecode' ],
    # [ B.bitslice, 64, size ],
    # [ B.unroll_cycle_const_range, 'setupW' ],
    # [ B.unroll_cycle_const_range_partly, 'setupW', 16 ],
    # [ B.unroll_cycle_const_range_partly, 'main', 40 ],

    # [ B.unroll_cycle_const_range, 'main' ],
    # [ 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)
Beispiel #5
0
import util_ui as U
import bytecode_main as B
from util_main import *

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],
Beispiel #6
0
interleave = 1

# B.global_vars['batch_size'] = 20
# B.global_vars['batch_size'] = 16
B.global_vars['batch_size'] = 1

B.global_vars['interleave'] = interleave

# skein512 loading

skein = B.thread_code(
    B.get_code_full(algo_file, **args),
    B.replace_state_with_const,
    [B.replace_length_with_const, 80],
    [B.dump, 'skein1.bytecode'],
    [B.compute_const_expressions, size],
    # [ B.dump, 'skein2.bytecode' ],
    B.drop_print,
    # [ B.dump, 'skein.bytecode' ]
)

# border of var sizes

border = B.evaluate('''
inputs = [input() for i in range(8)]
inputs = map(swap_to_be, inputs)
map(print_var, inputs)
Var.setup(4, 'le')
outputs = []
for v in inputs:
    outputs.append(high(v))
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])
reverse_num = 0

B.global_vars['interleave'] = interleave
B.global_vars['reverse_num'] =  reverse_num

B.global_vars['vectorize'] = 1

d = B.thread_code( code,
    B.replace_state_with_const,
    [ B.dump, 'pure.bytecode' ],
    # [ B.bitslice, 64, size ],

    # 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 ]
if B.global_vars['bs']:
    code = B.thread_code(
        code,
        B.replace_state_with_const,

        # B.drop_print,

        # [ B.unroll_cycle_const_range, 'setupW' ],
        # [ B.unroll_cycle_const_range, 'main' ],
        # [ B.unpack_const_subscripts, 'k' ],
        # B.remove_assignments,
        # [ B.compute_const_expressions, size ],
        # B.drop_arrays,
        # [ B.compute_const_expressions, size ],
        [B.bitslice],
        B.drop_unused,

        # [ B.dump, "int.bytecode" ],
        # [ B.interpret,
        #   [ 0x61626364, 0x00000000, 0x71776572, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000060 ],
        #   [ 0x0166844e, 0x6a0f4428, 0xf75ed9da, 0x4fb2c503, 0x0d4e393c, 0xd699502a, 0xf618aa33, 0x43c9f865 ]],
        # B.my_exit,

        # [ B.interpret,
        #   [ 0x65706978, 0x6f697080, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000038 ],
        #   [ 0x71c3f65d, 0x17745f05, 0x235570f1, 0x799d75e6, 0x9795d469, 0xd9fcb83e, 0x326f82f1, 0xafa80dea ]],
        # B.my_exit,

        # [ B.dump, 'post.bytecode' ],
    )
Beispiel #10
0
U.setup_vars(vs)

# Optimizations and code generation

# http://en.wikipedia.org/wiki/SHA2
# sha384 is sha512 with other initial values and 2 outputs dropped

state = [
    0xcbbb9d5dc1059ed8, 0x629a292a367cd507, 0x9159015a3070dd17,
    0x152fecd8f70e5939, 0x67332667ffc00b31, 0x8eb44a8768581511,
    0xdb0c2e0d64f98fa7, 0x47b5481dbefa4fa4
]

code = B.thread_code(
    B.get_code_full(algo_file, **args),
    [B.override_state, state],
    # %% there should 3 such filter, where is the last? typo?
    B.drop_last_output,
    B.drop_last_output)

interleave = 1

B.global_vars['batch_size'] = 20

reverse_num = 5

B.global_vars['interleave'] = interleave
B.global_vars['reverse_num'] = reverse_num

B.global_vars['vectorize'] = 1

d = B.thread_code(
Beispiel #11
0
vs = {
    'fmt_struct_name': 'raw1_LM',
    'format_name': 'LM',
    'algo_name': 'LM',
    'tag': '$LM$',
    'plaintext_length': '7',
    'binary_form_size': '8',
    'tests': tests
}

U.setup_vars(vs)


# Optimizations and code generation

code = B.get_code_full(algo_file, **args)

interleave = 1

B.global_vars['batch_size'] = 1

B.global_vars['interleave'] = interleave

# B.global_vars['vectorize'] = 1

d = B.thread_code( code,
    B.replace_state_with_const,
    [ B.dump, 'pure.bytecode' ],
    [ O.gen, c_code, args, B.global_vars ]
)