Repository: pyca/cryptography

Issue:
Numbers -> Key Methods
We have two different approaches to this right now. For RSA we have `load_rsa_private_numbers` and `load_rsa_public_numbers` in `serialization.py`, while for EC the `EC*Numbers` classes have `public_key` and `private_key` methods that take a backend.

We should decide which approach we want to use going forward. I'm leaning towards the EC method personally. Opinions?



Discussion:
We need to resolve this before 0.5 goes out IMO.

My preference is for the style in EC since numbers are special. https://cryptography.io/en/latest/hazmat/primitives/asymmetric/ec/#cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers.private_key

This is definitely a blocker for 0.5, but doesn't block us continuing with opaque key work while we discuss it.


Resolving patch:
diff --git a/cryptography/hazmat/primitives/asymmetric/rsa.py b/cryptography/hazmat/primitives/asymmetric/rsa.py
--- a/cryptography/hazmat/primitives/asymmetric/rsa.py
+++ b/cryptography/hazmat/primitives/asymmetric/rsa.py
@@ -377,6 +377,9 @@ def iqmp(self):
     def public_numbers(self):
         return self._public_numbers
 
+    def private_key(self, backend):
+        return backend.load_rsa_private_numbers(self)
+
 
 class RSAPublicNumbers(object):
     def __init__(self, e, n):
@@ -396,3 +399,6 @@ def e(self):
     @property
     def n(self):
         return self._n
+
+    def public_key(self, backend):
+        return backend.load_rsa_public_numbers(self)
diff --git a/cryptography/hazmat/primitives/serialization.py b/cryptography/hazmat/primitives/serialization.py
--- a/cryptography/hazmat/primitives/serialization.py
+++ b/cryptography/hazmat/primitives/serialization.py
@@ -24,11 +24,3 @@ def load_pem_pkcs8_private_key(data, password, backend):
     return backend.load_pkcs8_pem_private_key(
         data, password
     )
-
-
-def load_rsa_private_numbers(numbers, backend):
-    return backend.load_rsa_private_numbers(numbers)
-
-
-def load_rsa_public_numbers(numbers, backend):
-    return backend.load_rsa_public_numbers(numbers)


Test patch:
diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py
--- a/tests/hazmat/primitives/test_rsa.py
+++ b/tests/hazmat/primitives/test_rsa.py
@@ -27,9 +27,6 @@
 )
 from cryptography.hazmat.primitives import hashes, interfaces
 from cryptography.hazmat.primitives.asymmetric import padding, rsa
