aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/hazmat/backends/interfaces.rst5
-rw-r--r--docs/hazmat/primitives/asymmetric/ec.rst7
-rw-r--r--src/cryptography/hazmat/backends/interfaces.py4
-rw-r--r--src/cryptography/hazmat/backends/multibackend.py6
-rw-r--r--src/cryptography/hazmat/backends/openssl/backend.py13
-rw-r--r--src/cryptography/hazmat/primitives/asymmetric/ec.py11
-rw-r--r--tests/hazmat/backends/test_multibackend.py6
7 files changed, 28 insertions, 24 deletions
diff --git a/docs/hazmat/backends/interfaces.rst b/docs/hazmat/backends/interfaces.rst
index 942a359c..42e07d39 100644
--- a/docs/hazmat/backends/interfaces.rst
+++ b/docs/hazmat/backends/interfaces.rst
@@ -422,14 +422,15 @@ A specific ``backend`` may provide one or more of these interfaces.
:returns: An instance of
:class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
- .. method:: derive_elliptic_curve_public_point(private_value, curve)
+ .. method:: derive_elliptic_curve_private_key(private_value, curve)
:param private_value: A secret scalar value.
:param curve: An instance of
:class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve`.
- :returns: A tuple (x, y).
+ :returns: An instance of
+ :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`.
.. class:: PEMSerializationBackend
diff --git a/docs/hazmat/primitives/asymmetric/ec.rst b/docs/hazmat/primitives/asymmetric/ec.rst
index 33ebee0f..27debfa1 100644
--- a/docs/hazmat/primitives/asymmetric/ec.rst
+++ b/docs/hazmat/primitives/asymmetric/ec.rst
@@ -20,13 +20,14 @@ Elliptic curve cryptography
:returns: A new instance of :class:`EllipticCurvePrivateKey`.
-.. function:: derive_private_key(secret, curve, backend)
+.. function:: derive_private_key(private_value, curve, backend)
.. versionadded:: 1.6
- Derive a private key from ``secret`` on ``curve`` for use with ``backend``.
+ Derive a private key from ``private_value`` on ``curve`` for use with
+ ``backend``.
- :param int secret: The secret scalar value.
+ :param int private_value: The secret scalar value.
:param curve: An instance of :class:`EllipticCurve`.
diff --git a/src/cryptography/hazmat/backends/interfaces.py b/src/cryptography/hazmat/backends/interfaces.py
index 7417f6ca..e15a7ca4 100644
--- a/src/cryptography/hazmat/backends/interfaces.py
+++ b/src/cryptography/hazmat/backends/interfaces.py
@@ -222,9 +222,9 @@ class EllipticCurveBackend(object):
"""
@abc.abstractmethod
- def derive_elliptic_curve_public_point(self, private_value, curve):
+ def derive_elliptic_curve_private_key(self, private_value, curve):
"""
- Compute the public key point (x, y) given the private value and curve.
+ Compute the private key given the private value and curve.
"""
diff --git a/src/cryptography/hazmat/backends/multibackend.py b/src/cryptography/hazmat/backends/multibackend.py
index 36a83537..bcd9c520 100644
--- a/src/cryptography/hazmat/backends/multibackend.py
+++ b/src/cryptography/hazmat/backends/multibackend.py
@@ -279,11 +279,11 @@ class MultiBackend(object):
_Reasons.UNSUPPORTED_ELLIPTIC_CURVE
)
- def derive_elliptic_curve_public_point(self, private_value, curve):
+ def derive_elliptic_curve_private_key(self, private_value, curve):
for b in self._filtered_backends(EllipticCurveBackend):
try:
- return b.derive_elliptic_curve_public_point(private_value,
- curve)
+ return b.derive_elliptic_curve_private_key(private_value,
+ curve)
except UnsupportedAlgorithm:
continue
diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py
index b8e407b0..4a341fc2 100644
--- a/src/cryptography/hazmat/backends/openssl/backend.py
+++ b/src/cryptography/hazmat/backends/openssl/backend.py
@@ -1386,7 +1386,7 @@ class Backend(object):
return _EllipticCurvePublicKey(self, ec_cdata, evp_pkey)
- def derive_elliptic_curve_public_point(self, private_value, curve):
+ def derive_elliptic_curve_private_key(self, private_value, curve):
curve_nid = self._elliptic_curve_to_nid(curve)
ec_cdata = self._lib.EC_KEY_new_by_curve_name(curve_nid)
@@ -1415,10 +1415,15 @@ class Backend(object):
res = get_func(group, point, bn_x, bn_y, bn_ctx)
self.openssl_assert(res == 1)
- point_x = self._bn_to_int(bn_x)
- point_y = self._bn_to_int(bn_y)
+ res = self._lib.EC_KEY_set_public_key(ec_cdata, point)
+ self.openssl_assert(res == 1)
+ res = self._lib.EC_KEY_set_private_key(
+ ec_cdata, self._int_to_bn(private_value))
+ self.openssl_assert(res == 1)
- return point_x, point_y
+ evp_pkey = self._ec_cdata_to_evp_pkey(ec_cdata)
+
+ return _EllipticCurvePrivateKey(self, ec_cdata, evp_pkey)
def elliptic_curve_exchange_algorithm_supported(self, algorithm, curve):
return (
diff --git a/src/cryptography/hazmat/primitives/asymmetric/ec.py b/src/cryptography/hazmat/primitives/asymmetric/ec.py
index 1005ccd6..023a2d15 100644
--- a/src/cryptography/hazmat/primitives/asymmetric/ec.py
+++ b/src/cryptography/hazmat/primitives/asymmetric/ec.py
@@ -253,17 +253,14 @@ def generate_private_key(curve, backend):
return backend.generate_elliptic_curve_private_key(curve)
-def derive_private_key(secret, curve, backend):
- if not isinstance(secret, six.integer_types):
- raise TypeError("secret must be an integer type.")
+def derive_private_key(private_value, curve, backend):
+ if not isinstance(private_value, six.integer_types):
+ raise TypeError("private_value must be an integer type.")
if not isinstance(curve, EllipticCurve):
raise TypeError("curve must provide the EllipticCurve interface.")
- x, y = backend.derive_elliptic_curve_public_point(secret, curve)
- public_numbers = EllipticCurvePublicNumbers(x, y, curve)
- private_numbers = EllipticCurvePrivateNumbers(secret, public_numbers)
- return private_numbers.private_key(backend)
+ return backend.derive_elliptic_curve_private_key(private_value, curve)
class EllipticCurvePublicNumbers(object):
diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py
index 7ffc4236..ea08e17b 100644
--- a/tests/hazmat/backends/test_multibackend.py
+++ b/tests/hazmat/backends/test_multibackend.py
@@ -185,7 +185,7 @@ class DummyEllipticCurveBackend(object):
self.elliptic_curve_supported(curve)
)
- def derive_elliptic_curve_public_point(self, private_value, curve):
+ def derive_elliptic_curve_private_key(self, private_value, curve):
if not self.elliptic_curve_supported(curve):
raise UnsupportedAlgorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE)
@@ -515,9 +515,9 @@ class TestMultiBackend(object):
)
with pytest.raises(UnsupportedAlgorithm):
- backend.derive_elliptic_curve_public_point(123, DummyCurve())
+ backend.derive_elliptic_curve_private_key(123, DummyCurve())
- assert backend.derive_elliptic_curve_public_point(
+ assert backend.derive_elliptic_curve_private_key(
123, ec.SECT283K1()) is None
def test_pem_serialization_backend(self):