diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2020-04-26 11:44:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-26 10:44:49 -0500 |
commit | 069691a27b98bbca13faa843a1408d631b691bea (patch) | |
tree | 1fd37395f752049e81e5aa691951362954594ba9 /tests/wycheproof/test_rsa.py | |
parent | 8aa8665eaa0691acb84df627f86296e6e225773d (diff) | |
download | cryptography-069691a27b98bbca13faa843a1408d631b691bea.tar.gz cryptography-069691a27b98bbca13faa843a1408d631b691bea.tar.bz2 cryptography-069691a27b98bbca13faa843a1408d631b691bea.zip |
Added wycheproof RSA PKCSv1 encryption tests (#5234)
Diffstat (limited to 'tests/wycheproof/test_rsa.py')
-rw-r--r-- | tests/wycheproof/test_rsa.py | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/tests/wycheproof/test_rsa.py b/tests/wycheproof/test_rsa.py index 8a971d98..f17eff69 100644 --- a/tests/wycheproof/test_rsa.py +++ b/tests/wycheproof/test_rsa.py @@ -78,7 +78,9 @@ def test_rsa_pkcs1v15_signature(backend, wycheproof): digest = _DIGESTS[wycheproof.testgroup["sha"]] if digest is None or not backend.hash_supported(digest): - pytest.skip("Hash {} not supported".format(digest)) + pytest.skip( + "Hash {} not supported".format(wycheproof.testgroup["sha"]) + ) if should_verify(backend, wycheproof): key.verify( @@ -184,7 +186,11 @@ def test_rsa_oaep_encryption(backend, wycheproof): ) if not backend.rsa_padding_supported(padding_algo): - pytest.skip("Padding {} not supported".format(padding_algo)) + pytest.skip( + "OAEP with digest={} and MGF digest={} not supported".format( + wycheproof.testgroup["sha"], wycheproof.testgroup["mgfSha"], + ) + ) if wycheproof.valid or wycheproof.acceptable: pt = key.decrypt( @@ -198,3 +204,29 @@ def test_rsa_oaep_encryption(backend, wycheproof): binascii.unhexlify(wycheproof.testcase["ct"]), padding_algo ) + + +@pytest.mark.wycheproof_tests( + "rsa_pkcs1_2048_test.json", + "rsa_pkcs1_3072_test.json", + "rsa_pkcs1_4096_test.json", +) +def test_rsa_pkcs1_encryption(backend, wycheproof): + key = serialization.load_pem_private_key( + wycheproof.testgroup["privateKeyPem"].encode("ascii"), + password=None, + backend=backend, + ) + + if wycheproof.valid: + pt = key.decrypt( + binascii.unhexlify(wycheproof.testcase["ct"]), + padding.PKCS1v15() + ) + assert pt == binascii.unhexlify(wycheproof.testcase["msg"]) + else: + with pytest.raises(ValueError): + key.decrypt( + binascii.unhexlify(wycheproof.testcase["ct"]), + padding.PKCS1v15() + ) |