@@ -145,3 +145,66 @@ def test_rsa_pss_signature(backend, wycheproof):
145145 ),
146146 digest
147147 )
148+
149+
150+ @pytest .mark .requires_backend_interface (interface = RSABackend )
151+ @pytest .mark .supported (
152+ only_if = lambda backend : (
153+ backend ._lib .CRYPTOGRAPHY_OPENSSL_110_OR_GREATER or
154+ backend ._lib .CRYPTOGRAPHY_IS_LIBRESSL
155+ ),
156+ skip_message = (
157+ "A handful of these tests fail on OpenSSL 1.0.2 and since upstream "
158+ "isn't maintaining it, they'll never be fixed."
159+ ),
160+ )
161+ @pytest .mark .wycheproof_tests (
162+ "rsa_oaep_2048_sha1_mgf1sha1_test.json" ,
163+ "rsa_oaep_2048_sha224_mgf1sha1_test.json" ,
164+ "rsa_oaep_2048_sha224_mgf1sha224_test.json" ,
165+ "rsa_oaep_2048_sha256_mgf1sha1_test.json" ,
166+ "rsa_oaep_2048_sha256_mgf1sha256_test.json" ,
167+ "rsa_oaep_2048_sha384_mgf1sha1_test.json" ,
168+ "rsa_oaep_2048_sha384_mgf1sha384_test.json" ,
169+ "rsa_oaep_2048_sha512_mgf1sha1_test.json" ,
170+ "rsa_oaep_2048_sha512_mgf1sha512_test.json" ,
171+ "rsa_oaep_3072_sha256_mgf1sha1_test.json" ,
172+ "rsa_oaep_3072_sha256_mgf1sha256_test.json" ,
173+ "rsa_oaep_3072_sha512_mgf1sha1_test.json" ,
174+ "rsa_oaep_3072_sha512_mgf1sha512_test.json" ,
175+ "rsa_oaep_4096_sha256_mgf1sha1_test.json" ,
176+ "rsa_oaep_4096_sha256_mgf1sha256_test.json" ,
177+ "rsa_oaep_4096_sha512_mgf1sha1_test.json" ,
178+ "rsa_oaep_4096_sha512_mgf1sha512_test.json" ,
179+ "rsa_oaep_misc_test.json" ,
180+ )
181+ def test_rsa_oaep_encryption (backend , wycheproof ):
182+ key = serialization .load_pem_private_key (
183+ wycheproof .testgroup ["privateKeyPem" ].encode ("ascii" ),
184+ password = None ,
185+ backend = backend ,
186+ )
187+ digest = _DIGESTS [wycheproof .testgroup ["sha" ]]
188+ mgf_digest = _DIGESTS [wycheproof .testgroup ["mgfSha" ]]
189+
190+ padding_algo = padding .OAEP (
191+ mgf = padding .MGF1 (algorithm = mgf_digest ),
192+ algorithm = digest ,
193+ label = binascii .unhexlify (wycheproof .testcase ["label" ])
194+ )
195+
196+ if not backend .rsa_padding_supported (padding_algo ):
197+ pytest .skip ("Padding {} not supported" .format (padding_algo ))
198+
199+ if wycheproof .valid or wycheproof .acceptable :
200+ pt = key .decrypt (
201+ binascii .unhexlify (wycheproof .testcase ["ct" ]),
202+ padding_algo
203+ )
204+ assert pt == binascii .unhexlify (wycheproof .testcase ["msg" ])
205+ else :
206+ with pytest .raises (ValueError ):
207+ key .decrypt (
208+ binascii .unhexlify (wycheproof .testcase ["ct" ]),
209+ padding_algo
210+ )
0 commit comments