diff options
-rw-r--r-- | CHANGELOG.rst | 3 | ||||
-rw-r--r-- | cryptography/hazmat/backends/commoncrypto/backend.py | 1 | ||||
-rw-r--r-- | cryptography/hazmat/backends/openssl/backend.py | 5 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_3des.py | 37 |
4 files changed, 46 insertions, 0 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a38534d4..7a654546 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -19,6 +19,9 @@ Changelog :class:`~cryptography.hazmat.backends.interfaces.TraditionalOpenSSLSerializationBackend` support to the :doc:`/hazmat/backends/openssl`. * Added :class:`~cryptography.hazmat.backends.interfaces.EllipticCurveBackend`. +* Added :class:`~cryptography.hazmat.primitives.ciphers.modes.ECB` support + for :class:`~cryptography.hazmat.primitives.ciphers.algorithms.TripleDES` on + :doc:`/hazmat/backends/commoncrypto` and :doc:`/hazmat/backends/openssl`. 0.4 - 2014-05-03 ~~~~~~~~~~~~~~~~ diff --git a/cryptography/hazmat/backends/commoncrypto/backend.py b/cryptography/hazmat/backends/commoncrypto/backend.py index 213cbd8c..41be11f9 100644 --- a/cryptography/hazmat/backends/commoncrypto/backend.py +++ b/cryptography/hazmat/backends/commoncrypto/backend.py @@ -178,6 +178,7 @@ class Backend(object): ) for mode_cls, mode_const in [ (CBC, self._lib.kCCModeCBC), + (ECB, self._lib.kCCModeECB), (CFB, self._lib.kCCModeCFB), (CFB8, self._lib.kCCModeCFB8), (OFB, self._lib.kCCModeOFB), diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py index ab3f9471..eea58bec 100644 --- a/cryptography/hazmat/backends/openssl/backend.py +++ b/cryptography/hazmat/backends/openssl/backend.py @@ -181,6 +181,11 @@ class Backend(object): mode_cls, GetCipherByName("des-ede3-{mode.name}") ) + self.register_cipher_adapter( + TripleDES, + ECB, + GetCipherByName("des-ede3") + ) for mode_cls in [CBC, CFB, OFB, ECB]: self.register_cipher_adapter( Blowfish, diff --git a/tests/hazmat/primitives/test_3des.py b/tests/hazmat/primitives/test_3des.py index b9354f0e..65660386 100644 --- a/tests/hazmat/primitives/test_3des.py +++ b/tests/hazmat/primitives/test_3des.py @@ -174,3 +174,40 @@ class TestTripleDESModeCFB8(object): ), lambda iv, **kwargs: modes.CFB8(binascii.unhexlify(iv)), ) + + +@pytest.mark.supported( + only_if=lambda backend: backend.cipher_supported( + algorithms.TripleDES("\x00" * 8), modes.ECB() + ), + skip_message="Does not support TripleDES ECB", +) +@pytest.mark.cipher +class TestTripleDESModeECB(object): + test_KAT = generate_encrypt_test( + load_nist_vectors, + os.path.join("ciphers", "3DES", "ECB"), + [ + "TECBinvperm.rsp", + "TECBpermop.rsp", + "TECBsubtab.rsp", + "TECBvarkey.rsp", + "TECBvartext.rsp", + ], + lambda keys, **kwargs: algorithms.TripleDES(binascii.unhexlify(keys)), + lambda **kwargs: modes.ECB(), + ) + + test_MMT = generate_encrypt_test( + load_nist_vectors, + os.path.join("ciphers", "3DES", "ECB"), + [ + "TECBMMT1.rsp", + "TECBMMT2.rsp", + "TECBMMT3.rsp", + ], + lambda key1, key2, key3, **kwargs: algorithms.TripleDES( + binascii.unhexlify(key1 + key2 + key3) + ), + lambda **kwargs: modes.ECB(), + ) |