From 467072f7d50778f064f192b4e318c19c6cf98293 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sun, 25 Oct 2015 15:44:29 -0500 Subject: add support for encoding/decoding elliptic curve points Based on the work of @ronf in #2346. --- docs/hazmat/primitives/asymmetric/utils.rst | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'docs') diff --git a/docs/hazmat/primitives/asymmetric/utils.rst b/docs/hazmat/primitives/asymmetric/utils.rst index 07883598..825fe3c1 100644 --- a/docs/hazmat/primitives/asymmetric/utils.rst +++ b/docs/hazmat/primitives/asymmetric/utils.rst @@ -28,3 +28,44 @@ Asymmetric Utilities :param int s: The raw signature value ``s``. :return bytes: The encoded signature. + +.. function:: encode_ec_point(curve, x, y) + + .. versionadded:: 1.1 + + Encodes an elliptic curve point to a byte string as described in + _`SEC 1 v2.0` section 2.3.3. This function only supports uncompressed + points. + + :param curve: A :class:`EllipticCurve` provider. + + :param x: The x value of the point. + + :type: int or None + + :param int y: The y value of the point. + + :return bytes: The encoded point. + + :raises TypeError: Raised when curve is not an :class:`EllipticCurve`. + +.. function:: decode_ec_point(key_length, data) + + .. versionadded:: 1.1 + + Decodes a byte string as described in _`SEC 1 v2.0` section 2.3.3 to the + ``x`` and ``y`` integer values. This function only supports uncompressed + points. + + :param curve: A :class:`EllipticCurve` provider. + + :param bytes data: The serialized point byte string. + + :returns: The decoded tuple ``(x, y)``. + + :raises ValueError: Raised on invalid point type or data length. + + :raises TypeError: Raised when curve is not an :class:`EllipticCurve`. + + +.. _`SEC 1 v2.0`: http://www.secg.org/sec1-v2.pdf -- cgit v1.2.3 From d9cfab3fe2d9772d4f5812377a89d40624d20673 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 27 Oct 2015 09:02:36 +0900 Subject: fix some docs --- docs/hazmat/primitives/asymmetric/utils.rst | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'docs') diff --git a/docs/hazmat/primitives/asymmetric/utils.rst b/docs/hazmat/primitives/asymmetric/utils.rst index 825fe3c1..e67dd734 100644 --- a/docs/hazmat/primitives/asymmetric/utils.rst +++ b/docs/hazmat/primitives/asymmetric/utils.rst @@ -34,10 +34,12 @@ Asymmetric Utilities .. versionadded:: 1.1 Encodes an elliptic curve point to a byte string as described in - _`SEC 1 v2.0` section 2.3.3. This function only supports uncompressed + `SEC 1 v2.0`_ section 2.3.3. This function only supports uncompressed points. - :param curve: A :class:`EllipticCurve` provider. + :param curve: A + :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve` + provider. :param x: The x value of the point. @@ -47,17 +49,20 @@ Asymmetric Utilities :return bytes: The encoded point. - :raises TypeError: Raised when curve is not an :class:`EllipticCurve`. + :raises TypeError: Raised when curve is not an + :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve`. .. function:: decode_ec_point(key_length, data) .. versionadded:: 1.1 - Decodes a byte string as described in _`SEC 1 v2.0` section 2.3.3 to the + Decodes a byte string as described in `SEC 1 v2.0`_ section 2.3.3 to the ``x`` and ``y`` integer values. This function only supports uncompressed points. - :param curve: A :class:`EllipticCurve` provider. + :param curve: A + :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve` + provider. :param bytes data: The serialized point byte string. @@ -65,7 +70,8 @@ Asymmetric Utilities :raises ValueError: Raised on invalid point type or data length. - :raises TypeError: Raised when curve is not an :class:`EllipticCurve`. + :raises TypeError: Raised when curve is not an + :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve`. .. _`SEC 1 v2.0`: http://www.secg.org/sec1-v2.pdf -- cgit v1.2.3 From 3568563e0ecdec07606c8b5f3fed6eaea1fa95fd Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 27 Oct 2015 10:20:45 +0900 Subject: rst continues to be a mystery --- docs/hazmat/primitives/asymmetric/utils.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/hazmat/primitives/asymmetric/utils.rst b/docs/hazmat/primitives/asymmetric/utils.rst index e67dd734..829edb99 100644 --- a/docs/hazmat/primitives/asymmetric/utils.rst +++ b/docs/hazmat/primitives/asymmetric/utils.rst @@ -42,8 +42,7 @@ Asymmetric Utilities provider. :param x: The x value of the point. - - :type: int or None + :type x: int or `None` :param int y: The y value of the point. -- cgit v1.2.3 From e4150bcc07fb2c68e3c860c31766b4282bba8740 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 27 Oct 2015 12:29:58 +0900 Subject: remove support for null points, improve docs --- docs/hazmat/primitives/asymmetric/utils.rst | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'docs') diff --git a/docs/hazmat/primitives/asymmetric/utils.rst b/docs/hazmat/primitives/asymmetric/utils.rst index 829edb99..79d14dae 100644 --- a/docs/hazmat/primitives/asymmetric/utils.rst +++ b/docs/hazmat/primitives/asymmetric/utils.rst @@ -37,12 +37,11 @@ Asymmetric Utilities `SEC 1 v2.0`_ section 2.3.3. This function only supports uncompressed points. - :param curve: A + :param curve: An :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve` - provider. + instance. - :param x: The x value of the point. - :type x: int or `None` + :param int x: The x value of the point. :param int y: The y value of the point. @@ -59,9 +58,9 @@ Asymmetric Utilities ``x`` and ``y`` integer values. This function only supports uncompressed points. - :param curve: A + :param curve: An :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve` - provider. + instance. :param bytes data: The serialized point byte string. -- cgit v1.2.3 From 13d4e74b13832b495ddfdff043376144d8ada66a Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 27 Oct 2015 16:47:55 +0900 Subject: modify approach to use EllipticCurvePublicNumbers methods --- docs/hazmat/primitives/asymmetric/ec.rst | 32 ++++++++++++++++++++ docs/hazmat/primitives/asymmetric/utils.rst | 45 ----------------------------- 2 files changed, 32 insertions(+), 45 deletions(-) (limited to 'docs') diff --git a/docs/hazmat/primitives/asymmetric/ec.rst b/docs/hazmat/primitives/asymmetric/ec.rst index 90e73711..c1619dd0 100644 --- a/docs/hazmat/primitives/asymmetric/ec.rst +++ b/docs/hazmat/primitives/asymmetric/ec.rst @@ -122,6 +122,37 @@ Elliptic Curve Signature Algorithms :returns: A new instance of a :class:`EllipticCurvePublicKey` provider. + .. method:: encode_point() + + .. versionadded:: 1.1 + + Encodes an elliptic curve point to a byte string as described in + `SEC 1 v2.0`_ section 2.3.3. This method only supports uncompressed + points. + + :return bytes: The encoded point. + + .. classmethod:: from_encoded_point(curve, data) + + .. versionadded:: 1.1 + + Decodes a byte string as described in `SEC 1 v2.0`_ section 2.3.3 and + returns an :class:`EllipticCurvePublicNumbers`. This method only + supports uncompressed points. + + :param curve: An + :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve` + instance. + + :param bytes data: The serialized point byte string. + + :returns: An :class:`EllipticCurvePublicNumbers` instance. + + :raises ValueError: Raised on invalid point type or data length. + + :raises TypeError: Raised when curve is not an + :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve`. + Elliptic Curve Key Exchange algorithm ------------------------------------- @@ -478,3 +509,4 @@ Key Interfaces .. _`ECDSA`: https://en.wikipedia.org/wiki/ECDSA .. _`EdDSA`: https://en.wikipedia.org/wiki/EdDSA .. _`forward secrecy`: https://en.wikipedia.org/wiki/Forward_secrecy +.. _`SEC 1 v2.0`: http://www.secg.org/sec1-v2.pdf diff --git a/docs/hazmat/primitives/asymmetric/utils.rst b/docs/hazmat/primitives/asymmetric/utils.rst index 79d14dae..07883598 100644 --- a/docs/hazmat/primitives/asymmetric/utils.rst +++ b/docs/hazmat/primitives/asymmetric/utils.rst @@ -28,48 +28,3 @@ Asymmetric Utilities :param int s: The raw signature value ``s``. :return bytes: The encoded signature. - -.. function:: encode_ec_point(curve, x, y) - - .. versionadded:: 1.1 - - Encodes an elliptic curve point to a byte string as described in - `SEC 1 v2.0`_ section 2.3.3. This function only supports uncompressed - points. - - :param curve: An - :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve` - instance. - - :param int x: The x value of the point. - - :param int y: The y value of the point. - - :return bytes: The encoded point. - - :raises TypeError: Raised when curve is not an - :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve`. - -.. function:: decode_ec_point(key_length, data) - - .. versionadded:: 1.1 - - Decodes a byte string as described in `SEC 1 v2.0`_ section 2.3.3 to the - ``x`` and ``y`` integer values. This function only supports uncompressed - points. - - :param curve: An - :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve` - instance. - - :param bytes data: The serialized point byte string. - - :returns: The decoded tuple ``(x, y)``. - - :raises ValueError: Raised on invalid point type or data length. - - :raises TypeError: Raised when curve is not an - :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve`. - - -.. _`SEC 1 v2.0`: http://www.secg.org/sec1-v2.pdf -- cgit v1.2.3