def test_seal_with_test_vector_4(self):
        key = bytearray(b'\xfe\xff\xe9\x92\x86\x65\x73\x1c' +
                        b'\x6d\x6a\x8f\x94\x67\x30\x83\x08')

        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\xca\xfe\xba\xbe\xfa\xce\xdb\xad\xde\xca\xf8\x88')

        plaintext = bytearray(b'\xd9\x31\x32\x25\xf8\x84\x06\xe5'
                              b'\xa5\x59\x09\xc5\xaf\xf5\x26\x9a'
                              b'\x86\xa7\xa9\x53\x15\x34\xf7\xda'
                              b'\x2e\x4c\x30\x3d\x8a\x31\x8a\x72'
                              b'\x1c\x3c\x0c\x95\x95\x68\x09\x53'
                              b'\x2f\xcf\x0e\x24\x49\xa6\xb5\x25'
                              b'\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57'
                              b'\xba\x63\x7b\x39')

        data = bytearray(b'\xfe\xed\xfa\xce\xde\xad\xbe\xef'
                         b'\xfe\xed\xfa\xce\xde\xad\xbe\xef'
                         b'\xab\xad\xda\xd2')

        encData = aesCCM.seal(nonce, plaintext, data)

        self.assertEqual(
            bytearray(b'\x08\x93\xe9K\x91H\x80\x1a\xf0\xf74&\xab'
                      b'\xb0\x0e<\xa4\x9b\xf0\x9dy\xa2\x01\'\xa7'
                      b'\xeb\x19&\xfa\x89\x057\x87\xff\x02\xd0}q'
                      b'\x81;\x88[\x85\xe7\xf9lN\xed\xf4 \xdb'
                      b'\x12j\x04Q\xce\x13\xbdA\xba\x028\xc3&'
                      b'\xb4{4\xf7\x8fe\x9eu'
                      b'\x10\x96\xcd"'), encData)
Ejemplo n.º 2
0
    def test_open_identical_messages_8_python(self):

        aesCCM = AESCCM(self.key, "python", Rijndael(self.key, 16).encrypt, 8)

        for _ in range(2):
            decData = aesCCM.open(self.nonce, self.ciphertext_8, self.data)
            self.assertEqual(self.plaintext, decData)
    def test_seal_with_test_vector_4(self):
        key = bytearray(b'\xfe\xff\xe9\x92\x86\x65\x73\x1c' +
                        b'\x6d\x6a\x8f\x94\x67\x30\x83\x08')

        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\xca\xfe\xba\xbe\xfa\xce\xdb\xad\xde\xca\xf8\x88')

        plaintext = bytearray(b'\xd9\x31\x32\x25\xf8\x84\x06\xe5' +
                              b'\xa5\x59\x09\xc5\xaf\xf5\x26\x9a' +
                              b'\x86\xa7\xa9\x53\x15\x34\xf7\xda' +
                              b'\x2e\x4c\x30\x3d\x8a\x31\x8a\x72' +
                              b'\x1c\x3c\x0c\x95\x95\x68\x09\x53' +
                              b'\x2f\xcf\x0e\x24\x49\xa6\xb5\x25' +
                              b'\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57' +
                              b'\xba\x63\x7b\x39')

        data = bytearray(b'\xfe\xed\xfa\xce\xde\xad\xbe\xef' +
                         b'\xfe\xed\xfa\xce\xde\xad\xbe\xef' +
                         b'\xab\xad\xda\xd2')

        encData = aesGCM.seal(nonce, plaintext, data)

        self.assertEqual(
            bytearray(b'\x42\x83\x1e\xc2\x21\x77\x74\x24' +
                      b'\x4b\x72\x21\xb7\x84\xd0\xd4\x9c' +
                      b'\xe3\xaa\x21\x2f\x2c\x02\xa4\xe0' +
                      b'\x35\xc1\x7e\x23\x29\xac\xa1\x2e' +
                      b'\x21\xd5\x14\xb2\x54\x66\x93\x1c' +
                      b'\x7d\x8f\x6a\x5a\xac\x84\xaa\x05' +
                      b'\x1b\xa3\x0b\x39\x6a\x0a\xac\x97' +
                      b'\x3d\x58\xe0\x91' +
                      b'\x5b\xc9\x4f\xbc\x32\x21\xa5\xdb' +
                      b'\x94\xfa\xe9\x5a\xe7\x12\x1a\x47'), encData)
    def test_seal_with_test_vector_3(self):
        key = bytearray(b'\xfe\xff\xe9\x92\x86\x65\x73\x1c'
                        b'\x6d\x6a\x8f\x94\x67\x30\x83\x08')
        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\xca\xfe\xba\xbe\xfa\xce\xdb\xad\xde\xca\xf8\x88')

        plaintext = bytearray(b'\xd9\x31\x32\x25\xf8\x84\x06\xe5'
                              b'\xa5\x59\x09\xc5\xaf\xf5\x26\x9a'
                              b'\x86\xa7\xa9\x53\x15\x34\xf7\xda'
                              b'\x2e\x4c\x30\x3d\x8a\x31\x8a\x72'
                              b'\x1c\x3c\x0c\x95\x95\x68\x09\x53'
                              b'\x2f\xcf\x0e\x24\x49\xa6\xb5\x25'
                              b'\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57'
                              b'\xba\x63\x7b\x39\x1a\xaf\xd2\x55')

        self.assertEqual(len(plaintext), 4 * 16)

        encData = aesCCM.seal(nonce, plaintext, bytearray(0))

        self.assertEqual(
            bytearray(b"\x08\x93\xe9K\x91H\x80\x1a\xf0\xf74&"
                      b"\xab\xb0\x0e<\xa4\x9b\xf0\x9dy\xa2"
                      b"\x01\'\xa7\xeb\x19&\xfa\x89\x057\x87"
                      b"\xff\x02\xd0}q\x81;\x88[\x85\xe7\xf9"
                      b"lN\xed\xf4 \xdb\x12j\x04Q\xce\x13\xbdA"
                      b"\xba\x01\x8d\x1b\xa7\xfc\xece\x99Dg\xa7"
                      b"{\x8b&B\xde\x91,\x01."), encData)
