Ejemplo n.º 1
0
 def test_mul(self):
     '''Tests the __mul method
     test cases taken from FIPS 197 section 4.2.1'''
     self.assertEqual(AES._AES__mul(0x57, 0x13), 0xfe)  # @UndefinedVariable
     self.assertEqual(AES._AES__mul(0x13, 0x57), 0xfe)  # @UndefinedVariable
     self.assertEqual(AES._AES__mul(0x57, 0x83), 0xc1)  # @UndefinedVariable
     self.assertEqual(AES._AES__mul(0x83, 0x57), 0xc1)  # @UndefinedVariable
Ejemplo n.º 2
0
    def test_cipher_128(self):
        '''tests cipher with a 128-bit key
        Test taken from FIPS 197 section C.1'''
        plaintext = b'\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff'
        key = b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'
        expected_cipher = b'\x69\xc4\xe0\xd8\x6a\x7b\x04\x30\xd8\xcd\xb7\x80\x70\xb4\xc5\x5a'
        aes = AES(key)

        actual_cipher = bytearray(len(expected_cipher))
        aes._AES__cipher(plaintext, actual_cipher)

        self.assertEqual(expected_cipher, actual_cipher)
Ejemplo n.º 3
0
    def test_cipher_256(self):
        '''tests cipher with a 256-bit key
        Test taken from FIPS 197 section C.3'''
        plaintext = b'\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff'
        key = b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'
        expected_cipher = b'\x8e\xa2\xb7\xca\x51\x67\x45\xbf\xea\xfc\x49\x90\x4b\x49\x60\x89'
        aes = AES(key)

        actual_cipher = bytearray(len(expected_cipher))
        aes._AES__cipher(plaintext, actual_cipher)

        self.assertEqual(expected_cipher, actual_cipher)
Ejemplo n.º 4
0
    def test_cipher_192(self):
        '''tests cipher with a 192-bit key
        Test taken from FIPS 197 section C.2'''
        plaintext = b'\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff'
        key = b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17'
        expected_cipher = b'\xdd\xa9\x7c\xa4\x86\x4c\xdf\xe0\x6e\xaf\x70\xa0\xec\x0d\x71\x91'
        aes = AES(key)

        actual_cipher = bytearray(len(expected_cipher))
        aes._AES__cipher(plaintext, actual_cipher)

        self.assertEqual(expected_cipher, actual_cipher)