def test_mix_columns():
    ''' Mix columns on state array sa to return new state array '''
    stateArr = [[newBV(0xac), newBV(0xc1), newBV(0xd6), newBV(0xb8)], \
                [newBV(0xef), newBV(0xb5), newBV(0x5a), newBV(0x7b)], \
                [newBV(0x13), newBV(0x23), newBV(0xcf), newBV(0xdf)], \
                [newBV(0x45), newBV(0x73), newBV(0x11), newBV(0xb5)]]
    expected = [[newBV(0x75), newBV(0xec), newBV(0x09), newBV(0x93)], \
                [newBV(0x20), newBV(0x0b), newBV(0x63), newBV(0x33)], \
                [newBV(0x53), newBV(0xc0), newBV(0xcf), newBV(0x7c)], \
                [newBV(0xbb), newBV(0x25), newBV(0xd0), newBV(0xdc)]]
    actual = AES.mix_columns(stateArr)
    assert expected == actual

    stateArr = [[newBV(0x52), newBV(0xa4), newBV(0xc8), newBV(0x94)], \
                [newBV(0x85), newBV(0x11), newBV(0x6a), newBV(0x28)], \
                [newBV(0xe3), newBV(0xcf), newBV(0x2f), newBV(0xd7)], \
                [newBV(0xf6), newBV(0x50), newBV(0x5e), newBV(0x07)]]
    expected = [[newBV(0x0f), newBV(0xd6), newBV(0xda), newBV(0xa9)], \
                [newBV(0x60), newBV(0x31), newBV(0x38), newBV(0xbf)], \
                [newBV(0x6f), newBV(0xc0), newBV(0x10), newBV(0x6b)], \
                [newBV(0x5e), newBV(0xb3), newBV(0x13), newBV(0x01)]]
    actual = AES.mix_columns(stateArr)
    assert expected == actual

    stateArr = [[newBV(0xe1), newBV(0xfb), newBV(0x96), newBV(0x7c)], \
                [newBV(0xe8), newBV(0xc8), newBV(0xae), newBV(0x9b)], \
                [newBV(0x35), newBV(0x6c), newBV(0xd2), newBV(0xba)], \
                [newBV(0x97), newBV(0x4f), newBV(0xfb), newBV(0x53)]]
    expected = [[newBV(0x25), newBV(0xd1), newBV(0xa9), newBV(0xad)], \
                [newBV(0xbd), newBV(0x11), newBV(0xd1), newBV(0x68)], \
                [newBV(0xb6), newBV(0x3a), newBV(0x33), newBV(0x8e)], \
                [newBV(0x4c), newBV(0x4c), newBV(0xc0), newBV(0xb0)]]
    actual = AES.mix_columns(stateArr)
    assert expected == actual
def test_mix_columns():
    ''' Mix columns on state array sa to return new state array '''
    stateArr = [[newBV(0xac), newBV(0xc1), newBV(0xd6), newBV(0xb8)], \
                [newBV(0xef), newBV(0xb5), newBV(0x5a), newBV(0x7b)], \
                [newBV(0x13), newBV(0x23), newBV(0xcf), newBV(0xdf)], \
                [newBV(0x45), newBV(0x73), newBV(0x11), newBV(0xb5)]]
    expected = [[newBV(0x75), newBV(0xec), newBV(0x09), newBV(0x93)], \
                [newBV(0x20), newBV(0x0b), newBV(0x63), newBV(0x33)], \
                [newBV(0x53), newBV(0xc0), newBV(0xcf), newBV(0x7c)], \
                [newBV(0xbb), newBV(0x25), newBV(0xd0), newBV(0xdc)]]
    actual = AES.mix_columns(stateArr)
    assert expected == actual

    stateArr = [[newBV(0x52), newBV(0xa4), newBV(0xc8), newBV(0x94)], \
                [newBV(0x85), newBV(0x11), newBV(0x6a), newBV(0x28)], \
                [newBV(0xe3), newBV(0xcf), newBV(0x2f), newBV(0xd7)], \
                [newBV(0xf6), newBV(0x50), newBV(0x5e), newBV(0x07)]]
    expected = [[newBV(0x0f), newBV(0xd6), newBV(0xda), newBV(0xa9)], \
                [newBV(0x60), newBV(0x31), newBV(0x38), newBV(0xbf)], \
                [newBV(0x6f), newBV(0xc0), newBV(0x10), newBV(0x6b)], \
                [newBV(0x5e), newBV(0xb3), newBV(0x13), newBV(0x01)]]
    actual = AES.mix_columns(stateArr)
    assert expected == actual
    
    stateArr = [[newBV(0xe1), newBV(0xfb), newBV(0x96), newBV(0x7c)], \
                [newBV(0xe8), newBV(0xc8), newBV(0xae), newBV(0x9b)], \
                [newBV(0x35), newBV(0x6c), newBV(0xd2), newBV(0xba)], \
                [newBV(0x97), newBV(0x4f), newBV(0xfb), newBV(0x53)]]
    expected = [[newBV(0x25), newBV(0xd1), newBV(0xa9), newBV(0xad)], \
                [newBV(0xbd), newBV(0x11), newBV(0xd1), newBV(0x68)], \
                [newBV(0xb6), newBV(0x3a), newBV(0x33), newBV(0x8e)], \
                [newBV(0x4c), newBV(0x4c), newBV(0xc0), newBV(0xb0)]]
    actual = AES.mix_columns(stateArr)
    assert expected == actual
