fastecdsa


Namefastecdsa JSON
Version 2.3.2 PyPI version JSON
download
home_page
SummaryFast elliptic curve digital signatures
upload_time2024-02-22 19:42:55
maintainer
docs_urlNone
author
requires_python>=3.7
licenseThis is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to <http://unlicense.org/>
keywords elliptic curve cryptography ecdsa ecc
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            fastecdsa
=========
.. image:: https://img.shields.io/pypi/v/fastecdsa.svg
    :target: https://pypi.org/project/fastecdsa/
    :alt: PyPI

.. image:: https://travis-ci.com/AntonKueltz/fastecdsa.svg?branch=master
    :target: https://travis-ci.com/AntonKueltz/fastecdsa
    :alt: Travis CI

.. image:: https://readthedocs.org/projects/fastecdsa/badge/?version=stable
    :target: https://fastecdsa.readthedocs.io/en/stable/?badge=stable
    :alt: Documentation Status

.. contents::

About
-----
This is a python package for doing fast elliptic curve cryptography, specifically
digital signatures.

Security
--------
There is no nonce reuse, no branching on secret material,
and all points are validated before any operations are performed on them. Timing side challenges
are mitigated via Montgomery point multiplication. Nonces are generated per RFC6979_. The default
curve used throughout the package is P256 which provides 128 bits of security. If you require a
higher level of security you can specify the curve parameter in a method to use a curve over a
bigger field e.g. P384. All that being said, crypto is tricky and I'm not beyond making mistakes.
Please use a more established and reviewed library for security critical applications. Open an
issue or email me if you see any security issue or risk with this library.

Python Versions Supported
-------------------------
The initial release of this package was targeted at python2.7. Earlier versions may work but have
no guarantee of correctness or stability. As of release 1.2.1+ python3 is supported as well. Due to
python2's EOL on January 1st 2020 release 2.x of this package only supports python3.5+.

Operating Systems Supported
---------------------------
This package is targeted at the Linux and MacOS operating systems. Due to the the dependency on
the GMP C library building this package on Windows is difficult and no official support or
distributions are provided for Windows OSes. See issue11_ for what users have done to get things
building.

Supported Primitives
--------------------
Curves over Prime Fields
~~~~~~~~~~~~~~~~~~~~~~~~

+---------------------------+-----------------------------------------+-------------+
| Name                      | Class                                   | Proposed By |
+===========================+=========================================+=============+
| P192 / secp192r1          | :code:`fastecdsa.curve.P192`            | NIST / NSA  |
+---------------------------+-----------------------------------------+-------------+
| P224 / secp224r1          | :code:`fastecdsa.curve.P224`            | NIST / NSA  |
+---------------------------+-----------------------------------------+-------------+
| P256 / secp256r1          | :code:`fastecdsa.curve.P256`            | NIST / NSA  |
+---------------------------+-----------------------------------------+-------------+
| P384 / secp384r1          | :code:`fastecdsa.curve.P384`            | NIST / NSA  |
+---------------------------+-----------------------------------------+-------------+
| P521 / secp521r1          | :code:`fastecdsa.curve.P521`            | NIST / NSA  |
+---------------------------+-----------------------------------------+-------------+
| secp192k1                 | :code:`fastecdsa.curve.secp192k1`       | Certicom    |
+---------------------------+-----------------------------------------+-------------+
| secp224k1                 | :code:`fastecdsa.curve.secp224k1`       | Certicom    |
+---------------------------+-----------------------------------------+-------------+
| secp256k1 (bitcoin curve) | :code:`fastecdsa.curve.secp256k1`       | Certicom    |
+---------------------------+-----------------------------------------+-------------+
| brainpoolP160r1           | :code:`fastecdsa.curve.brainpoolP160r1` | BSI         |
+---------------------------+-----------------------------------------+-------------+
| brainpoolP192r1           | :code:`fastecdsa.curve.brainpoolP192r1` | BSI         |
+---------------------------+-----------------------------------------+-------------+
| brainpoolP224r1           | :code:`fastecdsa.curve.brainpoolP224r1` | BSI         |
+---------------------------+-----------------------------------------+-------------+
| brainpoolP256r1           | :code:`fastecdsa.curve.brainpoolP256r1` | BSI         |
+---------------------------+-----------------------------------------+-------------+
| brainpoolP320r1           | :code:`fastecdsa.curve.brainpoolP320r1` | BSI         |
+---------------------------+-----------------------------------------+-------------+
| brainpoolP384r1           | :code:`fastecdsa.curve.brainpoolP384r1` | BSI         |
+---------------------------+-----------------------------------------+-------------+
| brainpoolP512r1           | :code:`fastecdsa.curve.brainpoolP512r1` | BSI         |
+---------------------------+-----------------------------------------+-------------+

