Skip to content

Commit ebfa669

Browse files
alexreaperhulk
authored andcommitted
Refs pyca#4375 -- added RSA PSS wycheproof tests (pyca#4381)
1 parent f6ccb2e commit ebfa669

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

tests/wycheproof/test_rsa.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def should_verify(backend, wycheproof):
6262
"rsa_signature_4096_sha384_test.json",
6363
"rsa_signature_4096_sha512_test.json",
6464
)
65-
def test_rsa_signature(backend, wycheproof):
65+
def test_rsa_pkcs1v15_signature(backend, wycheproof):
6666
key = serialization.load_der_public_key(
6767
binascii.unhexlify(wycheproof.testgroup["keyDer"]), backend
6868
)
@@ -83,3 +83,43 @@ def test_rsa_signature(backend, wycheproof):
8383
padding.PKCS1v15(),
8484
digest,
8585
)
86+
87+
88+
@pytest.mark.requires_backend_interface(interface=RSABackend)
89+
@pytest.mark.wycheproof_tests(
90+
"rsa_pss_2048_sha1_mgf1_20_test.json",
91+
"rsa_pss_2048_sha256_mgf1_0_test.json",
92+
"rsa_pss_2048_sha256_mgf1_32_test.json",
93+
"rsa_pss_3072_sha256_mgf1_32_test.json",
94+
"rsa_pss_4096_sha256_mgf1_32_test.json",
95+
"rsa_pss_4096_sha512_mgf1_32_test.json",
96+
"rsa_pss_misc_test.json",
97+
)
98+
def test_rsa_pss_signature(backend, wycheproof):
99+
key = serialization.load_der_public_key(
100+
binascii.unhexlify(wycheproof.testgroup["keyDer"]), backend
101+
)
102+
digest = _DIGESTS[wycheproof.testgroup["sha"]]
103+
mgf_digest = _DIGESTS[wycheproof.testgroup["mgfSha"]]
104+
105+
if wycheproof.valid or wycheproof.acceptable:
106+
key.verify(
107+
binascii.unhexlify(wycheproof.testcase["sig"]),
108+
binascii.unhexlify(wycheproof.testcase["msg"]),
109+
padding.PSS(
110+
mgf=padding.MGF1(mgf_digest),
111+
salt_length=wycheproof.testgroup["sLen"]
112+
),
113+
digest
114+
)
115+
else:
116+
with pytest.raises(InvalidSignature):
117+
key.verify(
118+
binascii.unhexlify(wycheproof.testcase["sig"]),
119+
binascii.unhexlify(wycheproof.testcase["msg"]),
120+
padding.PSS(
121+
mgf=padding.MGF1(mgf_digest),
122+
salt_length=wycheproof.testgroup["sLen"]
123+
),
124+
digest
125+
)

0 commit comments

Comments
 (0)