Exemple #3
0
def test_mix_columns():
    """
    Test MixColumns.
    """
    nb = 4
    state = [
        0xdb, 0xf2, 0x01, 0xc6, 0x13, 0x0a, 0x01, 0xc6, 0x53, 0x22, 0x01, 0xc6,
        0x45, 0x5c, 0x01, 0xc6
    ]
    state_ref = [
        0x8e, 0x9f, 0x01, 0xc6, 0x4d, 0xdc, 0x01, 0xc6, 0xa1, 0x58, 0x01, 0xc6,
        0xbc, 0x9d, 0x01, 0xc6
    ]
    aes.mix_columns(state, nb)
    assert (state == state_ref)
Exemple #4
0
    d1 = aes.bytes2matrix(d1)
    aes.inv_mix_columns(d1)
    aes.inv_shift_rows(d1)
    aes.inv_sub_bytes(d1)
    d1 = aes.matrix2bytes(d1)
    return d1


mc_table = {}
for i in range(16):
    for c in range(1, 256):
        s = bytearray(16)
        s[i] = c
        s = aes.bytes2matrix(s)
        aes.shift_rows(s)
        aes.mix_columns(s)
        s = aes.matrix2bytes(s)
        for p in range(16):
            if s[p] != 0:
                assert (p, s[p]) not in mc_table
                mc_table[(i, p, s[p])] = c

sub_table = defaultdict(list)
for i in range(256):
    d = aes.sbox[i] ^ aes.sbox[i ^ 1]
    sub_table[d].append(i)

remote = Telnet('oracle2.2020.ctfcompetition.com', 1337)


def solve_phase1():
Exemple #5
0
 def test_mix_columns_3(self):
     sa = aes.init_state_array(
         aes.key_bv('2d6d7ef03f33e334093602dd5bfb12c7'))
     self.assertEqual(aes.state_str(aes.mix_columns(sa)),\
                      '6385b79ffc538df997be478e7547d691',\
         "Test mix columns from FIPS-197 C.1 round[4]")
Exemple #6
0
 def test_mix_columns_2(self):
     sa = aes.init_state_array(
         aes.key_bv('3bd92268fc74fb735767cbe0c0590e2d'))
     self.assertEqual(aes.state_str(aes.mix_columns(sa)),\
                      '4c9c1e66f771f0762c3f868e534df256',\
         "Test mix columns from FIPS-197 C.1 round[3]")
Exemple #7
0
 def test_mix_columns_1(self):
     sa = aes.init_state_array(
         aes.key_bv('a7be1a6997ad739bd8c9ca451f618b61'))
     self.assertEqual(aes.state_str(aes.mix_columns(sa)),\
                      'ff87968431d86a51645151fa773ad009',\
         "Test mix columns from FIPS-197 C.1 round[2]")
Exemple #8
0
 def test_mix_columns_0(self):
     sa = aes.init_state_array(
         aes.key_bv('6353e08c0960e104cd70b751bacad0e7'))
     self.assertEqual(aes.state_str(aes.mix_columns(sa)),\
                      '5f72641557f5bc92f7be3b291db9f91a',\
         "Test mix columns from FIPS-197 C.1 round[1]")
Exemple #9
0
 def test_mix_columns_3(self):
     sa=aes.init_state_array(aes.key_bv('2d6d7ef03f33e334093602dd5bfb12c7'))
     self.assertEqual(aes.state_str(aes.mix_columns(sa)),\
                      '6385b79ffc538df997be478e7547d691',\
         "Test mix columns from FIPS-197 C.1 round[4]")
Exemple #10
0
 def test_mix_columns_2(self):
     sa=aes.init_state_array(aes.key_bv('3bd92268fc74fb735767cbe0c0590e2d'))
     self.assertEqual(aes.state_str(aes.mix_columns(sa)),\
                      '4c9c1e66f771f0762c3f868e534df256',\
         "Test mix columns from FIPS-197 C.1 round[3]")
Exemple #11
0
 def test_mix_columns_1(self):
     sa=aes.init_state_array(aes.key_bv('a7be1a6997ad739bd8c9ca451f618b61'))
     self.assertEqual(aes.state_str(aes.mix_columns(sa)),\
                      'ff87968431d86a51645151fa773ad009',\
         "Test mix columns from FIPS-197 C.1 round[2]")
Exemple #12
0
 def test_mix_columns_0(self):
     sa=aes.init_state_array(aes.key_bv('6353e08c0960e104cd70b751bacad0e7'))
     self.assertEqual(aes.state_str(aes.mix_columns(sa)),\
                      '5f72641557f5bc92f7be3b291db9f91a',\
         "Test mix columns from FIPS-197 C.1 round[1]")