AntonKueltz / fastecdsa

Python library for fast elliptic curve crypto
https://pypi.python.org/pypi/fastecdsa
The Unlicense
264 stars 77 forks source link

ImportError: cannot import name keys #3

Closed SolarisYan closed 8 years ago

SolarisYan commented 8 years ago

hello, when i do this: from fastecdsa import keys, curve

it return an error like

ImportError: cannot import name keys

So how ?

AntonKueltz commented 8 years ago

If you are using v1.1.2 (i.e. if you installed via pip) or before the keys module does not exist yet. It is only available in the current "dev" version. A quick $ pip show fastecdsa should indicate the version. The old version uses fastecdsa.ecdsa.gen_keypair(). Usage for the older versions can be found in the accompanying README, or see the example below:

from fastecdsa import curve, ecdsa
from hashlib import sha384

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

''' use default curve and hash function (P256 and SHA2) '''
private_key, public_key = ecdsa.gen_keypair()
# 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 curve to use with ECDSA '''
private_key, public_key = ecdsa.gen_keypair(curve=curve.P224)
r, s = ecdsa.sign(m, private_key, curve=curve.P224)
valid = ecdsa.verify((r, s), m, public_key, curve=curve.P224)

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

Hope that helps -Anton

SolarisYan commented 8 years ago

do you plan to add the function: keys ?

AntonKueltz commented 8 years ago

If you clone this repo and do $ pip install -e . inside it you'll have the newest version with the keys module. There no plans for a "keys" function.

AntonKueltz commented 8 years ago

The package is now at version 1.1.3 which includes the keys module.

AntonKueltz commented 7 years ago

Fixed in 8c2a545.