aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2024-02-16 19:40:43 -0800
committerGitHub <noreply@github.com>2024-02-17 03:40:43 +0000
commit429d34906ce39c082413c10c23386e0b1f520230 (patch)
treec69d044059b799ebf90a359da7716a39fa76db9c /tests
parent6643f54ac9620d94330d4a31ffc58763168c3e29 (diff)
downloadpyca-cryptography-429d34906ce39c082413c10c23386e0b1f520230.zip
pyca-cryptography-429d34906ce39c082413c10c23386e0b1f520230.tar.gz
pyca-cryptography-429d34906ce39c082413c10c23386e0b1f520230.tar.bz2
support RC2-CBC (#10407)
This PR supports a bad old algorithm to support a scapy use case, but does not expose support for effective key bits or any key length other than 128-bit. CBC support only -- no other modes.
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/primitives/decrepit/test_rc2.py37
-rw-r--r--tests/hazmat/primitives/test_pkcs12.py7
2 files changed, 42 insertions, 2 deletions
diff --git a/tests/hazmat/primitives/decrepit/test_rc2.py b/tests/hazmat/primitives/decrepit/test_rc2.py
new file mode 100644
index 0000000..ecd4ce2
--- /dev/null
+++ b/tests/hazmat/primitives/decrepit/test_rc2.py
@@ -0,0 +1,37 @@
+# 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.
+
+"""
+Test using the NIST Test Vectors
+"""
+
+
+import binascii
+import os
+
+import pytest
+
+from cryptography.hazmat.decrepit.ciphers.algorithms import RC2
+from cryptography.hazmat.primitives.ciphers import modes
+
+from ....utils import load_nist_vectors
+from ..utils import generate_encrypt_test
+
+
+@pytest.mark.supported(
+ only_if=lambda backend: backend.cipher_supported(
+ RC2(b"\x00" * 16), modes.CBC(b"\x00" * 8)
+ ),
+ skip_message="Does not support RC2 CBC",
+)
+class TestRC2ModeCBC:
+ test_kat = generate_encrypt_test(
+ load_nist_vectors,
+ os.path.join("ciphers", "RC2"),
+ [
+ "rc2-cbc.txt",
+ ],
+ lambda key, **kwargs: RC2(binascii.unhexlify(key)),
+ lambda iv, **kwargs: modes.CBC(binascii.unhexlify(iv)),
+ )
diff --git a/tests/hazmat/primitives/test_pkcs12.py b/tests/hazmat/primitives/test_pkcs12.py
index cd9c279..f49c98a 100644
--- a/tests/hazmat/primitives/test_pkcs12.py
+++ b/tests/hazmat/primitives/test_pkcs12.py
@@ -10,7 +10,7 @@ import pytest
from cryptography import x509
from cryptography.exceptions import UnsupportedAlgorithm
-from cryptography.hazmat.backends.openssl.backend import _RC2
+from cryptography.hazmat.decrepit.ciphers.algorithms import RC2
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import (
dsa,
@@ -19,6 +19,7 @@ from cryptography.hazmat.primitives.asymmetric import (
ed25519,
rsa,
)
+from cryptography.hazmat.primitives.ciphers.modes import CBC
from cryptography.hazmat.primitives.serialization import (
Encoding,
PublicFormat,
@@ -81,7 +82,9 @@ class TestPKCS12Loading:
],
)
@pytest.mark.supported(
- only_if=lambda backend: backend.cipher_supported(_RC2(), None),
+ only_if=lambda backend: backend.cipher_supported(
+ RC2(b"0" * 16), CBC(b"0" * 8)
+ ),
skip_message="Does not support RC2",
)
def test_load_pkcs12_ec_keys_rc2(self, filename, password, backend):