Arbitrary Curves
~~~~~~~~~~~~~~~~
As of version 1.5.1 construction of arbitrary curves in Weierstrass form
(:code:`y^2 = x^3 + ax + b (mod p)`) is supported. I advise against using custom curves for any
security critical applications. It's up to you to make sure that the parameters you pass here are
correct, no validation of the base point is done, and in general no sanity checks are done. Use
at your own risk.

.. code:: python

    from fastecdsa.curve import Curve
    curve = Curve(
        name,  # (str): The name of the curve
        p,  # (long): The value of p in the curve equation.
        a,  # (long): The value of a in the curve equation.
        b,  # (long): The value of b in the curve equation.
        q,  # (long): The order of the base point of the curve.
        gx,  # (long): The x coordinate of the base point of the curve.
        gy,  # (long): The y coordinate of the base point of the curve.
        oid  # (str): The object identifier of the curve (optional).
    )

Hash Functions
~~~~~~~~~~~~~~
Any hash function in the :code:`hashlib` module (:code:`md5, sha1, sha224, sha256, sha384, sha512`)
will work, as will any hash function that implements the same interface / core functionality as the
those in :code:`hashlib`. For instance, if you wish to use SHA3 as the hash function the
:code:`pysha3` package will work with this library as long as it is at version >=1.0b1 (as previous
versions didn't work with the :code:`hmac` module which is used in nonce generation). Note
that :code:`sha3_224, sha3_256, sha3_384, sha3_512` are all in :code:`hashlib` as of python3.6.

Performance
-----------

Curves over Prime Fields
~~~~~~~~~~~~~~~~~~~~~~~~
Currently it does elliptic curve arithmetic significantly faster than the :code:`ecdsa`
package. You can see the times for 1,000 signature and verification operations over
various curves below. These were run on an early 2014 MacBook Air with a 1.4 GHz Intel
Core i5.

+-----------+------------------------+--------------------+---------+
| Curve     | :code:`fastecdsa` time | :code:`ecdsa` time | Speedup |
+-----------+------------------------+--------------------+---------+
| P192      | 3.62s                  | 1m35.49s           | ~26x    |
+-----------+------------------------+--------------------+---------+
| P224      | 4.50s                  | 2m13.42s           | ~29x    |
+-----------+------------------------+--------------------+---------+
| P256      | 6.15s                  | 2m52.43s           | ~28x    |
+-----------+------------------------+--------------------+---------+
| P384      | 12.11s                 | 6m21.01s           | ~31x    |
+-----------+------------------------+--------------------+---------+
| P521      | 22.21s                 | 11m39.53s          | ~31x    |
+-----------+------------------------+--------------------+---------+
| secp256k1 | 5.92s                  | 2m57.19s           | ~30x    |
+-----------+------------------------+--------------------+---------+

Benchmarking
~~~~~~~~~~~~
If you'd like to benchmark performance on your machine you can do so using the command:

.. code:: bash

    $ python setup.py benchmark

This will use the :code:`timeit` module to benchmark 1000 signature and verification operations
for each curve supported by this package. Alternatively, if you have not cloned the repo but
have installed the package via e.g. :code:`pip` you can use the following command:

.. code:: bash

    $ python -m fastecdsa.benchmark

Installing
----------
You can use pip: :code:`$ pip install fastecdsa` or clone the repo and use
:code:`$ python setup.py install`. Note that you need to have a C compiler.
You  also need to have GMP_ on your system as the underlying
C code in this package includes the :code:`gmp.h` header (and links against gmp
via the :code:`-lgmp` flag). You can install all dependencies as follows:

apt
~~~

.. code:: bash

    $ sudo apt-get install python3-dev libgmp3-dev

yum
~~~

.. code:: bash

    $ sudo yum install python-devel gmp-devel

Usage
-----
Generating Keys
~~~~~~~~~~~~~~~
You can use this package to generate keys if you like. Recall that private keys on elliptic curves
are integers, and public keys are points i.e. integer pairs.

.. code:: python

    from fastecdsa import keys, curve

    """The reason there are two ways to generate a keypair is that generating the public key requires
    a point multiplication, which can be expensive. That means sometimes you may want to delay
    generating the public key until it is actually needed."""

    # generate a keypair (i.e. both keys) for curve P256
    priv_key, pub_key = keys.gen_keypair(curve.P256)

    # generate a private key for curve P256
    priv_key = keys.gen_private_key(curve.P256)

    # get the public key corresponding to the private key we just generated
    pub_key = keys.get_public_key(priv_key, curve.P256)


Signing and Verifying
~~~~~~~~~~~~~~~~~~~~~
Some basic usage is shown below:

.. code:: python

    from fastecdsa import curve, ecdsa, keys
    from hashlib import sha384

    m = "a message to sign via ECDSA"  # some message

    ''' use default curve and hash function (P256 and SHA2) '''
    private_key = keys.gen_private_key(curve.P256)
    public_key = keys.get_public_key(private_key, curve.P256)
    # standard signature, returns two integers
    r, s = ecdsa.sign(m, private_key)
    # should return True as the signature we just generated is valid.
    valid = ecdsa.verify((r, s), m, public_key)

    ''' specify a different hash function to use with ECDSA '''
    r, s = ecdsa.sign(m, private_key, hashfunc=sha384)
    valid = ecdsa.verify((r, s), m, public_key, hashfunc=sha384)

    ''' specify a different curve to use with ECDSA '''
    private_key = keys.gen_private_key(curve.P224)
    public_key = keys.get_public_key(private_key, curve.P224)
    r, s = ecdsa.sign(m, private_key, curve=curve.P224)
    valid = ecdsa.verify((r, s), m, public_key, curve=curve.P224)

    ''' using SHA3 via pysha3>=1.0b1 package '''
    import sha3  # pip install [--user] pysha3==1.0b1
    from hashlib import sha3_256
    private_key, public_key = keys.gen_keypair(curve.P256)
    r, s = ecdsa.sign(m, private_key, hashfunc=sha3_256)
    valid = ecdsa.verify((r, s), m, public_key, hashfunc=sha3_256)

Arbitrary Elliptic Curve Arithmetic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The :code:`Point` class allows arbitrary arithmetic to be performed over curves. The two main
operations are point addition and point multiplication (by a scalar) which can be done via the
standard python operators (:code:`+` and :code:`*` respectively):

.. code:: python

    # example taken from the document below (section 4.3.2):
    # https://koclab.cs.ucsb.edu/teaching/cren/docs/w02/nist-routines.pdf

    from fastecdsa.curve import P256
    from fastecdsa.point import Point

    xs = 0xde2444bebc8d36e682edd27e0f271508617519b3221a8fa0b77cab3989da97c9
    ys = 0xc093ae7ff36e5380fc01a5aad1e66659702de80f53cec576b6350b243042a256
    S = Point(xs, ys, curve=P256)

    xt = 0x55a8b00f8da1d44e62f6b3b25316212e39540dc861c89575bb8cf92e35e0986b
    yt = 0x5421c3209c2d6c704835d82ac4c3dd90f61a8a52598b9e7ab656e9d8c8b24316
    T = Point(xt, yt, curve=P256)

    # Point Addition
    R = S + T

    # Point Subtraction: (xs, ys) - (xt, yt) = (xs, ys) + (xt, -yt)
    R = S - T

    # Point Doubling
    R = S + S  # produces the same value as the operation below
    R = 2 * S  # S * 2 works fine too i.e. order doesn't matter

    d = 0xc51e4753afdec1e6b6c6a5b992f43f8dd0c7a8933072708b6522468b2ffb06fd

    # Scalar Multiplication
    R = d * S  # S * d works fine too i.e. order doesn't matter

    e = 0xd37f628ece72a462f0145cbefe3f0b355ee8332d37acdd83a358016aea029db7

    # Joint Scalar Multiplication
    R = d * S + e * T

Importing and Exporting Keys
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can also export keys as files, ASN.1 encoded and formatted per RFC5480_ and RFC5915_. Both
private keys and public keys can be exported as follows:

.. code:: python

    from fastecdsa.curve import P256
    from fastecdsa.keys import export_key, gen_keypair

    d, Q = gen_keypair(P256)
    # save the private key to disk
    export_key(d, curve=P256, filepath='/path/to/exported/p256.key')
    # save the public key to disk
    export_key(Q, curve=P256, filepath='/path/to/exported/p256.pub')

Keys stored in this format can also be imported. The import function will figure out if the key
is a public or private key and parse it accordingly:

.. code:: python

    from fastecdsa.keys import import_key

    # if the file is a private key then parsed_d is a long and parsed_Q is a Point object
    # if the file is a public key then parsed_d will be None
    parsed_d, parsed_Q = import_key('/path/to/file.key')

Other encoding formats can also be specified, such as SEC1_ for public keys. This is done using
classes found in the :code:`fastecdsa.encoding` package, and passing them as keyword args to
the key functions:

.. code:: python

    from fastecdsa.curve import P256
    from fastecdsa.encoding.sec1 import SEC1Encoder
    from fastecdsa.keys import export_key, gen_keypair, import_key

    _, Q = gen_keypair(P256)
    export_key(Q, curve=P256, filepath='/path/to/p256.key', encoder=SEC1Encoder)
    parsed_Q = import_key('/path/to/p256.key', curve=P256, public=True, decoder=SEC1Encoder)

Encoding Signatures
~~~~~~~~~~~~~~~~~~~
DER encoding of ECDSA signatures as defined in RFC2459_ is also supported. The
:code:`fastecdsa.encoding.der` provides the :code:`DEREncoder` class which encodes signatures:

.. code:: python

    from fastecdsa.encoding.der import DEREncoder

    r, s = 0xdeadc0de, 0xbadc0de
    encoded = DEREncoder.encode_signature(r, s)
    decoded_r, decoded_s = DEREncoder.decode_signature(encoded)

Acknowledgements
----------------
Thanks to those below for contributing improvements:

- boneyard93501
- clouds56
- m-kus
- sirk390
- targon
- NotStatilko
- bbbrumley
- luinxz
- JJChiDguez
- J08nY
- trevor-crypto
- sylvainpelissier
- akaIDIOT 

.. _issue11: https://github.com/AntonKueltz/fastecdsa/issues/11
.. _GMP: https://gmplib.org/
.. _RFC2459: https://tools.ietf.org/html/rfc2459
.. _RFC5480: https://tools.ietf.org/html/rfc5480
.. _RFC5915: https://tools.ietf.org/html/rfc5915
.. _RFC6979: https://tools.ietf.org/html/rfc6979
.. _SEC1: http://www.secg.org/sec1-v2.pdf

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "fastecdsa",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "elliptic,curve,cryptography,ecdsa,ecc",
    "author": "",
    "author_email": "Anton Kueltz <kueltz.anton@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/fc/21/d5585856169c595d99a596dd8000afae40053f9f5c955d8ec8fb2ec3247c/fastecdsa-2.3.2.tar.gz",
    "platform": null,
    "description": "fastecdsa\n=========\n.. image:: https://img.shields.io/pypi/v/fastecdsa.svg\n    :target: https://pypi.org/project/fastecdsa/\n    :alt: PyPI\n\n.. image:: https://travis-ci.com/AntonKueltz/fastecdsa.svg?branch=master\n    :target: https://travis-ci.com/AntonKueltz/fastecdsa\n    :alt: Travis CI\n\n.. image:: https://readthedocs.org/projects/fastecdsa/badge/?version=stable\n    :target: https://fastecdsa.readthedocs.io/en/stable/?badge=stable\n    :alt: Documentation Status\n\n.. contents::\n\nAbout\n-----\nThis is a python package for doing fast elliptic curve cryptography, specifically\ndigital signatures.\n\nSecurity\n--------\nThere is no nonce reuse, no branching on secret material,\nand all points are validated before any operations are performed on them. Timing side challenges\nare mitigated via Montgomery point multiplication. Nonces are generated per RFC6979_. The default\ncurve used throughout the package is P256 which provides 128 bits of security. If you require a\nhigher level of security you can specify the curve parameter in a method to use a curve over a\nbigger field e.g. P384. All that being said, crypto is tricky and I'm not beyond making mistakes.\nPlease use a more established and reviewed library for security critical applications. Open an\nissue or email me if you see any security issue or risk with this library.\n\nPython Versions Supported\n-------------------------\nThe initial release of this package was targeted at python2.7. Earlier versions may work but have\nno guarantee of correctness or stability. As of release 1.2.1+ python3 is supported as well. Due to\npython2's EOL on January 1st 2020 release 2.x of this package only supports python3.5+.\n\nOperating Systems Supported\n---------------------------\nThis package is targeted at the Linux and MacOS operating systems. Due to the the dependency on\nthe GMP C library building this package on Windows is difficult and no official support or\ndistributions are provided for Windows OSes. See issue11_ for what users have done to get things\nbuilding.\n\nSupported Primitives\n--------------------\nCurves over Prime Fields\n~~~~~~~~~~~~~~~~~~~~~~~~\n\n+---------------------------+-----------------------------------------+-------------+\n| Name                      | Class                                   | Proposed By |\n+===========================+=========================================+=============+\n| P192 / secp192r1          | :code:`fastecdsa.curve.P192`            | NIST / NSA  |\n+---------------------------+-----------------------------------------+-------------+\n| P224 / secp224r1          | :code:`fastecdsa.curve.P224`            | NIST / NSA  |\n+---------------------------+-----------------------------------------+-------------+\n| P256 / secp256r1          | :code:`fastecdsa.curve.P256`            | NIST / NSA  |\n+---------------------------+-----------------------------------------+-------------+\n| P384 / secp384r1          | :code:`fastecdsa.curve.P384`            | NIST / NSA  |\n+---------------------------+-----------------------------------------+-------------+\n| P521 / secp521r1          | :code:`fastecdsa.curve.P521`            | NIST / NSA  |\n+---------------------------+-----------------------------------------+-------------+\n| secp192k1                 | :code:`fastecdsa.curve.secp192k1`       | Certicom    |\n+---------------------------+-----------------------------------------+-------------+\n| secp224k1                 | :code:`fastecdsa.curve.secp224k1`       | Certicom    |\n+---------------------------+-----------------------------------------+-------------+\n| secp256k1 (bitcoin curve) | :code:`fastecdsa.curve.secp256k1`       | Certicom    |\n+---------------------------+-----------------------------------------+-------------+\n| brainpoolP160r1           | :code:`fastecdsa.curve.brainpoolP160r1` | BSI         |\n+---------------------------+-----------------------------------------+-------------+\n| brainpoolP192r1           | :code:`fastecdsa.curve.brainpoolP192r1` | BSI         |\n+---------------------------+-----------------------------------------+-------------+\n| brainpoolP224r1           | :code:`fastecdsa.curve.brainpoolP224r1` | BSI         |\n+---------------------------+-----------------------------------------+-------------+\n| brainpoolP256r1           | :code:`fastecdsa.curve.brainpoolP256r1` | BSI         |\n+---------------------------+-----------------------------------------+-------------+\n| brainpoolP320r1           | :code:`fastecdsa.curve.brainpoolP320r1` | BSI         |\n+---------------------------+-----------------------------------------+-------------+\n| brainpoolP384r1           | :code:`fastecdsa.curve.brainpoolP384r1` | BSI         |\n+---------------------------+-----------------------------------------+-------------+\n| brainpoolP512r1           | :code:`fastecdsa.curve.brainpoolP512r1` | BSI         |\n+---------------------------+-----------------------------------------+-------------+\n\nArbitrary Curves\n~~~~~~~~~~~~~~~~\nAs of version 1.5.1 construction of arbitrary curves in Weierstrass form\n(:code:`y^2 = x^3 + ax + b (mod p)`) is supported. I advise against using custom curves for any\nsecurity critical applications. It's up to you to make sure that the parameters you pass here are\ncorrect, no validation of the base point is done, and in general no sanity checks are done. Use\nat your own risk.\n\n.. code:: python\n\n    from fastecdsa.curve import Curve\n    curve = Curve(\n        name,  # (str): The name of the curve\n        p,  # (long): The value of p in the curve equation.\n        a,  # (long): The value of a in the curve equation.\n        b,  # (long): The value of b in the curve equation.\n        q,  # (long): The order of the base point of the curve.\n        gx,  # (long): The x coordinate of the base point of the curve.\n        gy,  # (long): The y coordinate of the base point of the curve.\n        oid  # (str): The object identifier of the curve (optional).\n    )\n\nHash Functions\n~~~~~~~~~~~~~~\nAny hash function in the :code:`hashlib` module (:code:`md5, sha1, sha224, sha256, sha384, sha512`)\nwill work, as will any hash function that implements the same interface / core functionality as the\nthose in :code:`hashlib`. For instance, if you wish to use SHA3 as the hash function the\n:code:`pysha3` package will work with this library as long as it is at version >=1.0b1 (as previous\nversions didn't work with the :code:`hmac` module which is used in nonce generation). Note\nthat :code:`sha3_224, sha3_256, sha3_384, sha3_512` are all in :code:`hashlib` as of python3.6.\n\nPerformance\n-----------\n\nCurves over Prime Fields\n~~~~~~~~~~~~~~~~~~~~~~~~\nCurrently it does elliptic curve arithmetic significantly faster than the :code:`ecdsa`\npackage. You can see the times for 1,000 signature and verification operations over\nvarious curves below. These were run on an early 2014 MacBook Air with a 1.4 GHz Intel\nCore i5.\n\n+-----------+------------------------+--------------------+---------+\n| Curve     | :code:`fastecdsa` time | :code:`ecdsa` time | Speedup |\n+-----------+------------------------+--------------------+---------+\n| P192      | 3.62s                  | 1m35.49s           | ~26x    |\n+-----------+------------------------+--------------------+---------+\n| P224      | 4.50s                  | 2m13.42s           | ~29x    |\n+-----------+------------------------+--------------------+---------+\n| P256      | 6.15s                  | 2m52.43s           | ~28x    |\n+-----------+------------------------+--------------------+---------+\n| P384      | 12.11s                 | 6m21.01s           | ~31x    |\n+-----------+------------------------+--------------------+---------+\n| P521      | 22.21s                 | 11m39.53s          | ~31x    |\n+-----------+------------------------+--------------------+---------+\n| secp256k1 | 5.92s                  | 2m57.19s           | ~30x    |\n+-----------+------------------------+--------------------+---------+\n\nBenchmarking\n~~~~~~~~~~~~\nIf you'd like to benchmark performance on your machine you can do so using the command:\n\n.. code:: bash\n\n    $ python setup.py benchmark\n\nThis will use the :code:`timeit` module to benchmark 1000 signature and verification operations\nfor each curve supported by this package. Alternatively, if you have not cloned the repo but\nhave installed the package via e.g. :code:`pip` you can use the following command:\n\n.. code:: bash\n\n    $ python -m fastecdsa.benchmark\n\nInstalling\n----------\nYou can use pip: :code:`$ pip install fastecdsa` or clone the repo and use\n:code:`$ python setup.py install`. Note that you need to have a C compiler.\nYou  also need to have GMP_ on your system as the underlying\nC code in this package includes the :code:`gmp.h` header (and links against gmp\nvia the :code:`-lgmp` flag). You can install all dependencies as follows:\n\napt\n~~~\n\n.. code:: bash\n\n    $ sudo apt-get install python3-dev libgmp3-dev\n\nyum\n~~~\n\n.. code:: bash\n\n    $ sudo yum install python-devel gmp-devel\n\nUsage\n-----\nGenerating Keys\n~~~~~~~~~~~~~~~\nYou can use this package to generate keys if you like. Recall that private keys on elliptic curves\nare integers, and public keys are points i.e. integer pairs.\n\n.. code:: python\n\n    from fastecdsa import keys, curve\n\n    \"\"\"The reason there are two ways to generate a keypair is that generating the public key requires\n    a point multiplication, which can be expensive. That means sometimes you may want to delay\n    generating the public key until it is actually needed.\"\"\"\n\n    # generate a keypair (i.e. both keys) for curve P256\n    priv_key, pub_key = keys.gen_keypair(curve.P256)\n\n    # generate a private key for curve P256\n    priv_key = keys.gen_private_key(curve.P256)\n\n    # get the public key corresponding to the private key we just generated\n    pub_key = keys.get_public_key(priv_key, curve.P256)\n\n\nSigning and Verifying\n~~~~~~~~~~~~~~~~~~~~~\nSome basic usage is shown below:\n\n.. code:: python\n\n    from fastecdsa import curve, ecdsa, keys\n    from hashlib import sha384\n\n    m = \"a message to sign via ECDSA\"  # some message\n\n    ''' use default curve and hash function (P256 and SHA2) '''\n    private_key = keys.gen_private_key(curve.P256)\n    public_key = keys.get_public_key(private_key, curve.P256)\n    # standard signature, returns two integers\n    r, s = ecdsa.sign(m, private_key)\n    # should return True as the signature we just generated is valid.\n    valid = ecdsa.verify((r, s), m, public_key)\n\n    ''' specify a different hash function to use with ECDSA '''\n    r, s = ecdsa.sign(m, private_key, hashfunc=sha384)\n    valid = ecdsa.verify((r, s), m, public_key, hashfunc=sha384)\n\n    ''' specify a different curve to use with ECDSA '''\n    private_key = keys.gen_private_key(curve.P224)\n    public_key = keys.get_public_key(private_key, curve.P224)\n    r, s = ecdsa.sign(m, private_key, curve=curve.P224)\n    valid = ecdsa.verify((r, s), m, public_key, curve=curve.P224)\n\n    ''' using SHA3 via pysha3>=1.0b1 package '''\n    import sha3  # pip install [--user] pysha3==1.0b1\n    from hashlib import sha3_256\n    private_key, public_key = keys.gen_keypair(curve.P256)\n    r, s = ecdsa.sign(m, private_key, hashfunc=sha3_256)\n    valid = ecdsa.verify((r, s), m, public_key, hashfunc=sha3_256)\n\nArbitrary Elliptic Curve Arithmetic\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nThe :code:`Point` class allows arbitrary arithmetic to be performed over curves. The two main\noperations are point addition and point multiplication (by a scalar) which can be done via the\nstandard python operators (:code:`+` and :code:`*` respectively):\n\n.. code:: python\n\n    # example taken from the document below (section 4.3.2):\n    # https://koclab.cs.ucsb.edu/teaching/cren/docs/w02/nist-routines.pdf\n\n    from fastecdsa.curve import P256\n    from fastecdsa.point import Point\n\n    xs = 0xde2444bebc8d36e682edd27e0f271508617519b3221a8fa0b77cab3989da97c9\n    ys = 0xc093ae7ff36e5380fc01a5aad1e66659702de80f53cec576b6350b243042a256\n    S = Point(xs, ys, curve=P256)\n\n    xt = 0x55a8b00f8da1d44e62f6b3b25316212e39540dc861c89575bb8cf92e35e0986b\n    yt = 0x5421c3209c2d6c704835d82ac4c3dd90f61a8a52598b9e7ab656e9d8c8b24316\n    T = Point(xt, yt, curve=P256)\n\n    # Point Addition\n    R = S + T\n\n    # Point Subtraction: (xs, ys) - (xt, yt) = (xs, ys) + (xt, -yt)\n    R = S - T\n\n    # Point Doubling\n    R = S + S  # produces the same value as the operation below\n    R = 2 * S  # S * 2 works fine too i.e. order doesn't matter\n\n    d = 0xc51e4753afdec1e6b6c6a5b992f43f8dd0c7a8933072708b6522468b2ffb06fd\n\n    # Scalar Multiplication\n    R = d * S  # S * d works fine too i.e. order doesn't matter\n\n    e = 0xd37f628ece72a462f0145cbefe3f0b355ee8332d37acdd83a358016aea029db7\n\n    # Joint Scalar Multiplication\n    R = d * S + e * T\n\nImporting and Exporting Keys\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nYou can also export keys as files, ASN.1 encoded and formatted per RFC5480_ and RFC5915_. Both\nprivate keys and public keys can be exported as follows:\n\n.. code:: python\n\n    from fastecdsa.curve import P256\n    from fastecdsa.keys import export_key, gen_keypair\n\n    d, Q = gen_keypair(P256)\n    # save the private key to disk\n    export_key(d, curve=P256, filepath='/path/to/exported/p256.key')\n    # save the public key to disk\n    export_key(Q, curve=P256, filepath='/path/to/exported/p256.pub')\n\nKeys stored in this format can also be imported. The import function will figure out if the key\nis a public or private key and parse it accordingly:\n\n.. code:: python\n\n    from fastecdsa.keys import import_key\n\n    # if the file is a private key then parsed_d is a long and parsed_Q is a Point object\n    # if the file is a public key then parsed_d will be None\n    parsed_d, parsed_Q = import_key('/path/to/file.key')\n\nOther encoding formats can also be specified, such as SEC1_ for public keys. This is done using\nclasses found in the :code:`fastecdsa.encoding` package, and passing them as keyword args to\nthe key functions:\n\n.. code:: python\n\n    from fastecdsa.curve import P256\n    from fastecdsa.encoding.sec1 import SEC1Encoder\n    from fastecdsa.keys import export_key, gen_keypair, import_key\n\n    _, Q = gen_keypair(P256)\n    export_key(Q, curve=P256, filepath='/path/to/p256.key', encoder=SEC1Encoder)\n    parsed_Q = import_key('/path/to/p256.key', curve=P256, public=True, decoder=SEC1Encoder)\n\nEncoding Signatures\n~~~~~~~~~~~~~~~~~~~\nDER encoding of ECDSA signatures as defined in RFC2459_ is also supported. The\n:code:`fastecdsa.encoding.der` provides the :code:`DEREncoder` class which encodes signatures:\n\n.. code:: python\n\n    from fastecdsa.encoding.der import DEREncoder\n\n    r, s = 0xdeadc0de, 0xbadc0de\n    encoded = DEREncoder.encode_signature(r, s)\n    decoded_r, decoded_s = DEREncoder.decode_signature(encoded)\n\nAcknowledgements\n----------------\nThanks to those below for contributing improvements:\n\n- boneyard93501\n- clouds56\n- m-kus\n- sirk390\n- targon\n- NotStatilko\n- bbbrumley\n- luinxz\n- JJChiDguez\n- J08nY\n- trevor-crypto\n- sylvainpelissier\n- akaIDIOT \n\n.. _issue11: https://github.com/AntonKueltz/fastecdsa/issues/11\n.. _GMP: https://gmplib.org/\n.. _RFC2459: https://tools.ietf.org/html/rfc2459\n.. _RFC5480: https://tools.ietf.org/html/rfc5480\n.. _RFC5915: https://tools.ietf.org/html/rfc5915\n.. _RFC6979: https://tools.ietf.org/html/rfc6979\n.. _SEC1: http://www.secg.org/sec1-v2.pdf\n",
    "bugtrack_url": null,
    "license": "This is free and unencumbered software released into the public domain.  Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.  In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  For more information, please refer to <http://unlicense.org/> ",
    "summary": "Fast elliptic curve digital signatures",
    "version": "2.3.2",
    "project_urls": {
        "docs": "https://fastecdsa.readthedocs.io",
        "pypi": "https://pypi.org/project/fastecdsa/",
        "repo": "https://github.com/AntonKueltz/fastecdsa"
    },
    "split_keywords": [
        "elliptic",
        "curve",
        "cryptography",
        "ecdsa",
        "ecc"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7c0ab0e6dfcef078c35cab431e26c6236189a499e33482937a98418777c2063d",
                "md5": "5011cdfddd3e50297a3f66113ad199ac",
                "sha256": "138278b123b6c519f24fe9043d857e2f92c421c4fe256ac80d57404a38dc1326"
            },
            "downloads": -1,
            "filename": "fastecdsa-2.3.2-cp310-cp310-macosx_12_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "5011cdfddd3e50297a3f66113ad199ac",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.7",
            "size": 57872,
            "upload_time": "2024-02-22T19:42:44",
            "upload_time_iso_8601": "2024-02-22T19:42:44.803649Z",
            "url": "https://files.pythonhosted.org/packages/7c/0a/b0e6dfcef078c35cab431e26c6236189a499e33482937a98418777c2063d/fastecdsa-2.3.2-cp310-cp310-macosx_12_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f0566146872b905d8394a9c0ca7c158e99e207dd0d92dffaa5e7d61a415ddf8f",
                "md5": "6165fe77959855cc59ec4d4fcb9cdb24",
                "sha256": "5ba5eb5b33d4b861731108d0ac6e544fcdbdc1ab095a5e86e68081ba5713c958"
            },
            "downloads": -1,
            "filename": "fastecdsa-2.3.2-cp311-cp311-macosx_12_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "6165fe77959855cc59ec4d4fcb9cdb24",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.7",
            "size": 57874,
            "upload_time": "2024-02-22T19:42:47",
            "upload_time_iso_8601": "2024-02-22T19:42:47.090424Z",
            "url": "https://files.pythonhosted.org/packages/f0/56/6146872b905d8394a9c0ca7c158e99e207dd0d92dffaa5e7d61a415ddf8f/fastecdsa-2.3.2-cp311-cp311-macosx_12_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1c7d37bf10fdcf600f4d2d0a3522cd67e1e821cd5a515211075facbf0d93b8dd",
                "md5": "b7b7966dae1358bc9afd913a168139dd",
                "sha256": "cc7189b971bc434b4145c9e7084e4970a0817623927a647b70fb162060baaea2"
            },
            "downloads": -1,
            "filename": "fastecdsa-2.3.2-cp312-cp312-macosx_14_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "b7b7966dae1358bc9afd913a168139dd",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.7",
            "size": 57957,
            "upload_time": "2024-02-22T19:42:48",
            "upload_time_iso_8601": "2024-02-22T19:42:48.443465Z",
            "url": "https://files.pythonhosted.org/packages/1c/7d/37bf10fdcf600f4d2d0a3522cd67e1e821cd5a515211075facbf0d93b8dd/fastecdsa-2.3.2-cp312-cp312-macosx_14_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c30d5ce7fd93778fbb5b6279c1435919dda93ca2d9d9eb7792e8b575abee7672",
                "md5": "ee4c38ec8e2cb9d94e55162d68b811e4",
                "sha256": "08deada741efb94691873d50c0002b2b826bc41459f0d427fbc1a791176e7c2d"
            },
            "downloads": -1,
            "filename": "fastecdsa-2.3.2-cp37-cp37m-macosx_12_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "ee4c38ec8e2cb9d94e55162d68b811e4",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": ">=3.7",
            "size": 57883,
            "upload_time": "2024-02-22T19:42:50",
            "upload_time_iso_8601": "2024-02-22T19:42:50.055399Z",
            "url": "https://files.pythonhosted.org/packages/c3/0d/5ce7fd93778fbb5b6279c1435919dda93ca2d9d9eb7792e8b575abee7672/fastecdsa-2.3.2-cp37-cp37m-macosx_12_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bdce05fe86e97c408c91ccf73b56d07f37bc32c73a527bca163e015bb9594ec2",
                "md5": "d9906c110367836566246b287ec521cf",
                "sha256": "398448290a70bede54f1a8878e797865c40f359ca5840dd12fa33cab277b3b47"
            },
            "downloads": -1,
            "filename": "fastecdsa-2.3.2-cp38-cp38-macosx_12_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "d9906c110367836566246b287ec521cf",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.7",
            "size": 57867,
            "upload_time": "2024-02-22T19:42:51",
            "upload_time_iso_8601": "2024-02-22T19:42:51.951277Z",
            "url": "https://files.pythonhosted.org/packages/bd/ce/05fe86e97c408c91ccf73b56d07f37bc32c73a527bca163e015bb9594ec2/fastecdsa-2.3.2-cp38-cp38-macosx_12_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d5cae7c897489c0fdf3b662fd3e9768ddb7c3abad99ed11887de75f5c748ff64",
                "md5": "5830cb289fbeb1a9c199ae2806cc85f2",
                "sha256": "368f757403f191560d6e0757b8580a58c7b0b53d4db0fa8154b398c1de9f733d"
            },
            "downloads": -1,
            "filename": "fastecdsa-2.3.2-cp39-cp39-macosx_12_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "5830cb289fbeb1a9c199ae2806cc85f2",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.7",
            "size": 57867,
            "upload_time": "2024-02-22T19:42:53",
            "upload_time_iso_8601": "2024-02-22T19:42:53.600668Z",
            "url": "https://files.pythonhosted.org/packages/d5/ca/e7c897489c0fdf3b662fd3e9768ddb7c3abad99ed11887de75f5c748ff64/fastecdsa-2.3.2-cp39-cp39-macosx_12_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fc21d5585856169c595d99a596dd8000afae40053f9f5c955d8ec8fb2ec3247c",
                "md5": "70173954f8949c0eac7ca062111912e0",
                "sha256": "f35255a6d3e41109166b5d4b08866d5acbb99f2e1e64d3a7e74c774664cda842"
            },
            "downloads": -1,
            "filename": "fastecdsa-2.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "70173954f8949c0eac7ca062111912e0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 47729,
            "upload_time": "2024-02-22T19:42:55",
            "upload_time_iso_8601": "2024-02-22T19:42:55.385312Z",
            "url": "https://files.pythonhosted.org/packages/fc/21/d5585856169c595d99a596dd8000afae40053f9f5c955d8ec8fb2ec3247c/fastecdsa-2.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-22 19:42:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AntonKueltz",
    "github_project": "fastecdsa",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "fastecdsa"
}
        
Elapsed time: 0.22954s