-from cryptography.hazmat.primitives.serialization import (
-    load_rsa_private_numbers
-)
 
 from .fixtures_rsa import (
     RSA_KEY_1024, RSA_KEY_1025, RSA_KEY_1026, RSA_KEY_1027, RSA_KEY_1028,
@@ -102,6 +99,8 @@ def test_generate_rsa_keys(self, backend, public_exponent, key_size):
 
         if isinstance(skey, interfaces.RSAPrivateKeyWithNumbers):
             _check_rsa_private_numbers(skey.private_numbers())
+            pkey = skey.public_key()
+            assert isinstance(pkey.public_numbers(), rsa.RSAPublicNumbers)
 
     def test_generate_rsa_key_class_method(self, backend):
         skey = pytest.deprecated_call(
@@ -522,7 +521,7 @@ def test_pss_signing(self, pkcs1_example, backend):
         skip_message="Does not support PSS."
     )
     def test_deprecated_pss_mgf1_salt_length(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         signer = private_key.signer(
             pytest.deprecated_call(
                 padding.PSS,
@@ -566,7 +565,7 @@ def test_pss_signing_sha2(self, hash_alg, backend):
             pytest.skip(
                 "Does not support {0} in MGF1 using PSS.".format(hash_alg.name)
             )
-        private_key = load_rsa_private_numbers(RSA_KEY_768, backend)
+        private_key = RSA_KEY_768.private_key(backend)
         public_key = private_key.public_key()
         pss = padding.PSS(
             mgf=padding.MGF1(hash_alg),
@@ -592,7 +591,7 @@ def test_pss_signing_sha2(self, hash_alg, backend):
         skip_message="Does not support SHA512."
     )
     def test_pss_minimum_key_size_for_digest(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_522, backend)
+        private_key = RSA_KEY_522.private_key(backend)
         signer = private_key.signer(
             padding.PSS(
                 mgf=padding.MGF1(hashes.SHA1()),
@@ -617,7 +616,7 @@ def test_pss_minimum_key_size_for_digest(self, backend):
         skip_message="Does not support SHA512."
     )
     def test_pss_signing_digest_too_large_for_key_size(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         with pytest.raises(ValueError):
             private_key.signer(
                 padding.PSS(
@@ -637,7 +636,7 @@ def test_pss_signing_digest_too_large_for_key_size(self, backend):
         skip_message="Does not support PSS."
     )
     def test_pss_signing_salt_length_too_long(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         signer = private_key.signer(
             padding.PSS(
                 mgf=padding.MGF1(hashes.SHA1()),
@@ -656,7 +655,7 @@ def test_pss_signing_salt_length_too_long(self, backend):
         skip_message="Does not support PKCS1v1.5."
     )
     def test_use_after_finalize(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         signer = private_key.signer(padding.PKCS1v15(), hashes.SHA1())
         signer.update(b"sign me")
         signer.finalize()
@@ -666,12 +665,12 @@ def test_use_after_finalize(self, backend):
             signer.update(b"more data")
 
     def test_unsupported_padding(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_PADDING):
             private_key.signer(DummyPadding(), hashes.SHA1())
 
     def test_padding_incorrect_type(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         with pytest.raises(TypeError):
             private_key.signer("notpadding", hashes.SHA1())
 
@@ -700,7 +699,7 @@ def test_rsa_signer_invalid_backend(self, backend):
         skip_message="Does not support PSS."
     )
     def test_unsupported_pss_mgf(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_MGF):
             private_key.signer(padding.PSS(mgf=DummyMGF()), hashes.SHA1())
 
@@ -711,7 +710,7 @@ def test_unsupported_pss_mgf(self, backend):
         skip_message="Does not support PKCS1v1.5."
     )
     def test_pkcs1_digest_too_large_for_key_size(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_599, backend)
+        private_key = RSA_KEY_599.private_key(backend)
         signer = private_key.signer(
             padding.PKCS1v15(),
             hashes.SHA512()
@@ -727,7 +726,7 @@ def test_pkcs1_digest_too_large_for_key_size(self, backend):
         skip_message="Does not support PKCS1v1.5."
     )
     def test_pkcs1_minimum_key_size(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_745, backend)
+        private_key = RSA_KEY_745.private_key(backend)
         signer = private_key.signer(
             padding.PKCS1v15(),
             hashes.SHA512()
@@ -774,7 +773,7 @@ def test_pkcs1v15_verification(self, pkcs1_example, backend):
         skip_message="Does not support PKCS1v1.5."
     )
     def test_invalid_pkcs1v15_signature_wrong_data(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         public_key = private_key.public_key()
         signer = private_key.signer(padding.PKCS1v15(), hashes.SHA1())
         signer.update(b"sign me")
@@ -795,8 +794,8 @@ def test_invalid_pkcs1v15_signature_wrong_data(self, backend):
         skip_message="Does not support PKCS1v1.5."
     )
     def test_invalid_pkcs1v15_signature_wrong_key(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
-        private_key2 = load_rsa_private_numbers(RSA_KEY_512_ALT, backend)
+        private_key = RSA_KEY_512.private_key(backend)
+        private_key2 = RSA_KEY_512_ALT.private_key(backend)
         public_key = private_key2.public_key()
         signer = private_key.signer(padding.PKCS1v15(), hashes.SHA1())
         signer.update(b"sign me")
@@ -961,7 +960,7 @@ def test_invalid_pss_signature_data_too_large_for_modulus(self, backend):
         skip_message="Does not support PKCS1v1.5."
     )
     def test_use_after_finalize(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         public_key = private_key.public_key()
         signer = private_key.signer(padding.PKCS1v15(), hashes.SHA1())
         signer.update(b"sign me")
@@ -980,13 +979,13 @@ def test_use_after_finalize(self, backend):
             verifier.update(b"more data")
 
     def test_unsupported_padding(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         public_key = private_key.public_key()
         with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_PADDING):
             public_key.verifier(b"sig", DummyPadding(), hashes.SHA1())
 
     def test_padding_incorrect_type(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         public_key = private_key.public_key()
         with pytest.raises(TypeError):
             public_key.verifier(b"sig", "notpadding", hashes.SHA1())
@@ -1012,7 +1011,7 @@ def test_rsa_verifier_invalid_backend(self, backend):
         skip_message="Does not support PSS."
     )
     def test_unsupported_pss_mgf(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         public_key = private_key.public_key()
         with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_MGF):
             public_key.verifier(b"sig", padding.PSS(mgf=DummyMGF()),
@@ -1032,7 +1031,7 @@ def test_unsupported_pss_mgf(self, backend):
         skip_message="Does not support SHA512."
     )
     def test_pss_verify_digest_too_large_for_key_size(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         signature = binascii.unhexlify(
             b"8b9a3ae9fb3b64158f3476dd8d8a1f1425444e98940e0926378baa9944d219d8"
             b"534c050ef6b19b1bdc6eb4da422e89161106a6f5b5cc16135b11eb6439b646bd"
@@ -1433,7 +1432,7 @@ def test_decrypt_pkcs1v15_vectors(self, vector, backend):
         assert message == binascii.unhexlify(example["message"])
 
     def test_unsupported_padding(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_PADDING):
             private_key.decrypt(b"0" * 64, DummyPadding())
 
@@ -1444,7 +1443,7 @@ def test_unsupported_padding(self, backend):
         skip_message="Does not support PKCS1v1.5."
     )
     def test_decrypt_invalid_decrypt(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         with pytest.raises(ValueError):
             private_key.decrypt(
                 b"\x00" * 64,
@@ -1458,7 +1457,7 @@ def test_decrypt_invalid_decrypt(self, backend):
         skip_message="Does not support PKCS1v1.5."
     )
     def test_decrypt_ciphertext_too_large(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         with pytest.raises(ValueError):
             private_key.decrypt(
                 b"\x00" * 65,
@@ -1472,7 +1471,7 @@ def test_decrypt_ciphertext_too_large(self, backend):
         skip_message="Does not support PKCS1v1.5."
     )
     def test_decrypt_ciphertext_too_small(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         ct = binascii.unhexlify(
             b"50b4c14136bd198c2f3c3ed243fce036e168d56517984a263cd66492b80804f1"
             b"69d210f2b9bdfb48b12f9ea05009c77da257cc600ccefe3a6283789d8ea0"
@@ -1539,7 +1538,7 @@ def test_decrypt_oaep_vectors(self, vector, backend):
         assert message == binascii.unhexlify(example["message"])
 
     def test_unsupported_oaep_mgf(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_MGF):
             private_key.decrypt(
                 b"0" * 64,
@@ -1613,7 +1612,7 @@ def test_rsa_encrypt_oaep(self, key_data, pad, backend):
         )
     )
     def test_rsa_encrypt_pkcs1v15(self, key_data, pad, backend):
-        private_key = load_rsa_private_numbers(key_data, backend)
+        private_key = key_data.private_key(backend)
         pt = b"encrypt me!"
         public_key = private_key.public_key()
         ct = public_key.encrypt(pt, pad)
@@ -1639,7 +1638,7 @@ def test_rsa_encrypt_pkcs1v15(self, key_data, pad, backend):
         )
     )
     def test_rsa_encrypt_key_too_small(self, key_data, pad, backend):
-        private_key = load_rsa_private_numbers(key_data, backend)
+        private_key = key_data.private_key(backend)
         public_key = private_key.public_key()
         # Slightly smaller than the key size but not enough for padding.
         with pytest.raises(ValueError):
@@ -1670,14 +1669,14 @@ def test_rsa_encrypt_invalid_backend(self, backend):
             )
 
     def test_unsupported_padding(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         public_key = private_key.public_key()
 
         with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_PADDING):
             public_key.encrypt(b"somedata", DummyPadding())
 
     def test_unsupported_oaep_mgf(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_512, backend)
+        private_key = RSA_KEY_512.private_key(backend)
         public_key = private_key.public_key()
 
         with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_MGF):
@@ -1718,6 +1717,14 @@ def test_rsa_private_numbers(self):
         assert private_numbers.iqmp == 2
         assert private_numbers.public_numbers == public_numbers
 
+    def test_rsa_private_numbers_create_key(self, backend):
+        private_key = RSA_KEY_1024.private_key(backend)
+        assert private_key
+
+    def test_rsa_public_numbers_create_key(self, backend):
+        public_key = RSA_KEY_1024.public_numbers.public_key(backend)
+        assert public_key
+
     def test_public_numbers_invalid_types(self):
         with pytest.raises(TypeError):
             rsa.RSAPublicNumbers(e=None, n=15)
@@ -1812,19 +1819,19 @@ def test_invalid_public_numbers_argument_values(self, backend):
         # Test a modulus < 3.
 
         with pytest.raises(ValueError):
-            backend.load_rsa_public_numbers(rsa.RSAPublicNumbers(e=7, n=2))
+            rsa.RSAPublicNumbers(e=7, n=2).public_key(backend)
 
         # Test a public_exponent < 3
         with pytest.raises(ValueError):
-            backend.load_rsa_public_numbers(rsa.RSAPublicNumbers(e=1, n=15))
+            rsa.RSAPublicNumbers(e=1, n=15).public_key(backend)
 
         # Test a public_exponent > modulus
         with pytest.raises(ValueError):
-            backend.load_rsa_public_numbers(rsa.RSAPublicNumbers(e=17, n=15))
+            rsa.RSAPublicNumbers(e=17, n=15).public_key(backend)
 
         # Test a public_exponent that is not odd.
         with pytest.raises(ValueError):
-            backend.load_rsa_public_numbers(rsa.RSAPublicNumbers(e=16, n=15))
+            rsa.RSAPublicNumbers(e=16, n=15).public_key(backend)
 
     def test_invalid_private_numbers_argument_values(self, backend):
         # Start with p=3, q=11, private_exponent=3, public_exponent=7,
@@ -1833,221 +1840,195 @@ def test_invalid_private_numbers_argument_values(self, backend):
 
         # Test a modulus < 3.
         with pytest.raises(ValueError):
-            backend.load_rsa_private_numbers(
-                rsa.RSAPrivateNumbers(
-                    p=3,
-                    q=11,
-                    d=3,
-                    dmp1=1,
-                    dmq1=3,
-                    iqmp=2,
-                    public_numbers=rsa.RSAPublicNumbers(
-                        e=7,
-                        n=2
-                    )
+            rsa.RSAPrivateNumbers(
+                p=3,
+                q=11,
+                d=3,
+                dmp1=1,
+                dmq1=3,
+                iqmp=2,
+                public_numbers=rsa.RSAPublicNumbers(
+                    e=7,
+                    n=2
                 )
-            )
+            ).private_key(backend)
 
         # Test a modulus != p * q.
         with pytest.raises(ValueError):
-            backend.load_rsa_private_numbers(
-                rsa.RSAPrivateNumbers(
-                    p=3,
-                    q=11,
-                    d=3,
-                    dmp1=1,
-                    dmq1=3,
-                    iqmp=2,
-                    public_numbers=rsa.RSAPublicNumbers(
-                        e=7,
-                        n=35
-                    )
+            rsa.RSAPrivateNumbers(
+                p=3,
+                q=11,
+                d=3,
+                dmp1=1,
+                dmq1=3,
+                iqmp=2,
+                public_numbers=rsa.RSAPublicNumbers(
+                    e=7,
+                    n=35
                 )
-            )
+            ).private_key(backend)
 
         # Test a p > modulus.
         with pytest.raises(ValueError):
-            backend.load_rsa_private_numbers(
-                rsa.RSAPrivateNumbers(
-                    p=37,
-                    q=11,
-                    d=3,
-                    dmp1=1,
-                    dmq1=3,
-                    iqmp=2,
-                    public_numbers=rsa.RSAPublicNumbers(
-                        e=7,
-                        n=33
-                    )
+            rsa.RSAPrivateNumbers(
+                p=37,
+                q=11,
+                d=3,
+                dmp1=1,
+                dmq1=3,
+                iqmp=2,
+                public_numbers=rsa.RSAPublicNumbers(
+                    e=7,
+                    n=33
                 )
-            )
+            ).private_key(backend)
 
         # Test a q > modulus.
         with pytest.raises(ValueError):
-            backend.load_rsa_private_numbers(
-                rsa.RSAPrivateNumbers(
-                    p=3,
-                    q=37,
-                    d=3,
-                    dmp1=1,
-                    dmq1=3,
-                    iqmp=2,
-                    public_numbers=rsa.RSAPublicNumbers(
-                        e=7,
-                        n=33
-                    )
+            rsa.RSAPrivateNumbers(
+                p=3,
+                q=37,
+                d=3,
+                dmp1=1,
+                dmq1=3,
+                iqmp=2,
+                public_numbers=rsa.RSAPublicNumbers(
+                    e=7,
+                    n=33
                 )
-            )
+            ).private_key(backend)
 
         # Test a dmp1 > modulus.
         with pytest.raises(ValueError):
-            backend.load_rsa_private_numbers(
-                rsa.RSAPrivateNumbers(
-                    p=3,
-                    q=11,
-                    d=3,
-                    dmp1=35,
-                    dmq1=3,
-                    iqmp=2,
-                    public_numbers=rsa.RSAPublicNumbers(
-                        e=7,
-                        n=33
-                    )
+            rsa.RSAPrivateNumbers(
+                p=3,
+                q=11,
+                d=3,
+                dmp1=35,
+                dmq1=3,
+                iqmp=2,
+                public_numbers=rsa.RSAPublicNumbers(
+                    e=7,
+                    n=33
                 )
-            )
+            ).private_key(backend)
 
         # Test a dmq1 > modulus.
         with pytest.raises(ValueError):
-            backend.load_rsa_private_numbers(
-                rsa.RSAPrivateNumbers(
-                    p=3,
-                    q=11,
-                    d=3,
-                    dmp1=1,
-                    dmq1=35,
-                    iqmp=2,
-                    public_numbers=rsa.RSAPublicNumbers(
-                        e=7,
-                        n=33
-                    )
+            rsa.RSAPrivateNumbers(
+                p=3,
+                q=11,
+                d=3,
+                dmp1=1,
+                dmq1=35,
+                iqmp=2,
+                public_numbers=rsa.RSAPublicNumbers(
+                    e=7,
+                    n=33
                 )
-            )
+            ).private_key(backend)
 
         # Test an iqmp > modulus.
         with pytest.raises(ValueError):
-            backend.load_rsa_private_numbers(
-                rsa.RSAPrivateNumbers(
-                    p=3,
-                    q=11,
-                    d=3,
-                    dmp1=1,
-                    dmq1=3,
-                    iqmp=35,
-                    public_numbers=rsa.RSAPublicNumbers(
-                        e=7,
-                        n=33
-                    )
+            rsa.RSAPrivateNumbers(
+                p=3,
+                q=11,
+                d=3,
+                dmp1=1,
+                dmq1=3,
+                iqmp=35,
+                public_numbers=rsa.RSAPublicNumbers(
+                    e=7,
+                    n=33
                 )
-            )
+            ).private_key(backend)
 
         # Test a private_exponent > modulus
         with pytest.raises(ValueError):
-            backend.load_rsa_private_numbers(
-                rsa.RSAPrivateNumbers(
-                    p=3,
-                    q=11,
-                    d=37,
-                    dmp1=1,
-                    dmq1=3,
-                    iqmp=2,
-                    public_numbers=rsa.RSAPublicNumbers(
-                        e=7,
-                        n=33
-                    )
+            rsa.RSAPrivateNumbers(
+                p=3,
+                q=11,
+                d=37,
+                dmp1=1,
+                dmq1=3,
+                iqmp=2,
+                public_numbers=rsa.RSAPublicNumbers(
+                    e=7,
+                    n=33
                 )
-            )
+            ).private_key(backend)
 
         # Test a public_exponent < 3
         with pytest.raises(ValueError):
-            backend.load_rsa_private_numbers(
-                rsa.RSAPrivateNumbers(
-                    p=3,
-                    q=11,
-                    d=3,
-                    dmp1=1,
-                    dmq1=3,
-                    iqmp=2,
-                    public_numbers=rsa.RSAPublicNumbers(
-                        e=1,
-                        n=33
-                    )
+            rsa.RSAPrivateNumbers(
+                p=3,
+                q=11,
+                d=3,
+                dmp1=1,
+                dmq1=3,
+                iqmp=2,
+                public_numbers=rsa.RSAPublicNumbers(
+                    e=1,
+                    n=33
                 )
-            )
+            ).private_key(backend)
 
         # Test a public_exponent > modulus
         with pytest.raises(ValueError):
-            backend.load_rsa_private_numbers(
-                rsa.RSAPrivateNumbers(
-                    p=3,
-                    q=11,
-                    d=3,
-                    dmp1=1,
-                    dmq1=3,
-                    iqmp=35,
-                    public_numbers=rsa.RSAPublicNumbers(
-                        e=65537,
-                        n=33
-                    )
+            rsa.RSAPrivateNumbers(
+                p=3,
+                q=11,
+                d=3,
+                dmp1=1,
+                dmq1=3,
+                iqmp=35,
+                public_numbers=rsa.RSAPublicNumbers(
+                    e=65537,
+                    n=33
                 )
-            )
+            ).private_key(backend)
 
         # Test a public_exponent that is not odd.
         with pytest.raises(ValueError):
-            backend.load_rsa_private_numbers(
-                rsa.RSAPrivateNumbers(
-                    p=3,
-                    q=11,
-                    d=3,
-                    dmp1=1,
-                    dmq1=3,
-                    iqmp=2,
-                    public_numbers=rsa.RSAPublicNumbers(
-                        e=6,
-                        n=33
-                    )
+            rsa.RSAPrivateNumbers(
+                p=3,
+                q=11,
+                d=3,
+                dmp1=1,
+                dmq1=3,
+                iqmp=2,
+                public_numbers=rsa.RSAPublicNumbers(
+                    e=6,
+                    n=33
                 )
-            )
+            ).private_key(backend)
 
         # Test a dmp1 that is not odd.
         with pytest.raises(ValueError):
-            backend.load_rsa_private_numbers(
-                rsa.RSAPrivateNumbers(
-                    p=3,
-                    q=11,
-                    d=3,
-                    dmp1=2,
-                    dmq1=3,
-                    iqmp=2,
-                    public_numbers=rsa.RSAPublicNumbers(
-                        e=7,
-                        n=33
-                    )
+            rsa.RSAPrivateNumbers(
+                p=3,
+                q=11,
+                d=3,
+                dmp1=2,
+                dmq1=3,
+                iqmp=2,
+                public_numbers=rsa.RSAPublicNumbers(
+                    e=7,
+                    n=33
                 )
-            )
+            ).private_key(backend)
 
         # Test a dmq1 that is not odd.
         with pytest.raises(ValueError):
-            backend.load_rsa_private_numbers(
-                rsa.RSAPrivateNumbers(
-                    p=3,
-                    q=11,
-                    d=3,
-                    dmp1=1,
-                    dmq1=4,
-                    iqmp=2,
-                    public_numbers=rsa.RSAPublicNumbers(
-                        e=7,
-                        n=33
-                    )
+            rsa.RSAPrivateNumbers(
+                p=3,
+                q=11,
+                d=3,
+                dmp1=1,
+                dmq1=4,
+                iqmp=2,
+                public_numbers=rsa.RSAPublicNumbers(
+                    e=7,
+                    n=33
                 )
-            )
+            ).private_key(backend)
diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py
--- a/tests/hazmat/primitives/test_serialization.py
+++ b/tests/hazmat/primitives/test_serialization.py
@@ -23,13 +23,9 @@
 from cryptography.hazmat.primitives import interfaces
 from cryptography.hazmat.primitives.asymmetric import dsa
 from cryptography.hazmat.primitives.serialization import (
-    load_pem_pkcs8_private_key,
-    load_pem_traditional_openssl_private_key,
-    load_rsa_private_numbers,
-    load_rsa_public_numbers
+    load_pem_pkcs8_private_key, load_pem_traditional_openssl_private_key
 )
 
-from .fixtures_rsa import RSA_KEY_1024
 from .utils import _check_rsa_private_numbers, load_vectors_from_file
 from ...utils import raises_unsupported_algorithm
 
@@ -553,18 +549,3 @@ def test_load_bad_encryption_oid_key(self, key_file, password, backend):
                     pemfile.read().encode(), password, backend
                 )
             )
-
-
-@pytest.mark.rsa
-class TestLoadRSANumbers(object):
-    def test_load_private_numbers(self, backend):
-        private_key = load_rsa_private_numbers(RSA_KEY_1024, backend)
-        assert private_key
-        assert private_key.private_numbers()
-
-    def test_load_public_numbers(self, backend):
-        public_key = load_rsa_public_numbers(
-            RSA_KEY_1024.public_numbers, backend
-        )
-        assert public_key
-        assert public_key.public_numbers()
diff --git a/tests/hazmat/primitives/utils.py b/tests/hazmat/primitives/utils.py
--- a/tests/hazmat/primitives/utils.py
+++ b/tests/hazmat/primitives/utils.py
@@ -28,9 +28,6 @@
 from cryptography.hazmat.primitives.ciphers import Cipher
 from cryptography.hazmat.primitives.kdf.hkdf import HKDF, HKDFExpand
 from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
-from cryptography.hazmat.primitives.serialization import (
-    load_rsa_public_numbers
-)
 
 from ...utils import load_vectors_from_file
 
@@ -395,7 +392,7 @@ def rsa_verification_test(backend, params, hash_alg, pad_factory):
         e=params["public_exponent"],
         n=params["modulus"]
     )
-    public_key = load_rsa_public_numbers(public_numbers, backend)
+    public_key = public_numbers.public_key(backend)
     pad = pad_factory(params, hash_alg)
     verifier = public_key.verifier(
         binascii.unhexlify(params["s"]),