def test_open_with_invalid_nonce(self): key = bytearray(b'\x01' * 16) aesCCM = AESCCM(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) as err: aesCCM.open(nonce, ciphertext, bytearray(0)) self.assertEqual("Bad nonce length", str(err.exception))
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_open_with_invalid_ciphertext(self): key = bytearray(b'\x01' * 16) aesCCM = AESCCM(key, "python", Rijndael(key, 16).encrypt) nonce = bytearray(b'\x02' * 12) ciphertext = bytearray(b'\xff' * 15) self.assertIsNone(aesCCM.open(nonce, ciphertext, 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_open_with_incorrect_nonce(self): key = bytearray(b'\x01' * 16) aesCCM = AESCCM(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 = aesCCM.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(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_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.'))