def test_inv_shift_rows():
    ''' shift rows on state array sa to return new state array '''
    expected = [[newBV(0xbe), newBV(0x83), newBV(0x2c), newBV(0xc8)], \
                [newBV(0xd4), newBV(0x3b), newBV(0x86), newBV(0xc0)], \
                [newBV(0x0a), newBV(0xe1), newBV(0xd4), newBV(0x4d)], \
                [newBV(0xda), newBV(0x64), newBV(0xf2), newBV(0xfe)]]
    stateArr = [[newBV(0xbe), newBV(0x3b), newBV(0xd4), newBV(0xfe)], \
                [newBV(0xd4), newBV(0xe1), newBV(0xf2), newBV(0xc8)], \
                [newBV(0x0a), newBV(0x64), newBV(0x2c), newBV(0xc0)], \
                [newBV(0xda), newBV(0x83), newBV(0x86), newBV(0x4d)]]
    actual = AES.inv_shift_rows(stateArr)
    assert actual == expected

    expected = [[newBV(0x87), newBV(0xec), newBV(0x4a), newBV(0x8c)], \
                [newBV(0xf2), newBV(0x6e), newBV(0xc3), newBV(0xd8)], \
                [newBV(0x4d), newBV(0x4c), newBV(0x46), newBV(0x95)], \
                [newBV(0x97), newBV(0x90), newBV(0xe7), newBV(0xa6)]]
    stateArr = [[newBV(0x87), newBV(0x6e), newBV(0x46), newBV(0xa6)], \
                [newBV(0xf2), newBV(0x4c), newBV(0xe7), newBV(0x8c)], \
                [newBV(0x4d), newBV(0x90), newBV(0x4a), newBV(0xd8)], \
                [newBV(0x97), newBV(0xec), newBV(0xc3), newBV(0x95)]]
    actual = AES.inv_shift_rows(stateArr)
    assert actual == expected

    expected = [[newBV(0xe9), newBV(0x09), newBV(0x89), newBV(0x72)], \
                [newBV(0xcb), newBV(0x31), newBV(0x07), newBV(0x5f)], \
                [newBV(0x3d), newBV(0x32), newBV(0x7d), newBV(0x94)], \
                [newBV(0xaf), newBV(0x2e), newBV(0x2c), newBV(0xb5)]]
    stateArr = [[newBV(0xe9), newBV(0x31), newBV(0x7d), newBV(0xb5)], \
                [newBV(0xcb), newBV(0x32), newBV(0x2c), newBV(0x72)], \
                [newBV(0x3d), newBV(0x2e), newBV(0x89), newBV(0x5f)], \
                [newBV(0xaf), newBV(0x09), newBV(0x07), newBV(0x94)]]
    actual = AES.inv_shift_rows(stateArr)
    assert actual == expected
def test_inv_shift_rows():
    ''' shift rows on state array sa to return new state array '''
    expected = [[newBV(0xbe), newBV(0x83), newBV(0x2c), newBV(0xc8)], \
                [newBV(0xd4), newBV(0x3b), newBV(0x86), newBV(0xc0)], \
                [newBV(0x0a), newBV(0xe1), newBV(0xd4), newBV(0x4d)], \
                [newBV(0xda), newBV(0x64), newBV(0xf2), newBV(0xfe)]]
    stateArr = [[newBV(0xbe), newBV(0x3b), newBV(0xd4), newBV(0xfe)], \
                [newBV(0xd4), newBV(0xe1), newBV(0xf2), newBV(0xc8)], \
                [newBV(0x0a), newBV(0x64), newBV(0x2c), newBV(0xc0)], \
                [newBV(0xda), newBV(0x83), newBV(0x86), newBV(0x4d)]]
    actual = AES.inv_shift_rows(stateArr)
    assert actual == expected

    expected = [[newBV(0x87), newBV(0xec), newBV(0x4a), newBV(0x8c)], \
                [newBV(0xf2), newBV(0x6e), newBV(0xc3), newBV(0xd8)], \
                [newBV(0x4d), newBV(0x4c), newBV(0x46), newBV(0x95)], \
                [newBV(0x97), newBV(0x90), newBV(0xe7), newBV(0xa6)]]
    stateArr = [[newBV(0x87), newBV(0x6e), newBV(0x46), newBV(0xa6)], \
                [newBV(0xf2), newBV(0x4c), newBV(0xe7), newBV(0x8c)], \
                [newBV(0x4d), newBV(0x90), newBV(0x4a), newBV(0xd8)], \
                [newBV(0x97), newBV(0xec), newBV(0xc3), newBV(0x95)]]
    actual = AES.inv_shift_rows(stateArr)
    assert actual == expected

    expected = [[newBV(0xe9), newBV(0x09), newBV(0x89), newBV(0x72)], \
                [newBV(0xcb), newBV(0x31), newBV(0x07), newBV(0x5f)], \
                [newBV(0x3d), newBV(0x32), newBV(0x7d), newBV(0x94)], \
                [newBV(0xaf), newBV(0x2e), newBV(0x2c), newBV(0xb5)]]
    stateArr = [[newBV(0xe9), newBV(0x31), newBV(0x7d), newBV(0xb5)], \
                [newBV(0xcb), newBV(0x32), newBV(0x2c), newBV(0x72)], \
                [newBV(0x3d), newBV(0x2e), newBV(0x89), newBV(0x5f)], \
                [newBV(0xaf), newBV(0x09), newBV(0x07), newBV(0x94)]]
    actual = AES.inv_shift_rows(stateArr)
    assert actual == expected
