Ejemplo n.º 1
0
    def testInvCipher(self):
        inputBytes = [0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a]
        exampleCypherKeyBytes = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
        expectedResultBytes = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff]
        
        inputState = aes.createState(inputBytes)
        expectedState = aes.createState(expectedResultBytes)
        keySchedule = aes.keyExpansion(exampleCypherKeyBytes)

        result = aes.invCipher(inputState, keySchedule)
        self.assertEqual(result, expectedState)
Ejemplo n.º 2
0
    def testCipher(self):
        inputBytes = [0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d, 0x31, 0x31, 0x98, 0xa2, 0xe0, 0x37, 0x07, 0x34]
        exampleCypherKeyBytes = [0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c]
        expectedResultBytes = [0x39, 0x25, 0x84, 0x1d, 0x02, 0xdc, 0x09, 0xfb, 0xdc, 0x11, 0x85, 0x97, 0x19, 0x6a, 0x0b, 0x32]
        
        inputState = aes.createState(inputBytes)
        expectedState = aes.createState(expectedResultBytes)
        keySchedule = aes.keyExpansion(exampleCypherKeyBytes)

        result = aes.cipher(inputState, keySchedule)
        self.assertEqual(result, expectedState)
Ejemplo n.º 3
0
    def testKeyExpansion3Rounds(self):
        key = [[0x0f, 0x47, 0x0c, 0xaf],
               [0x15, 0xd9, 0xb7, 0x7f],
               [0x71, 0xe8, 0xad, 0x67],
               [0xc9, 0x59, 0xd6, 0x98]]

        rounds = 3
        expected = [[0x0f, 0x47, 0x0c, 0xaf, 0xdc, 0x9b, 0x97, 0x38, 0xd2, 0x49, 0xde, 0xe6],
                    [0x15, 0xd9, 0xb7, 0x7f, 0x90, 0x49, 0xfe, 0x81, 0xc9, 0x80, 0x7e, 0xff],
                    [0x71, 0xe8, 0xad, 0x67, 0x37, 0xdf, 0x72, 0x15, 0x6b, 0xb4, 0xc6, 0xd3],
                    [0xc9, 0x59, 0xd6, 0x98, 0xb0, 0xe9, 0x3f, 0xa7, 0xb7, 0x5e, 0x61, 0xc6]]

        returned = aes.keyExpansion(key, rounds)
        self.assertEqual(returned, expected)
Ejemplo n.º 4
0
    def testKeyExpansion2Rounds(self):
        key = [[0x0f, 0x47, 0x0c, 0xaf],
               [0x15, 0xd9, 0xb7, 0x7f],
               [0x71, 0xe8, 0xad, 0x67],
               [0xc9, 0x59, 0xd6, 0x98]]

        rounds = 2
        expected = [[0x0f, 0x47, 0x0c, 0xaf, 0xdc, 0x9b, 0x97, 0x38],
                    [0x15, 0xd9, 0xb7, 0x7f, 0x90, 0x49, 0xfe, 0x81],
                    [0x71, 0xe8, 0xad, 0x67, 0x37, 0xdf, 0x72, 0x15],
                    [0xc9, 0x59, 0xd6, 0x98, 0xb0, 0xe9, 0x3f, 0xa7]]

        returned = aes.keyExpansion(key, rounds)
        self.assertEqual(returned, expected)
Ejemplo n.º 5
0
 def testKeyScheduleLastKey(self):
     keySchedule = aes.keyExpansion(TEST_KEY_BYTES)
     lastKey = keySchedule[len(keySchedule)-1]
     self.assertEqual(lastKey, 0xb6630ca6)
Ejemplo n.º 6
0
 def testKeyScheduleException(self):
     with self.assertRaises(ValueError):
         aes.keyExpansion(TEST_KEY_BYTES[:10:])
Ejemplo n.º 7
0
 def testKeyScheduleLength(self):
     keySchedule = aes.keyExpansion(TEST_KEY_BYTES)
     self.assertEqual(len(keySchedule), 44)