aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2024-01-28 16:34:33 -0600
committerGitHub <noreply@github.com>2024-01-28 17:34:33 -0500
commit1729edef70315b532379db998efc6d69c546fe27 (patch)
treebff344363bbe4f442640b3aeb0fab944ccc1b9e3 /tests
parentea5a5b4ad01737bce57de7ca3803436abf32dc61 (diff)
downloadpyca-cryptography-1729edef70315b532379db998efc6d69c546fe27.zip
pyca-cryptography-1729edef70315b532379db998efc6d69c546fe27.tar.gz
pyca-cryptography-1729edef70315b532379db998efc6d69c546fe27.tar.bz2
add decrepit namespace and put SEED, IDEA, Blowfish, and CAST5 in it (#10284)
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/primitives/decrepit/__init__.py3
-rw-r--r--tests/hazmat/primitives/decrepit/test_algorithms.py340
-rw-r--r--tests/hazmat/primitives/test_blowfish.py86
-rw-r--r--tests/hazmat/primitives/test_cast5.py86
-rw-r--r--tests/hazmat/primitives/test_ciphers.py88
-rw-r--r--tests/hazmat/primitives/test_idea.py86
-rw-r--r--tests/hazmat/primitives/test_seed.py86
7 files changed, 363 insertions, 412 deletions
diff --git a/tests/hazmat/primitives/decrepit/__init__.py b/tests/hazmat/primitives/decrepit/__init__.py
new file mode 100644
index 0000000..b509336
--- /dev/null
+++ b/tests/hazmat/primitives/decrepit/__init__.py
@@ -0,0 +1,3 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
diff --git a/tests/hazmat/primitives/decrepit/test_algorithms.py b/tests/hazmat/primitives/decrepit/test_algorithms.py
new file mode 100644
index 0000000..c812f17
--- /dev/null
+++ b/tests/hazmat/primitives/decrepit/test_algorithms.py
@@ -0,0 +1,340 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
+
+
+import binascii
+import os
+
+import pytest
+
+from cryptography.hazmat.decrepit.ciphers.algorithms import (
+ CAST5,
+ IDEA,
+ SEED,
+ Blowfish,
+)
+from cryptography.hazmat.primitives.ciphers import modes
+
+from ....utils import load_nist_vectors
+from ..utils import generate_encrypt_test
+
+
+class TestBlowfish:
+ @pytest.mark.parametrize(
+ ("key", "keysize"),
+ [(b"0" * (keysize // 4), keysize) for keysize in range(32, 449, 8)],
+ )
+ def test_key_size(self, key, keysize):
+ cipher = Blowfish(binascii.unhexlify(key))
+ assert cipher.key_size == keysize
+
+ def test_invalid_key_size(self):
+ with pytest.raises(ValueError):
+ Blowfish(binascii.unhexlify(b"0" * 6))
+
+ def test_invalid_key_type(self):
+ with pytest.raises(TypeError, match="key must be bytes"):
+ Blowfish("0" * 8) # type: ignore[arg-type]
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ Blowfish(b"\x00" * 56), modes.ECB()
+ ),
+ skip_message="Does not support Blowfish ECB",
+)
+class TestBlowfishModeECB:
+ test_ecb = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "Blowfish"),
+ ["bf-ecb.txt"],
+ lambda key, **kwargs: Blowfish(binascii.unhexlify(key)),
+ lambda **kwargs: modes.ECB(),
+ )
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ Blowfish(b"\x00" * 56), modes.CBC(b"\x00" * 8)
+ ),
+ skip_message="Does not support Blowfish CBC",
+)
+class TestBlowfishModeCBC:
+ test_cbc = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "Blowfish"),
+ ["bf-cbc.txt"],
+ lambda key, **kwargs: Blowfish(binascii.unhexlify(key)),
+ lambda iv, **kwargs: modes.CBC(binascii.unhexlify(iv)),
+ )
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ Blowfish(b"\x00" * 56), modes.OFB(b"\x00" * 8)
+ ),
+ skip_message="Does not support Blowfish OFB",
+)
+class TestBlowfishModeOFB:
+ test_ofb = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "Blowfish"),
+ ["bf-ofb.txt"],
+ lambda key, **kwargs: Blowfish(binascii.unhexlify(key)),
+ lambda iv, **kwargs: modes.OFB(binascii.unhexlify(iv)),
+ )
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ Blowfish(b"\x00" * 56), modes.CFB(b"\x00" * 8)
+ ),
+ skip_message="Does not support Blowfish CFB",
+)
+class TestBlowfishModeCFB:
+ test_cfb = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "Blowfish"),
+ ["bf-cfb.txt"],
+ lambda key, **kwargs: Blowfish(binascii.unhexlify(key)),
+ lambda iv, **kwargs: modes.CFB(binascii.unhexlify(iv)),
+ )
+
+
+class TestCAST5:
+ @pytest.mark.parametrize(
+ ("key", "keysize"),
+ [(b"0" * (keysize // 4), keysize) for keysize in range(40, 129, 8)],
+ )
+ def test_key_size(self, key, keysize):
+ cipher = CAST5(binascii.unhexlify(key))
+ assert cipher.key_size == keysize
+
+ def test_invalid_key_size(self):
+ with pytest.raises(ValueError):
+ CAST5(binascii.unhexlify(b"0" * 34))
+
+ def test_invalid_key_type(self):
+ with pytest.raises(TypeError, match="key must be bytes"):
+ CAST5("0" * 10) # type: ignore[arg-type]
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ CAST5(b"\x00" * 16), modes.ECB()
+ ),
+ skip_message="Does not support CAST5 ECB",
+)
+class TestCAST5ModeECB:
+ test_ecb = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "CAST5"),
+ ["cast5-ecb.txt"],
+ lambda key, **kwargs: CAST5(binascii.unhexlify(key)),
+ lambda **kwargs: modes.ECB(),
+ )
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ CAST5(b"\x00" * 16), modes.CBC(b"\x00" * 8)
+ ),
+ skip_message="Does not support CAST5 CBC",
+)
+class TestCAST5ModeCBC:
+ test_cbc = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "CAST5"),
+ ["cast5-cbc.txt"],
+ lambda key, **kwargs: CAST5(binascii.unhexlify(key)),
+ lambda iv, **kwargs: modes.CBC(binascii.unhexlify(iv)),
+ )
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ CAST5(b"\x00" * 16), modes.OFB(b"\x00" * 8)
+ ),
+ skip_message="Does not support CAST5 OFB",
+)
+class TestCAST5ModeOFB:
+ test_ofb = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "CAST5"),
+ ["cast5-ofb.txt"],
+ lambda key, **kwargs: CAST5(binascii.unhexlify(key)),
+ lambda iv, **kwargs: modes.OFB(binascii.unhexlify(iv)),
+ )
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ CAST5(b"\x00" * 16), modes.CFB(b"\x00" * 8)
+ ),
+ skip_message="Does not support CAST5 CFB",
+)
+class TestCAST5ModeCFB:
+ test_cfb = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "CAST5"),
+ ["cast5-cfb.txt"],
+ lambda key, **kwargs: CAST5(binascii.unhexlify(key)),
+ lambda iv, **kwargs: modes.CFB(binascii.unhexlify(iv)),
+ )
+
+
+class TestIDEA:
+ def test_key_size(self):
+ cipher = IDEA(b"\x00" * 16)
+ assert cipher.key_size == 128
+
+ def test_invalid_key_size(self):
+ with pytest.raises(ValueError):
+ IDEA(b"\x00" * 17)
+
+ def test_invalid_key_type(self):
+ with pytest.raises(TypeError, match="key must be bytes"):
+ IDEA("0" * 16) # type: ignore[arg-type]
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ IDEA(b"\x00" * 16), modes.ECB()
+ ),
+ skip_message="Does not support IDEA ECB",
+)
+class TestIDEAModeECB:
+ test_ecb = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "IDEA"),
+ ["idea-ecb.txt"],
+ lambda key, **kwargs: IDEA(binascii.unhexlify(key)),
+ lambda **kwargs: modes.ECB(),
+ )
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ IDEA(b"\x00" * 16), modes.CBC(b"\x00" * 8)
+ ),
+ skip_message="Does not support IDEA CBC",
+)
+class TestIDEAModeCBC:
+ test_cbc = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "IDEA"),
+ ["idea-cbc.txt"],
+ lambda key, **kwargs: IDEA(binascii.unhexlify(key)),
+ lambda iv, **kwargs: modes.CBC(binascii.unhexlify(iv)),
+ )
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ IDEA(b"\x00" * 16), modes.OFB(b"\x00" * 8)
+ ),
+ skip_message="Does not support IDEA OFB",
+)
+class TestIDEAModeOFB:
+ test_ofb = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "IDEA"),
+ ["idea-ofb.txt"],
+ lambda key, **kwargs: IDEA(binascii.unhexlify(key)),
+ lambda iv, **kwargs: modes.OFB(binascii.unhexlify(iv)),
+ )
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ IDEA(b"\x00" * 16), modes.CFB(b"\x00" * 8)
+ ),
+ skip_message="Does not support IDEA CFB",
+)
+class TestIDEAModeCFB:
+ test_cfb = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "IDEA"),
+ ["idea-cfb.txt"],
+ lambda key, **kwargs: IDEA(binascii.unhexlify(key)),
+ lambda iv, **kwargs: modes.CFB(binascii.unhexlify(iv)),
+ )
+
+
+class TestSEED:
+ def test_key_size(self):
+ cipher = SEED(b"\x00" * 16)
+ assert cipher.key_size == 128
+
+ def test_invalid_key_size(self):
+ with pytest.raises(ValueError):
+ SEED(b"\x00" * 17)
+
+ def test_invalid_key_type(self):
+ with pytest.raises(TypeError, match="key must be bytes"):
+ SEED("0" * 16) # type: ignore[arg-type]
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ SEED(b"\x00" * 16), modes.ECB()
+ ),
+ skip_message="Does not support SEED ECB",
+)
+class TestSEEDModeECB:
+ test_ecb = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "SEED"),
+ ["rfc-4269.txt"],
+ lambda key, **kwargs: SEED(binascii.unhexlify(key)),
+ lambda **kwargs: modes.ECB(),
+ )
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ SEED(b"\x00" * 16), modes.CBC(b"\x00" * 16)
+ ),
+ skip_message="Does not support SEED CBC",
+)
+class TestSEEDModeCBC:
+ test_cbc = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "SEED"),
+ ["rfc-4196.txt"],
+ lambda key, **kwargs: SEED(binascii.unhexlify(key)),
+ lambda iv, **kwargs: modes.CBC(binascii.unhexlify(iv)),
+ )
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ SEED(b"\x00" * 16), modes.OFB(b"\x00" * 16)
+ ),
+ skip_message="Does not support SEED OFB",
+)
+class TestSEEDModeOFB:
+ test_ofb = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "SEED"),
+ ["seed-ofb.txt"],
+ lambda key, **kwargs: SEED(binascii.unhexlify(key)),
+ lambda iv, **kwargs: modes.OFB(binascii.unhexlify(iv)),
+ )
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ SEED(b"\x00" * 16), modes.CFB(b"\x00" * 16)
+ ),
+ skip_message="Does not support SEED CFB",
+)
+class TestSEEDModeCFB:
+ test_cfb = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "SEED"),
+ ["seed-cfb.txt"],
+ lambda key, **kwargs: SEED(binascii.unhexlify(key)),
+ lambda iv, **kwargs: modes.CFB(binascii.unhexlify(iv)),
+ )
diff --git a/tests/hazmat/primitives/test_blowfish.py b/tests/hazmat/primitives/test_blowfish.py
deleted file mode 100644
index b8f34df..0000000
--- a/tests/hazmat/primitives/test_blowfish.py
+++ /dev/null
@@ -1,86 +0,0 @@
-# This file is dual licensed under the terms of the Apache License, Version
-# 2.0, and the BSD License. See the LICENSE file in the root of this repository
-# for complete details.
-
-
-import binascii
-import os
-
-import pytest
-
-from cryptography.hazmat.primitives.ciphers import algorithms, modes
-
-from ...utils import load_nist_vectors
-from .utils import generate_encrypt_test
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._BlowfishInternal(b"\x00" * 56), modes.ECB()
- ),
- skip_message="Does not support Blowfish ECB",
-)
-class TestBlowfishModeECB:
- test_ecb = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "Blowfish"),
- ["bf-ecb.txt"],
- lambda key, **kwargs: algorithms._BlowfishInternal(
- binascii.unhexlify(key)
- ),
- lambda **kwargs: modes.ECB(),
- )
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._BlowfishInternal(b"\x00" * 56), modes.CBC(b"\x00" * 8)
- ),
- skip_message="Does not support Blowfish CBC",
-)
-class TestBlowfishModeCBC:
- test_cbc = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "Blowfish"),
- ["bf-cbc.txt"],
- lambda key, **kwargs: algorithms._BlowfishInternal(
- binascii.unhexlify(key)
- ),
- lambda iv, **kwargs: modes.CBC(binascii.unhexlify(iv)),
- )
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._BlowfishInternal(b"\x00" * 56), modes.OFB(b"\x00" * 8)
- ),
- skip_message="Does not support Blowfish OFB",
-)
-class TestBlowfishModeOFB:
- test_ofb = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "Blowfish"),
- ["bf-ofb.txt"],
- lambda key, **kwargs: algorithms._BlowfishInternal(
- binascii.unhexlify(key)
- ),
- lambda iv, **kwargs: modes.OFB(binascii.unhexlify(iv)),
- )
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._BlowfishInternal(b"\x00" * 56), modes.CFB(b"\x00" * 8)
- ),
- skip_message="Does not support Blowfish CFB",
-)
-class TestBlowfishModeCFB:
- test_cfb = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "Blowfish"),
- ["bf-cfb.txt"],
- lambda key, **kwargs: algorithms._BlowfishInternal(
- binascii.unhexlify(key)
- ),
- lambda iv, **kwargs: modes.CFB(binascii.unhexlify(iv)),
- )
diff --git a/tests/hazmat/primitives/test_cast5.py b/tests/hazmat/primitives/test_cast5.py
deleted file mode 100644
index 327a463..0000000
--- a/tests/hazmat/primitives/test_cast5.py
+++ /dev/null
@@ -1,86 +0,0 @@
-# This file is dual licensed under the terms of the Apache License, Version
-# 2.0, and the BSD License. See the LICENSE file in the root of this repository
-# for complete details.
-
-
-import binascii
-import os
-
-import pytest
-
-from cryptography.hazmat.primitives.ciphers import algorithms, modes
-
-from ...utils import load_nist_vectors
-from .utils import generate_encrypt_test
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._CAST5Internal(b"\x00" * 16), modes.ECB()
- ),
- skip_message="Does not support CAST5 ECB",
-)
-class TestCAST5ModeECB:
- test_ecb = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "CAST5"),
- ["cast5-ecb.txt"],
- lambda key, **kwargs: algorithms._CAST5Internal(
- binascii.unhexlify(key)
- ),
- lambda **kwargs: modes.ECB(),
- )
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._CAST5Internal(b"\x00" * 16), modes.CBC(b"\x00" * 8)
- ),
- skip_message="Does not support CAST5 CBC",
-)
-class TestCAST5ModeCBC:
- test_cbc = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "CAST5"),
- ["cast5-cbc.txt"],
- lambda key, **kwargs: algorithms._CAST5Internal(
- binascii.unhexlify(key)
- ),
- lambda iv, **kwargs: modes.CBC(binascii.unhexlify(iv)),
- )
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._CAST5Internal(b"\x00" * 16), modes.OFB(b"\x00" * 8)
- ),
- skip_message="Does not support CAST5 OFB",
-)
-class TestCAST5ModeOFB:
- test_ofb = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "CAST5"),
- ["cast5-ofb.txt"],
- lambda key, **kwargs: algorithms._CAST5Internal(
- binascii.unhexlify(key)
- ),
- lambda iv, **kwargs: modes.OFB(binascii.unhexlify(iv)),
- )
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._CAST5Internal(b"\x00" * 16), modes.CFB(b"\x00" * 8)
- ),
- skip_message="Does not support CAST5 CFB",
-)
-class TestCAST5ModeCFB:
- test_cfb = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "CAST5"),
- ["cast5-cfb.txt"],
- lambda key, **kwargs: algorithms._CAST5Internal(
- binascii.unhexlify(key)
- ),
- lambda iv, **kwargs: modes.CFB(binascii.unhexlify(iv)),
- )
diff --git a/tests/hazmat/primitives/test_ciphers.py b/tests/hazmat/primitives/test_ciphers.py
index 1659fa2..e096986 100644
--- a/tests/hazmat/primitives/test_ciphers.py
+++ b/tests/hazmat/primitives/test_ciphers.py
@@ -10,6 +10,7 @@ import sys
import pytest
+from cryptography import utils
from cryptography.exceptions import AlreadyFinalized, _Reasons
from cryptography.hazmat.primitives import ciphers
from cryptography.hazmat.primitives.ciphers import modes
@@ -18,10 +19,6 @@ from cryptography.hazmat.primitives.ciphers.algorithms import (
ARC4,
Camellia,
TripleDES,
- _BlowfishInternal,
- _CAST5Internal,
- _IDEAInternal,
- _SEEDInternal,
)
from ...utils import (
@@ -31,6 +28,25 @@ from ...utils import (
)
+def test_deprecated_ciphers_import_with_warning():
+ with pytest.warns(utils.CryptographyDeprecationWarning):
+ from cryptography.hazmat.primitives.ciphers.algorithms import (
+ Blowfish, # noqa: F401
+ )
+ with pytest.warns(utils.CryptographyDeprecationWarning):
+ from cryptography.hazmat.primitives.ciphers.algorithms import (
+ CAST5, # noqa: F401
+ )
+ with pytest.warns(utils.CryptographyDeprecationWarning):
+ from cryptography.hazmat.primitives.ciphers.algorithms import (
+ IDEA, # noqa: F401
+ )
+ with pytest.warns(utils.CryptographyDeprecationWarning):
+ from cryptography.hazmat.primitives.ciphers.algorithms import (
+ SEED, # noqa: F401
+ )
+
+
class TestAES:
@pytest.mark.parametrize(
("key", "keysize"),
@@ -110,42 +126,6 @@ class TestTripleDES:
TripleDES("0" * 16) # type: ignore[arg-type]
-class TestBlowfish:
- @pytest.mark.parametrize(
- ("key", "keysize"),
- [(b"0" * (keysize // 4), keysize) for keysize in range(32, 449, 8)],
- )
- def test_key_size(self, key, keysize):
- cipher = _BlowfishInternal(binascii.unhexlify(key))
- assert cipher.key_size == keysize
-
- def test_invalid_key_size(self):
- with pytest.raises(ValueError):
- _BlowfishInternal(binascii.unhexlify(b"0" * 6))
-
- def test_invalid_key_type(self):
- with pytest.raises(TypeError, match="key must be bytes"):
- _BlowfishInternal("0" * 8) # type: ignore[arg-type]
-
-
-class TestCAST5:
- @pytest.mark.parametrize(
- ("key", "keysize"),
- [(b"0" * (keysize // 4), keysize) for keysize in range(40, 129, 8)],
- )
- def test_key_size(self, key, keysize):
- cipher = _CAST5Internal(binascii.unhexlify(key))
- assert cipher.key_size == keysize
-
- def test_invalid_key_size(self):
- with pytest.raises(ValueError):
- _CAST5Internal(binascii.unhexlify(b"0" * 34))
-
- def test_invalid_key_type(self):
- with pytest.raises(TypeError, match="key must be bytes"):
- _CAST5Internal("0" * 10) # type: ignore[arg-type]
-
-
class TestARC4:
@pytest.mark.parametrize(
("key", "keysize"),
@@ -172,34 +152,6 @@ class TestARC4:
ARC4("0" * 10) # type: ignore[arg-type]
-class TestIDEA:
- def test_key_size(self):
- cipher = _IDEAInternal(b"\x00" * 16)
- assert cipher.key_size == 128
-
- def test_invalid_key_size(self):
- with pytest.raises(ValueError):
- _IDEAInternal(b"\x00" * 17)
-
- def test_invalid_key_type(self):
- with pytest.raises(TypeError, match="key must be bytes"):
- _IDEAInternal("0" * 16) # type: ignore[arg-type]
-
-
-class TestSEED:
- def test_key_size(self):
- cipher = _SEEDInternal(b"\x00" * 16)
- assert cipher.key_size == 128
-
- def test_invalid_key_size(self):
- with pytest.raises(ValueError):
- _SEEDInternal(b"\x00" * 17)
-
- def test_invalid_key_type(self):
- with pytest.raises(TypeError, match="key must be bytes"):
- _SEEDInternal("0" * 16) # type: ignore[arg-type]
-
-
def test_invalid_mode_algorithm():
with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_CIPHER):
ciphers.Cipher(
diff --git a/tests/hazmat/primitives/test_idea.py b/tests/hazmat/primitives/test_idea.py
deleted file mode 100644
index 6631a93..0000000
--- a/tests/hazmat/primitives/test_idea.py
+++ /dev/null
@@ -1,86 +0,0 @@
-# This file is dual licensed under the terms of the Apache License, Version
-# 2.0, and the BSD License. See the LICENSE file in the root of this repository
-# for complete details.
-
-
-import binascii
-import os
-
-import pytest
-
-from cryptography.hazmat.primitives.ciphers import algorithms, modes
-
-from ...utils import load_nist_vectors
-from .utils import generate_encrypt_test
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._IDEAInternal(b"\x00" * 16), modes.ECB()
- ),
- skip_message="Does not support IDEA ECB",
-)
-class TestIDEAModeECB:
- test_ecb = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "IDEA"),
- ["idea-ecb.txt"],
- lambda key, **kwargs: algorithms._IDEAInternal(
- binascii.unhexlify(key)
- ),
- lambda **kwargs: modes.ECB(),
- )
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._IDEAInternal(b"\x00" * 16), modes.CBC(b"\x00" * 8)
- ),
- skip_message="Does not support IDEA CBC",
-)
-class TestIDEAModeCBC:
- test_cbc = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "IDEA"),
- ["idea-cbc.txt"],
- lambda key, **kwargs: algorithms._IDEAInternal(
- binascii.unhexlify(key)
- ),
- lambda iv, **kwargs: modes.CBC(binascii.unhexlify(iv)),
- )
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._IDEAInternal(b"\x00" * 16), modes.OFB(b"\x00" * 8)
- ),
- skip_message="Does not support IDEA OFB",
-)
-class TestIDEAModeOFB:
- test_ofb = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "IDEA"),
- ["idea-ofb.txt"],
- lambda key, **kwargs: algorithms._IDEAInternal(
- binascii.unhexlify(key)
- ),
- lambda iv, **kwargs: modes.OFB(binascii.unhexlify(iv)),
- )
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._IDEAInternal(b"\x00" * 16), modes.CFB(b"\x00" * 8)
- ),
- skip_message="Does not support IDEA CFB",
-)
-class TestIDEAModeCFB:
- test_cfb = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "IDEA"),
- ["idea-cfb.txt"],
- lambda key, **kwargs: algorithms._IDEAInternal(
- binascii.unhexlify(key)
- ),
- lambda iv, **kwargs: modes.CFB(binascii.unhexlify(iv)),
- )
diff --git a/tests/hazmat/primitives/test_seed.py b/tests/hazmat/primitives/test_seed.py
deleted file mode 100644
index f36ce1e..0000000
--- a/tests/hazmat/primitives/test_seed.py
+++ /dev/null
@@ -1,86 +0,0 @@
-# This file is dual licensed under the terms of the Apache License, Version
-# 2.0, and the BSD License. See the LICENSE file in the root of this repository
-# for complete details.
-
-
-import binascii
-import os
-
-import pytest
-
-from cryptography.hazmat.primitives.ciphers import algorithms, modes
-
-from ...utils import load_nist_vectors
-from .utils import generate_encrypt_test
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._SEEDInternal(b"\x00" * 16), modes.ECB()
- ),
- skip_message="Does not support SEED ECB",
-)
-class TestSEEDModeECB:
- test_ecb = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "SEED"),
- ["rfc-4269.txt"],
- lambda key, **kwargs: algorithms._SEEDInternal(
- binascii.unhexlify(key)
- ),
- lambda **kwargs: modes.ECB(),
- )
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._SEEDInternal(b"\x00" * 16), modes.CBC(b"\x00" * 16)
- ),
- skip_message="Does not support SEED CBC",
-)
-class TestSEEDModeCBC:
- test_cbc = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "SEED"),
- ["rfc-4196.txt"],
- lambda key, **kwargs: algorithms._SEEDInternal(
- binascii.unhexlify(key)
- ),
- lambda iv, **kwargs: modes.CBC(binascii.unhexlify(iv)),
- )
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._SEEDInternal(b"\x00" * 16), modes.OFB(b"\x00" * 16)
- ),
- skip_message="Does not support SEED OFB",
-)
-class TestSEEDModeOFB:
- test_ofb = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "SEED"),
- ["seed-ofb.txt"],
- lambda key, **kwargs: algorithms._SEEDInternal(
- binascii.unhexlify(key)
- ),
- lambda iv, **kwargs: modes.OFB(binascii.unhexlify(iv)),
- )
-
-
-@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(
- algorithms._SEEDInternal(b"\x00" * 16), modes.CFB(b"\x00" * 16)
- ),
- skip_message="Does not support SEED CFB",
-)
-class TestSEEDModeCFB:
- test_cfb = generate_encrypt_test(
- load_nist_vectors,
- os.path.join("ciphers", "SEED"),
- ["seed-cfb.txt"],
- lambda key, **kwargs: algorithms._SEEDInternal(
- binascii.unhexlify(key)
- ),
- lambda iv, **kwargs: modes.CFB(binascii.unhexlify(iv)),
- )