示例#1
0
def show_postcondition():
    p = list(range(0xB + 1))
    q = [int(x, 16) for x in g_perm.split(' ')]
    b = '''s7 ^4+sB+s5 ^3+s8+sA" s6+s3 s2+s1' s0'''
    l = '''s6 ^5+sB+s0 ^4+s9+s2" s7+s8 sA+s4' s1'''
    for i in range(2, 8):
        print 'i=%X pre' % i, E.apply_s_permutation(b, p)
        if i < 7:
            print 'i=%X pst' % i, E.apply_s_permutation(l, p)
        else:
            k = ' '.join(['s%X' % j for j in range(0xB + 1)])
            print k, '\n' + E.apply_s_permutation(k, p)
        p = P.composition(p, q)
def show_postcondition():
    p = list(range(0xD + 1))
    q = [int(x, 16) for x in g_perm_bwl.split(' ')]
    b = '''s7 sC+s9+s5 s8+sB+s1" s3+sA s2+s0' s4 == s6 sD'''
    l = '''sD s7+sA+s4 s8+s5+s1" s6+s2 s9+s3' s0 == sC sB'''
    l9 = '''sD sA+s4+s2 s8+s5+sB" s6+s1 s9+s7' sC'''
    print 'Broadwell'
    for i in range(2, 10):
        print 'i=%X pre' % i, E.apply_s_permutation(b, p)
        if i == 9:
            print E.apply_s_permutation(l9, p)
        print 'i=%X pst' % i, E.apply_s_permutation(l, p)
        p = P.composition(p, q)
    p = list(range(0xD + 1))
    b = '''sD sC+s9+sB sA+s4+s0 s7+s5+s2" s1| s3|' == s6 s8'''
    l = '''s3 sD+s8+s7 s9+s5+s6 s0+sA+sC" s2| sB|' == s1 s4'''
    l9 = '''sD s9 s0+sA s2+s7+s1 sB+s3|" s6|' == s4=v[10]'''
    q = [int(x, 16) for x in g_perm_zen.split(' ')]
    print '\nZen'
    for i in range(2, 10):
        print 'i=%X pre' % i, E.apply_s_permutation(b, p)
        if i == 9:
            print E.apply_s_permutation(l9, p)
        print 'i=%X pst' % i, E.apply_s_permutation(l, p)
        p = P.composition(p, q)
def show_postcondition():
    p = list(range(0xC + 1))
    q = [int(x, 16) for x in g_perm.split(' ')]
    assert len(p) == len(q)
    b = '''sA sB+s2+s8 s7+sC+s0' s4+s3 s1+s5"'''
    l = '''sB s9+sC+s4 s2+s8+s5' s0+s7 s3+s6"'''
    for i in range(3, 11):
        print 'i=%X pre' % i, A.apply_s_permutation(b, p)
        if i == 10:
            break
        pst = A.apply_s_permutation(l, p)
        print 'i=%X pst' % i, pst
        pst = P.replace_symbolic_names_wr(pst, g_var_map).replace('%', '')
        print 'pst again', pst
        p = P.composition(p, q)
def chew_code(src, amd, i, aligned, p):
    if not isinstance(src, list):
        src = P.cutoff_comments(src)

    if i:
        rr = ['# mul_add %s' % i]
        if p:
            e = '# '
            for x in range(len(p)):
                e += 's%X->W%X ' % (x, p[x])
            rr.append(e)
    else:
        rr = []

    for j in src:
        k = evaluate_row(j, i, amd, aligned)
        if k and (k != [None]) and (k != ['']):
            rr += k

    if p:
        re = []
        for x in rr:
            if x[0] == '#':
                re.append(x)
            else:
                re.append(E.apply_s_permutation(x, p))
        return re
    return rr
def chew_code(src, i, aligned, p):
    if not isinstance(src, list):
        src = P.cutoff_comments(src)

    if i:
        rr = ['# mul_add %s' % i]
    else:
        rr = []

    for j in src:
        for k in evaluate_row(j, i, aligned):
            if k:
                rr.append(k)
                if k == 'jmp tail':
                    break

    if not p:
        return rr
    re = []
    for x in rr:
        if x[0] == '#':
            re.append(x)
        else:
            re.append(E.apply_s_permutation(x, p))
    return re
def mul_code(i, jj_arg, p, align):
    if i:
        rr = ['# mul_add %s' % i]
    else:
        rr = []

    if i == 5:
        jj = jj_arg[:-1] + P.cutoff_comments(g_tail)
    else:
        jj = jj_arg

    for j in jj:
        m = g_patt.match(j)
        if m:
            u, v = m.group(1), m.group(2)
            if v == 'i+1':
                k = extract_v(i + 1, u, align)
            else:
                k = extract_v(int(v), u, align)
            if k:
                rr.append(k)
            continue
        rr.append(j)

    for y in range(len(rr)):
        src = E.apply_s_permutation(rr[y], p)
        for x in range(1, 9):
            ' replace i+x with 8*(i+x) '
            src = src.replace('i+%s(' % x, '%s(' % (8 * (i + x)))
        ' replace i with 8*i '
        src = src.replace('i(', '%s(' % (8 * i))
        rr[y] = src.rstrip()

    return rr
def muladd_code(i, jj, p, align):
    if i:
        rr = ['# mul_add %s' % i]
    else:
        rr = []

    for j in jj:
        k = chew_line(i, j, align)
        if k:
            rr.append(k)

    return [E.apply_s_permutation(j, p) for j in rr]
示例#8
0
def mul_code(i, jj, p):
    if i:
        rr = ['# mul_add %s' % i]
    else:
        rr = []

    for j in jj:
        k = evaluate_row(i, j)
        if k:
            rr.append(k)

    return [E.apply_s_permutation(x, p) for x in rr]
def mul1_code(i, jj, p, align):
    rr = ['# mul_add %s' % i]
    for j in jj:
        if j.find(':=v[i+1]') != -1:
            j = extract_v(i + 1, j[:2], align)
            if not j:
                continue
        rr.append(j)

    #print post_condition(i, ' pre', '''s8" s0+s5 s9+s6' s3 s1 s2 s4''', p)

    # apply permutation p, replace i(rp)
    for y in range(len(rr)):
        src = E.apply_s_permutation(rr[y], p)
        for x in range(1, 9):
            ' replace i+x with 8*(i+x) '
            src = src.replace('i+%s(' % x, '%s(' % (8 * (i + x)))
        ' replace i with 8*i '
        src = src.replace('i(', '%s(' % (8 * i))
        rr[y] = src.rstrip()

    #print post_condition(i, 'post', '''s2' s8+s4 s0+s7" s6 s3 s1 sB''', p)

    return rr