def test_inv_sub_bytes(): ''' Iterate throught state array sa to perform inv-sbox substitution returning new state array. ''' expected = [[newBV(0xaa), newBV(0x8f), newBV(0x5f), newBV(0x03)], \ [newBV(0x61), newBV(0xdd), newBV(0xe3), newBV(0xef)], \ [newBV(0x82), newBV(0xd2), newBV(0x4a), newBV(0xd2)], \ [newBV(0x68), newBV(0x32), newBV(0x46), newBV(0x9a)]] stateArr = [[newBV(0xac), newBV(0x73), newBV(0xcf), newBV(0x7b)], \ [newBV(0xef), newBV(0xc1), newBV(0x11), newBV(0xdf)], \ [newBV(0x13), newBV(0xb5), newBV(0xd6), newBV(0xb5)], \ [newBV(0x45), newBV(0x23), newBV(0x5a), newBV(0xb8)]] actual = AES.inv_sub_bytes(stateArr) assert expected == actual expected = [[newBV(0x48), newBV(0x67), newBV(0x4d), newBV(0xd6)], \ [newBV(0x6c), newBV(0x1d), newBV(0xe3), newBV(0x5f)], \ [newBV(0x4e), newBV(0x9d), newBV(0xb1), newBV(0x58)], \ [newBV(0xee), newBV(0x0d), newBV(0x38), newBV(0xe7)]] stateArr = [[newBV(0x52), newBV(0x85), newBV(0xe3), newBV(0xf6)], \ [newBV(0x50), newBV(0xa4), newBV(0x11), newBV(0xcf)], \ [newBV(0x2f), newBV(0x5e), newBV(0xc8), newBV(0x6a)], \ [newBV(0x28), newBV(0xd7), newBV(0x07), newBV(0x94)]] actual = AES.inv_sub_bytes(stateArr) assert expected == actual expected = [[newBV(0xe0), newBV(0xc8), newBV(0xd9), newBV(0x85)], \ [newBV(0x92), newBV(0x63), newBV(0xb1), newBV(0xb8)], \ [newBV(0x7f), newBV(0x63), newBV(0x35), newBV(0xbe)], \ [newBV(0xe8), newBV(0xc0), newBV(0x50), newBV(0x01)]] stateArr = [[newBV(0xe1), newBV(0xe8), newBV(0x35), newBV(0x97)], \ [newBV(0x4f), newBV(0xfb), newBV(0xc8), newBV(0x6c)], \ [newBV(0xd2), newBV(0xfb), newBV(0x96), newBV(0xae)], \ [newBV(0x9b), newBV(0xba), newBV(0x53), newBV(0x7c)]] actual = AES.inv_sub_bytes(stateArr) assert expected == actual
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
def test_inv_sub_bytes_3(self): sa = aes.init_state_array( aes.key_bv('2dfb02343f6d12dd09337ec75b36e3f0')) self.assertEqual(aes.state_str(aes.inv_sub_bytes(sa)),\ 'fa636a2825b339c940668a3157244d17',\ "testing inv_sub_bytes from FIPS-197 C.1 round[1]")
def test_inv_sub_bytes_2(self): sa = aes.init_state_array( aes.key_bv('3b59cb73fcd90ee05774222dc067fb68')) self.assertEqual(aes.state_str(aes.inv_sub_bytes(sa)),\ '4915598f55e5d7a0daca94fa1f0a63f7',\ "testing inv_sub_bytes from FIPS-197 C.1 round[4]")
def test_inv_sub_bytes_1(self): sa = aes.init_state_array( aes.key_bv('a761ca9b97be8b45d8ad1a611fc97369')) self.assertEqual(aes.state_str(aes.inv_sub_bytes(sa)),\ '89d810e8855ace682d1843d8cb128fe4',\ "testing inv_sub_bytes from FIPS-197 C.1 round[3]")
def test_inv_sub_bytes_0(self): sa = aes.init_state_array( aes.key_bv('63cab7040953d051cd60e0e7ba70e18c')) self.assertEqual(aes.state_str(aes.inv_sub_bytes(sa)),\ '00102030405060708090a0b0c0d0e0f0',\ "testing inv_sub_bytes from FIPS-197 C.1 round[2]")
def test_inv_sub_bytes_3(self): sa=aes.init_state_array(aes.key_bv('2dfb02343f6d12dd09337ec75b36e3f0')) self.assertEqual(aes.state_str(aes.inv_sub_bytes(sa)),\ 'fa636a2825b339c940668a3157244d17',\ "testing inv_sub_bytes from FIPS-197 C.1 round[1]")
def test_inv_sub_bytes_2(self): sa=aes.init_state_array(aes.key_bv('3b59cb73fcd90ee05774222dc067fb68')) self.assertEqual(aes.state_str(aes.inv_sub_bytes(sa)),\ '4915598f55e5d7a0daca94fa1f0a63f7',\ "testing inv_sub_bytes from FIPS-197 C.1 round[4]")
def test_inv_sub_bytes_1(self): sa=aes.init_state_array(aes.key_bv('a761ca9b97be8b45d8ad1a611fc97369')) self.assertEqual(aes.state_str(aes.inv_sub_bytes(sa)),\ '89d810e8855ace682d1843d8cb128fe4',\ "testing inv_sub_bytes from FIPS-197 C.1 round[3]")
def test_inv_sub_bytes_0(self): sa=aes.init_state_array(aes.key_bv('63cab7040953d051cd60e0e7ba70e18c')) self.assertEqual(aes.state_str(aes.inv_sub_bytes(sa)),\ '00102030405060708090a0b0c0d0e0f0',\ "testing inv_sub_bytes from FIPS-197 C.1 round[2]")