aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2016-11-20 22:48:10 +0800
committerAlex Gaynor <alex.gaynor@gmail.com>2016-11-20 09:48:10 -0500
commitf555c74d5419a52648e2a903595c13bd13d13ce2 (patch)
tree592b855980fecba54c51924b58457607c6da1463 /tests/hazmat
parent033bd7167d6546d34576dd0d798318999ec82a07 (diff)
downloadcryptography-f555c74d5419a52648e2a903595c13bd13d13ce2.tar.gz
cryptography-f555c74d5419a52648e2a903595c13bd13d13ce2.tar.bz2
cryptography-f555c74d5419a52648e2a903595c13bd13d13ce2.zip
support RSA verify with prehashing (#3265)
* support RSA verify with prehashing * review feedback * more dedupe * refactor and move to a separate module
Diffstat (limited to 'tests/hazmat')
-rw-r--r--tests/hazmat/primitives/test_rsa.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py
index 6ec17993..cbb9be6f 100644
--- a/tests/hazmat/primitives/test_rsa.py
+++ b/tests/hazmat/primitives/test_rsa.py
@@ -897,6 +897,29 @@ class TestRSAVerification(object):
public_key = private_key.public_key()
public_key.verify(signature, message, pkcs, algorithm)
+ def test_prehashed_verify(self, backend):
+ private_key = RSA_KEY_512.private_key(backend)
+ message = b"one little message"
+ h = hashes.Hash(hashes.SHA1(), backend)
+ h.update(message)
+ digest = h.finalize()
+ prehashed_alg = asym_utils.Prehashed(hashes.SHA1())
+ pkcs = padding.PKCS1v15()
+ signature = private_key.sign(message, pkcs, hashes.SHA1())
+ public_key = private_key.public_key()
+ public_key.verify(signature, digest, pkcs, prehashed_alg)
+
+ def test_prehashed_digest_mismatch(self, backend):
+ public_key = RSA_KEY_512.private_key(backend).public_key()
+ message = b"one little message"
+ h = hashes.Hash(hashes.SHA1(), backend)
+ h.update(message)
+ data = h.finalize()
+ prehashed_alg = asym_utils.Prehashed(hashes.SHA512())
+ pkcs = padding.PKCS1v15()
+ with pytest.raises(ValueError):
+ public_key.verify(b"\x00" * 64, data, pkcs, prehashed_alg)
+
@pytest.mark.requires_backend_interface(interface=RSABackend)
class TestRSAPSSMGF1Verification(object):