Ejemplo n.º 1
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
Ejemplo n.º 2
0
def test_inv_mix_columns():
    ''' Inverse mix columns on state array sa to return new state array '''
    expected = [[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)]]
    stateArr = [[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.inv_mix_columns(stateArr)
    AES.print_state(expected)
    AES.print_state(actual)
    assert expected == actual

    expected = [[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)]]
    stateArr = [[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.inv_mix_columns(stateArr)
    assert expected == actual
    
    expected = [[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)]]
    stateArr = [[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.inv_mix_columns(stateArr)
    assert expected == actual
Ejemplo n.º 3
0
def test_inv_mix_columns():
    ''' Inverse mix columns on state array sa to return new state array '''
    expected = [[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)]]
    stateArr = [[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.inv_mix_columns(stateArr)
    AES.print_state(expected)
    AES.print_state(actual)
    assert expected == actual

    expected = [[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)]]
    stateArr = [[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.inv_mix_columns(stateArr)
    assert expected == actual

    expected = [[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)]]
    stateArr = [[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.inv_mix_columns(stateArr)
    assert expected == actual
Ejemplo n.º 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
Ejemplo n.º 5
0
 def test_inv_mix_columns_3(self):
     sa = aes.init_state_array(
         aes.key_bv('6385b79ffc538df997be478e7547d691'))
     self.assertEqual(aes.state_str(aes.inv_mix_columns(sa)),\
                      '2d6d7ef03f33e334093602dd5bfb12c7',\
         "Test inv mix columns from FIPS-197 C.1 round[4]")
Ejemplo n.º 6
0
 def test_inv_mix_columns_2(self):
     sa = aes.init_state_array(
         aes.key_bv('4c9c1e66f771f0762c3f868e534df256'))
     self.assertEqual(aes.state_str(aes.inv_mix_columns(sa)),\
                      '3bd92268fc74fb735767cbe0c0590e2d',\
         "Test inv mix columns from FIPS-197 C.1 round[3]")
Ejemplo n.º 7
0
 def test_inv_mix_columns_1(self):
     sa = aes.init_state_array(
         aes.key_bv('ff87968431d86a51645151fa773ad009'))
     self.assertEqual(aes.state_str(aes.inv_mix_columns(sa)),\
                      'a7be1a6997ad739bd8c9ca451f618b61',\
         "Test inv mix columns from FIPS-197 C.1 round[2]")
Ejemplo n.º 8
0
 def test_inv_mix_columns_0(self):
     sa = aes.init_state_array(
         aes.key_bv('5f72641557f5bc92f7be3b291db9f91a'))
     self.assertEqual(aes.state_str(aes.inv_mix_columns(sa)),\
                      '6353e08c0960e104cd70b751bacad0e7',\
         "Test inv mix columns from FIPS-197 C.1 round[1]")
Ejemplo n.º 9
0
 def test_inv_mix_columns_3(self):
     sa=aes.init_state_array(aes.key_bv('6385b79ffc538df997be478e7547d691'))
     self.assertEqual(aes.state_str(aes.inv_mix_columns(sa)),\
                      '2d6d7ef03f33e334093602dd5bfb12c7',\
         "Test inv mix columns from FIPS-197 C.1 round[4]")
Ejemplo n.º 10
0
 def test_inv_mix_columns_2(self):
     sa=aes.init_state_array(aes.key_bv('4c9c1e66f771f0762c3f868e534df256'))
     self.assertEqual(aes.state_str(aes.inv_mix_columns(sa)),\
                      '3bd92268fc74fb735767cbe0c0590e2d',\
         "Test inv mix columns from FIPS-197 C.1 round[3]")
Ejemplo n.º 11
0
 def test_inv_mix_columns_1(self):
     sa=aes.init_state_array(aes.key_bv('ff87968431d86a51645151fa773ad009'))
     self.assertEqual(aes.state_str(aes.inv_mix_columns(sa)),\
                      'a7be1a6997ad739bd8c9ca451f618b61',\
         "Test inv mix columns from FIPS-197 C.1 round[2]")
Ejemplo n.º 12
0
 def test_inv_mix_columns_0(self):
     sa=aes.init_state_array(aes.key_bv('5f72641557f5bc92f7be3b291db9f91a'))
     self.assertEqual(aes.state_str(aes.inv_mix_columns(sa)),\
                      '6353e08c0960e104cd70b751bacad0e7',\
         "Test inv mix columns from FIPS-197 C.1 round[1]")