Ejemplo n.º 5
0
    def test_seal_identical_messages_python(self):

        aesCCM = AESCCM(self.key, "python", Rijndael(self.key, 16).encrypt)

        for _ in range(2):
            encData = aesCCM.seal(self.nonce, self.plaintext, self.data)
            self.assertEqual(self.ciphertext, encData)
    def test_open_with_invalid_ciphertext(self):
        key = bytearray(b'\x01' * 16)
        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02' * 12)

        ciphertext = bytearray(b'\xff' * 15)

        self.assertIsNone(aesGCM.open(nonce, ciphertext, bytearray(0)))
    def test_open_with_invalid_nonce(self):
        key = bytearray(b'\x01' * 16)
        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02' * 11)

        ciphertext = bytearray(b'\'\x81h\x17\xe6Z)\\\xf2\x8emF\xcb\x91\x0eu'
                               b'z1:\xf6}\xa7\\@\xba\x11\xd8r\xdf#K\xd4')

        with self.assertRaises(ValueError):
            aesGCM.open(nonce, ciphertext, bytearray(0))
    def test_seal_with_invalid_nonce(self):
        key = bytearray(b'\x01' * 16)
        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02' * 11)

        plaintext = bytearray(b'text to encrypt.')
        self.assertEqual(len(plaintext), 16)

        with self.assertRaises(ValueError):
            aesGCM.seal(nonce, plaintext, bytearray(0))
    def test_open_256_small_tag(self):
        key = bytearray(b'\x01' * 32)
        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt, 8)

        nonce = bytearray(b'\x02' * 12)

        ciphertext = bytearray(b'IN\x1c\x06\xb8\x0b9SD<\xf8RL'
                               b'\xb4,=\xa2\x91\x84j1*\x0f\xeb')
        plaintext = aesCCM.open(nonce, ciphertext, bytearray(0))

        self.assertEqual(plaintext, bytearray(b'text to encrypt.'))
    def test_seal_with_invalid_nonce(self):
        key = bytearray(b'\x01' * 16)
        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02' * 11)

        plaintext = bytearray(b'text to encrypt.')
        self.assertEqual(len(plaintext), 16)

        with self.assertRaises(ValueError) as err:
            aesCCM.seal(nonce, plaintext, bytearray(0))
        self.assertEqual("Bad nonce length", str(err.exception))
    def test_open(self):
        key = bytearray(b'\x01' * 16)
        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02' * 12)

        ciphertext = bytearray(b'\'\x81h\x17\xe6Z)\\\xf2\x8emF\xcb\x91\x0eu'
                               b'z1:\xf6}\xa7\\@\xba\x11\xd8r\xdf#K\xd4')

        plaintext = aesGCM.open(nonce, ciphertext, bytearray(0))

        self.assertEqual(plaintext, bytearray(b'text to encrypt.'))
    def test_open(self):
        key = bytearray(b'\x01' * 16)
        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02' * 12)

        ciphertext = bytearray(b'%}Q.\x99\xa3\r\xae\xcbMc\xf2\x16,^\xff\xa0I'
                               b'\x8e\xf9\xc9F>\xbf\xa4\x00Y\x02p\xe3\xb8\xa2')

        plaintext = aesCCM.open(nonce, ciphertext, bytearray(0))

        self.assertEqual(plaintext, bytearray(b'text to encrypt.'))
    def test_open_with_incorrect_nonce(self):
        key = bytearray(b'\x01' * 16)
        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02' * 11 + b'\x01')

        ciphertext = bytearray(b'\'\x81h\x17\xe6Z)\\\xf2\x8emF\xcb\x91\x0eu'
                               b'z1:\xf6}\xa7\\@\xba\x11\xd8r\xdf#K\xd4')

        plaintext = aesGCM.open(nonce, ciphertext, bytearray(0))

        self.assertIsNone(plaintext)
    def test_open_small_tag(self):
        key = bytearray(b'\x01' * 16)
        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt, 8)

        nonce = bytearray(b'\x02' * 12)

        ciphertext = bytearray(b'%}Q.\x99\xa3\r\xae\xcbMc\xf2\x16,^\xff\x14'
                               b'\xb8-?\x7f\xac\x8bI')

        plaintext = aesCCM.open(nonce, ciphertext, bytearray(0))

        self.assertEqual(plaintext, bytearray(b'text to encrypt.'))
    def test_open_256(self):
        key = bytearray(b'\x01' * 32)
        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02' * 12)

        ciphertext = bytearray(b'IN\x1c\x06\xb8\x0b9SD<\xf8RL'
                               b'\xb4,=\xd6&d\xae^1\xf8\xbf'
                               b'\xfa8D\x98\xdd\x14\xb51')

        plaintext = aesCCM.open(nonce, ciphertext, bytearray(0))

        self.assertEqual(plaintext, bytearray(b'text to encrypt.'))
    def test_seal_with_test_vector_1(self):
        key = bytearray(b'\x00' * 16)
        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x00' * 12)

        plaintext = bytearray(b'')
        self.assertEqual(len(plaintext), 0)

        encData = aesCCM.seal(nonce, plaintext, bytearray(0))
        self.assertEqual(
            bytearray(b'\xb9\xf6P\xfb<9\xbb\x1b\xee\x0e)\x1d3'
                      b'\xf6\xae('), encData)
    def test_seal_with_test_vector_5(self):
        key = bytearray(32)

        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(12)
        plaintext = bytearray(0)
        data = bytearray(0)

        encData = aesCCM.seal(nonce, plaintext, data)

        self.assertEqual(
            bytearray(b'\xa8\x90&^C\xa2hU\xf2i'
                      b'\xb9?\xf4\xdd\xde\xf6'), encData)
    def test_seal_256_small_tag(self):
        key = bytearray(b'\x01' * 32)
        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt, 8)

        nonce = bytearray(b'\x02' * 12)

        plaintext = bytearray(b'text to encrypt.')
        self.assertEqual(len(plaintext), 16)

        encData = aesCCM.seal(nonce, plaintext, bytearray(0))

        self.assertEqual(
            bytearray(b'IN\x1c\x06\xb8\x0b9SD<\xf8RL'
                      b'\xb4,=\xa2\x91\x84j1*\x0f\xeb'), encData)
    def test_seal_small_tag(self):
        key = bytearray(b'\x01' * 16)
        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt, 8)

        nonce = bytearray(b'\x02' * 12)

        plaintext = bytearray(b'text to encrypt.')
        self.assertEqual(len(plaintext), 16)

        encData = aesCCM.seal(nonce, plaintext, bytearray(0))

        self.assertEqual(
            bytearray(b'%}Q.\x99\xa3\r\xae\xcbMc\xf2\x16,^\xff'
                      b'\x14\xb8-?\x7f\xac\x8bI'), encData)
    def test_seal_with_test_vector_1(self):
        key = bytearray(b'\x00' * 16)
        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x00' * 12)

        plaintext = bytearray(b'')
        self.assertEqual(len(plaintext), 0)

        encData = aesGCM.seal(nonce, plaintext, bytearray(0))

        self.assertEqual(
            bytearray(b'\x58\xe2\xfc\xce\xfa\x7e\x30\x61' +
                      b'\x36\x7f\x1d\x57\xa4\xe7\x45\x5a'), encData)
    def test_seal(self):
        key = bytearray(b'\x01' * 16)
        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02' * 12)

        plaintext = bytearray(b'text to encrypt.')
        self.assertEqual(len(plaintext), 16)

        encData = aesCCM.seal(nonce, plaintext, bytearray(0))

        self.assertEqual(
            bytearray(b'%}Q.\x99\xa3\r\xae\xcbMc\xf2\x16,^\xff'
                      b'\xa0I\x8e\xf9\xc9F>\xbf\xa4\x00Y\x02p'
                      b'\xe3\xb8\xa2'), encData)
    def test_seal_with_test_vector_2(self):
        key = bytearray(b'\x00' * 16)
        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x00' * 12)

        plaintext = bytearray(b'\x00' * 16)
        self.assertEqual(len(plaintext), 16)

        encData = aesCCM.seal(nonce, plaintext, bytearray(0))

        self.assertEqual(
            bytearray(b'n\xc7_\xb2\xe2\xb4\x87F\x1e\xdd\xcb\xb8'
                      b'\x97\x11\x92\xbaMO\xa3\xaf\x0b\xf6\xd3E'
                      b'Aq0o\xfa\xdd\x9a\xfd'), encData)
    def test_seal_with_test_vector_6(self):
        key = bytearray(32)

        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(12)
        plaintext = bytearray(16)
        data = bytearray(0)

        encData = aesCCM.seal(nonce, plaintext, data)

        self.assertEqual(
            bytearray(b'\xc1\x94@D\xc8\xe7\xaa\x95\xd2\xde\x95'
                      b'\x13\xc7\xf3\xdd\x8cK\n>^Q\xf1Q\xeb\x0f'
                      b'\xfa\xe7\xc4=\x01\x0f\xdb'), encData)
    def test_seal_256(self):
        key = bytearray(b'\x01' * 32)
        aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x02' * 12)

        plaintext = bytearray(b'text to encrypt.')
        self.assertEqual(len(plaintext), 16)

        encData = aesCCM.seal(nonce, plaintext, bytearray(0))

        self.assertEqual(
            bytearray(b'IN\x1c\x06\xb8\x0b9SD<\xf8RL'
                      b'\xb4,=\xd6&d\xae^1\xf8\xbf'
                      b'\xfa8D\x98\xdd\x14\xb51'), encData)
    def test_seal_with_test_vector_13(self):
        key = bytearray(32)

        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        self.assertEqual(aesGCM.name, "aes256gcm")

        nonce = bytearray(12)
        data = bytearray(0)

        encData = aesGCM.seal(nonce, data, data)

        self.assertEqual(
            bytearray(b'\x53\x0f\x8a\xfb\xc7\x45\x36\xb9' +
                      b'\xa9\x63\xb4\xf1\xc4\xcb\x73\x8b'), encData)
    def test_seal_with_test_vector_2(self):
        key = bytearray(b'\x00' * 16)
        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        nonce = bytearray(b'\x00' * 12)

        plaintext = bytearray(b'\x00' * 16)
        self.assertEqual(len(plaintext), 16)

        encData = aesGCM.seal(nonce, plaintext, bytearray(0))

        self.assertEqual(
            bytearray(b'\x03\x88\xda\xce\x60\xb6\xa3\x92' +
                      b'\xf3\x28\xc2\xb9\x71\xb2\xfe\x78' +
                      b'\xab\x6e\x47\xd4\x2c\xec\x13\xbd' +
                      b'\xf5\x3a\x67\xb2\x12\x57\xbd\xdf'), encData)
    def test_seal_with_test_vector_14(self):
        key = bytearray(32)

        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        self.assertEqual(aesGCM.name, "aes256gcm")

        nonce = bytearray(12)
        plaintext = bytearray(16)
        data = bytearray(0)

        encData = aesGCM.seal(nonce, plaintext, data)

        self.assertEqual(
            bytearray(b'\xce\xa7\x40\x3d\x4d\x60\x6b\x6e' +
                      b'\x07\x4e\xc5\xd3\xba\xf3\x9d\x18' +
                      b'\xd0\xd1\xc8\xa7\x99\x99\x6b\xf0' +
                      b'\x26\x5b\x98\xb5\xd4\x8a\xb9\x19'), encData)
    def test___init___with_invalid_key(self):
        key = bytearray(8)

        with self.assertRaises(AssertionError):
            aesGCM = AESGCM(key, "python", Rijndael(bytearray(16), 16).encrypt)
    def test___init__(self):
        key = bytearray(16)
        aesGCM = AESGCM(key, "python", Rijndael(key, 16).encrypt)

        self.assertIsNotNone(aesGCM)
Ejemplo n.º 30
0
 def new(key):
     return OPENSSL_AESGCM(key, "openssl", Rijndael(key, 16).encrypt)