Fix test_mac_with_cryptographic_failure unit test.

This test is meant to intentionally trigger an exception in the cryptography library
by creating a CMAC with a non-block cipher algorithm, IDEA.
That doesn't work any more because IDEA is now treated as a block cipher algorithm.
To fix this, we now use the ARC4 algorithm instead,
which does trigger the expected exception.
This commit is contained in:
arp102 2023-08-08 15:35:21 -04:00
parent f0a44b26ce
commit 0b63de97ee
2 changed files with 3 additions and 4 deletions

View File

@ -269,8 +269,7 @@ class CryptographyEngine(api.CryptographicEngine):
)
cipher_algorithm = self._symmetric_key_algorithms.get(algorithm)
try:
# ARC4 and IDEA algorithms will raise exception as CMAC
# requires block ciphers
# ARC4 and other non-block cipher algorithms will raise TypeError exceptions
c = cmac.CMAC(cipher_algorithm(key), backend=default_backend())
c.update(data)
mac_data = c.finalize()

View File

@ -247,8 +247,8 @@ class TestCryptographyEngine(testtools.TestCase):
engine = crypto.CryptographyEngine()
# IDEA is not block cipher so cmac should raise exception
args = [enums.CryptographicAlgorithm.IDEA, key, data]
# RC4 is not block cipher so cmac should raise exception
args = [enums.CryptographicAlgorithm.RC4, key, data]
self.assertRaises(
exceptions.CryptographicFailure,
engine.mac,