Пример #1
0
def word_xor(a, b, verbose=1):
    """
    >>> word_xor([1,2,3,4],[1,2,3,4])
    [0, 0, 0, 0]

    >>> word_xor([1,2,3,4],[2,3,4,5])
    [3, 1, 7, 1]

    >>> word_xor([8,91,24,18],[73,143,43,11],verbose=0)
    [65, 212, 51, 25]

    >>> word_xor([18,91,234,88],[93,114,57,10],verbose=0)
    [79, 41, 211, 82]

    >>> word_xor([93,114,57,10],[18,91,234,88],verbose=0)
    [79, 41, 211, 82]

    """

    assert is_word(a) and is_word(b)

    r = [xor(a[0], b[0]), xor(a[1], b[1]), xor(a[2], b[2]), xor(a[3], b[3])]

    if verbose >= 1:  #tvn traces
        print 'l0: r a b'
        print 'l0: ', r, a, b

    assert is_word(r)
    return r
Пример #2
0
def SubWord(w, verbose=1):
    """
    tvn: *nested* array
    r[i] = S[w[i]]
    """

    assert is_word(w)

    r = [S[w[0]], S[w[1]], S[w[2]], S[w[3]]]

    if verbose >= 1:  #tvn traces
        print 'l0: r w'
        print 'l0: ', r, w

    assert is_word(r)
    return r
Пример #3
0
def word_xor_xor(a, b, c, verbose=1):
    r = [
        xor_xor(a[0], b[0], c[0]),
        xor_xor(a[1], b[1], c[1]),
        xor_xor(a[2], b[2], c[2]),
        xor_xor(a[3], b[3], c[3])
    ]

    assert (is_word(a) and is_word(b) and is_word(c))

    if verbose >= 1:  #tvn traces

        print 'l0: r a b c'
        print 'l0: ', r, a, b, c

    assert is_word(r)
    return r
Пример #4
0
def AddRoundKey(st, rk0, rk1, rk2, rk3, verbose=1):
    """
    *nested* array
    r[i][j] = xor(st[i][j], rk[i][j])
    """

    assert is_state(st), st
    assert (is_word(rk0) and is_word(rk1) and is_word(rk2)
            and is_word(rk3)), (rk0, rk1, rk2, rk3)

    if verbose >= 1:
        print 'l1: st rk0 rk1 rk2 rk3'
        print 'l1: ', st, rk0, rk1, rk2, rk3

    r = [[
        xor(st[0][0], rk0[0]),
        xor(st[0][1], rk0[1]),
        xor(st[0][2], rk0[2]),
        xor(st[0][3], rk0[3])
    ],
         [
             xor(st[1][0], rk1[0]),
             xor(st[1][1], rk1[1]),
             xor(st[1][2], rk1[2]),
             xor(st[1][3], rk1[3])
         ],
         [
             xor(st[2][0], rk2[0]),
             xor(st[2][1], rk2[1]),
             xor(st[2][2], rk2[2]),
             xor(st[2][3], rk2[3])
         ],
         [
             xor(st[3][0], rk3[0]),
             xor(st[3][1], rk3[1]),
             xor(st[3][2], rk3[2]),
             xor(st[3][3], rk3[3])
         ]]

    if verbose >= 1:
        print 'l0: st rk0 rk1 rk2 rk3 r'
        print 'l0: ', st, rk0, rk1, rk2, rk3, r

    assert is_state(r)

    return r
Пример #5
0
def RotWord(w, verbose=1):
    """
    #tvn: miscs array type
    r0 = w1 , r1 = w2,  r2 = w3, r3 = w0

    """
    assert is_word(w)

    r = [w[1], w[2], w[3], w[0]]

    #tvn traces
    if verbose >= 1:
        print 'l0: r w'
        print 'l0: ', r, w

    assert is_word(r)
    return r