Skip to content

Commit

Permalink
Merge 0699935 into 3365968
Browse files Browse the repository at this point in the history
  • Loading branch information
tomato42 committed Oct 10, 2019
2 parents 3365968 + 0699935 commit dc7c057
Show file tree
Hide file tree
Showing 11 changed files with 631 additions and 60 deletions.
6 changes: 1 addition & 5 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@
include =
src/ecdsa/*
omit =
src/ecdsa/six.py
src/ecdsa/_version.py
src/ecdsa/test_ecdsa.py
src/ecdsa/test_ellipticcurve.py
src/ecdsa/test_numbertheory.py
src/ecdsa/test_pyecdsa.py
src/ecdsa/test_*
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ is to call `s=sk.to_string()`, and then re-create it with
`SigningKey.from_string(s, curve)` . This short form does not record the
curve, so you must be sure to tell from_string() the same curve you used for
the original key. The short form of a NIST192p-based signing key is just 24
bytes long. If the point encoding is invalid or it does not lie on the
specified curve, `from_string()` will raise MalformedPointError.
bytes long. If a point encoding is invalid or it does not lie on the specified
curve, `from_string()` will raise MalformedPointError.

```python
from ecdsa import SigningKey, NIST384p
Expand Down
6 changes: 4 additions & 2 deletions speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ def do(setup_statements, statement):
import ecdsa
c = getattr(ecdsa, curve)
sig = ecdsa.SigningKey.generate(c).sign(six.b("msg"))
print("%9s: siglen=%3d, keygen=%.3fs, sign=%.3fs, verify=%.3fs" \
% (curve, len(sig), keygen, sign, verf))
print("%9s: siglen=%3d, keygen=%.4fs, %5.1f/s, "
"sign=%.4fs, %5.1f/s, verify=%.4fs, %5.1f/s" \
% (curve, len(sig), keygen, 1.0/keygen, sign, 1.0/sign,
verf, 1.0/verf))
5 changes: 4 additions & 1 deletion src/ecdsa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .keys import SigningKey, VerifyingKey, BadSignatureError, BadDigestError
from .keys import SigningKey, VerifyingKey, BadSignatureError, BadDigestError,\
MalformedPointError
from .curves import NIST192p, NIST224p, NIST256p, NIST384p, NIST521p, SECP256k1
from .der import UnexpectedDER

# This code comes from http://github.com/warner/python-ecdsa
from ._version import get_versions
Expand All @@ -10,5 +12,6 @@
"test_pyecdsa", "util", "six"]

_hush_pyflakes = [SigningKey, VerifyingKey, BadSignatureError, BadDigestError,
MalformedPointError, UnexpectedDER,
NIST192p, NIST224p, NIST256p, NIST384p, NIST521p, SECP256k1]
del _hush_pyflakes
13 changes: 7 additions & 6 deletions src/ecdsa/curves.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import division

from . import der, ecdsa
from .ellipticcurve import PointJacobi


class UnknownCurveError(Exception):
Expand All @@ -26,22 +27,22 @@ def __init__(self, name, curve, generator, oid, openssl_name=None):
self.encoded_oid = der.encode_oid(*oid)

NIST192p = Curve("NIST192p", ecdsa.curve_192,
ecdsa.generator_192,
PointJacobi.from_weierstrass(ecdsa.generator_192, True),
(1, 2, 840, 10045, 3, 1, 1), "prime192v1")
NIST224p = Curve("NIST224p", ecdsa.curve_224,
ecdsa.generator_224,
PointJacobi.from_weierstrass(ecdsa.generator_224, True),
(1, 3, 132, 0, 33), "secp224r1")
NIST256p = Curve("NIST256p", ecdsa.curve_256,
ecdsa.generator_256,
PointJacobi.from_weierstrass(ecdsa.generator_256, True),
(1, 2, 840, 10045, 3, 1, 7), "prime256v1")
NIST384p = Curve("NIST384p", ecdsa.curve_384,
ecdsa.generator_384,
PointJacobi.from_weierstrass(ecdsa.generator_384, True),
(1, 3, 132, 0, 34), "secp384r1")
NIST521p = Curve("NIST521p", ecdsa.curve_521,
ecdsa.generator_521,
PointJacobi.from_weierstrass(ecdsa.generator_521, True),
(1, 3, 132, 0, 35), "secp521r1")
SECP256k1 = Curve("SECP256k1", ecdsa.curve_secp256k1,
ecdsa.generator_secp256k1,
PointJacobi.from_weierstrass(ecdsa.generator_secp256k1, True),
(1, 3, 132, 0, 10), "secp256k1")

curves = [NIST192p, NIST224p, NIST256p, NIST384p, NIST521p, SECP256k1]
Expand Down
4 changes: 2 additions & 2 deletions src/ecdsa/ecdsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ def recover_public_keys(self, hash, generator):
y = beta if beta % 2 == 0 else curve.p() - beta

# Compute the public key
R1 = ellipticcurve.Point(curve, x, y, n)
R1 = ellipticcurve.PointJacobi(curve, x, y, 1, n)
Q1 = numbertheory.inverse_mod(r, n) * (s * R1 + (-e % n) * generator)
Pk1 = Public_key(generator, Q1)

# And the second solution
R2 = ellipticcurve.Point(curve, x, -y, n)
R2 = ellipticcurve.PointJacobi(curve, x, -y, 1, n)
Q2 = numbertheory.inverse_mod(r, n) * (s * R2 + (-e % n) * generator)
Pk2 = Public_key(generator, Q2)

Expand Down

0 comments on commit dc7c057

Please sign in to comment.