Exemple #3
0
def inv_state(d0, d1):
    d1 = aes.xor_bytes(d0, d1)
    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
Exemple #4
0
def inv_diff(d1):
    d1 = aes.bytes2matrix(d1)
    aes.inv_mix_columns(d1)
    aes.inv_shift_rows(d1)
    d1 = aes.matrix2bytes(d1)
    return d1
Exemple #5
0
 def test_inv_shift_rows_3(self):
     sa = aes.init_state_array(
         aes.key_bv('2d6d7ef03f33e334093602dd5bfb12c7'))
     self.assertEqual(aes.state_str(aes.inv_shift_rows(sa)),\
                      '2dfb02343f6d12dd09337ec75b36e3f0',\
         "Test shift rows from FIPS-197 C.1 round[4]")
Exemple #6
0
 def test_inv_shift_rows_2(self):
     sa = aes.init_state_array(
         aes.key_bv('3bd92268fc74fb735767cbe0c0590e2d'))
     self.assertEqual(aes.state_str(aes.inv_shift_rows(sa)),\
                      '3b59cb73fcd90ee05774222dc067fb68',\
         "Test shift rows from FIPS-197 C.1 round[3]")
Exemple #7
0
 def test_inv_shift_rows_1(self):
     sa = aes.init_state_array(
         aes.key_bv('a7be1a6997ad739bd8c9ca451f618b61'))
     self.assertEqual(aes.state_str(aes.inv_shift_rows(sa)),\
                      'a761ca9b97be8b45d8ad1a611fc97369',\
         "Test shift rows from FIPS-197 C.1 round[2]")
Exemple #8
0
 def test_inv_shift_rows_0(self):
     sa = aes.init_state_array(
         aes.key_bv('6353e08c0960e104cd70b751bacad0e7'))
     self.assertEqual(aes.state_str(aes.inv_shift_rows(sa)),\
                      '63cab7040953d051cd60e0e7ba70e18c',\
         "Test shift rows from FIPS-197 C.1 round[1]")
Exemple #9
0
 def test_inv_shift_rows_3(self):
     sa=aes.init_state_array(aes.key_bv('2d6d7ef03f33e334093602dd5bfb12c7'))
     self.assertEqual(aes.state_str(aes.inv_shift_rows(sa)),\
                      '2dfb02343f6d12dd09337ec75b36e3f0',\
         "Test shift rows from FIPS-197 C.1 round[4]")
Exemple #10
0
 def test_inv_shift_rows_2(self):
     sa=aes.init_state_array(aes.key_bv('3bd92268fc74fb735767cbe0c0590e2d'))
     self.assertEqual(aes.state_str(aes.inv_shift_rows(sa)),\
                      '3b59cb73fcd90ee05774222dc067fb68',\
         "Test shift rows from FIPS-197 C.1 round[3]")
Exemple #11
0
 def test_inv_shift_rows_1(self):
     sa=aes.init_state_array(aes.key_bv('a7be1a6997ad739bd8c9ca451f618b61'))
     self.assertEqual(aes.state_str(aes.inv_shift_rows(sa)),\
                      'a761ca9b97be8b45d8ad1a611fc97369',\
         "Test shift rows from FIPS-197 C.1 round[2]")
Exemple #12
0
 def test_inv_shift_rows_0(self):
     sa=aes.init_state_array(aes.key_bv('6353e08c0960e104cd70b751bacad0e7'))
     self.assertEqual(aes.state_str(aes.inv_shift_rows(sa)),\
                      '63cab7040953d051cd60e0e7ba70e18c',\
         "Test shift rows from FIPS-197 C.1 round[1]")