Пример #1
0
def test_sub_bytes():
    ''' Iterate throught state array sa to perform sbox substitution 
    returning new state array. '''
    stateArr = [[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)]]
    expected = [[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.sub_bytes(stateArr)
    assert expected == actual

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

    stateArr = [[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)]]
    expected = [[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.sub_bytes(stateArr)
    assert expected == actual
Пример #2
0
def test_sub_bytes():
    ''' Iterate throught state array sa to perform sbox substitution 
    returning new state array. '''
    stateArr = [[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)]]
    expected = [[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.sub_bytes(stateArr)
    assert expected == actual

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

    stateArr = [[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)]]
    expected = [[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.sub_bytes(stateArr)
    assert expected == actual
Пример #3
0
def test_sub_bytes():
    """
    Test SubBytes.
    """
    offset = 16
    state = [0] * 16
    state_ref = [0x63] * 16
    aes.sub_bytes(state, offset)
    assert (state == state_ref)
Пример #4
0
 def test_sub_bytes_3(self):
     sa = aes.init_state_array(
         aes.key_bv('fa636a2825b339c940668a3157244d17'))
     self.assertEqual(aes.state_str(aes.sub_bytes(sa)),\
                      '2dfb02343f6d12dd09337ec75b36e3f0',\
                      "testing sub_bytes from FIPS-197 C.1 round[4]")
Пример #5
0
 def test_sub_bytes_2(self):
     sa = aes.init_state_array(
         aes.key_bv('4915598f55e5d7a0daca94fa1f0a63f7'))
     self.assertEqual(aes.state_str(aes.sub_bytes(sa)),\
                      '3b59cb73fcd90ee05774222dc067fb68',\
                      "testing sub_bytes from FIPS-197 C.1 round[3]")
Пример #6
0
 def test_sub_bytes_1(self):
     sa = aes.init_state_array(
         aes.key_bv('89d810e8855ace682d1843d8cb128fe4'))
     self.assertEqual(aes.state_str(aes.sub_bytes(sa)),\
                      'a761ca9b97be8b45d8ad1a611fc97369',\
                      "testing sub_bytes from FIPS-197 C.1 round[2]")
Пример #7
0
 def test_sub_bytes_0(self):
     sa = aes.init_state_array(
         aes.key_bv('00102030405060708090a0b0c0d0e0f0'))
     self.assertEqual(aes.state_str(aes.sub_bytes(sa)),\
                      '63cab7040953d051cd60e0e7ba70e18c',\
                      "testing sub_bytes from FIPS-197 C.1 round[1]")
Пример #8
0
 def test_sub_bytes_3(self):
     sa=aes.init_state_array(aes.key_bv('fa636a2825b339c940668a3157244d17'))
     self.assertEqual(aes.state_str(aes.sub_bytes(sa)),\
                      '2dfb02343f6d12dd09337ec75b36e3f0',\
                      "testing sub_bytes from FIPS-197 C.1 round[4]")
Пример #9
0
 def test_sub_bytes_2(self):
     sa=aes.init_state_array(aes.key_bv('4915598f55e5d7a0daca94fa1f0a63f7'))
     self.assertEqual(aes.state_str(aes.sub_bytes(sa)),\
                      '3b59cb73fcd90ee05774222dc067fb68',\
                      "testing sub_bytes from FIPS-197 C.1 round[3]")
Пример #10
0
 def test_sub_bytes_1(self):
     sa=aes.init_state_array(aes.key_bv('89d810e8855ace682d1843d8cb128fe4'))
     self.assertEqual(aes.state_str(aes.sub_bytes(sa)),\
                      'a761ca9b97be8b45d8ad1a611fc97369',\
                      "testing sub_bytes from FIPS-197 C.1 round[2]")
Пример #11
0
 def test_sub_bytes_0(self):
     sa=aes.init_state_array(aes.key_bv('00102030405060708090a0b0c0d0e0f0'))
     self.assertEqual(aes.state_str(aes.sub_bytes(sa)),\
                      '63cab7040953d051cd60e0e7ba70e18c',\
                      "testing sub_bytes from FIPS-197 C.1 round[1]")