Skip to content

Commit

Permalink
Merge 1e3da9b into 34864b1
Browse files Browse the repository at this point in the history
  • Loading branch information
tomato42 committed Nov 30, 2019
2 parents 34864b1 + 1e3da9b commit f1e4803
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 38 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ matrix:
env: TOX_ENV=py37
dist: xenial
sudo: true
- python: 3.8
env: TOX_ENV=codechecks
dist: xenial
sudo: true
- python: 3.8
env: TOX_ENV=py38
dist: xenial
Expand Down
6 changes: 4 additions & 2 deletions speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def do(setup_statements, statement):
break
return x / number

prnt_form = ("{name:>16}{sep:1} {siglen:>6} {keygen:>9{form}}{unit:1} "
prnt_form = (
"{name:>16}{sep:1} {siglen:>6} {keygen:>9{form}}{unit:1} "
"{keygen_inv:>9{form_inv}} {sign:>9{form}}{unit:1} "
"{sign_inv:>9{form_inv}} {verify:>9{form}}{unit:1} "
"{verify_inv:>9{form_inv}}")
Expand Down Expand Up @@ -48,7 +49,8 @@ def do(setup_statements, statement):

print('')

ecdh_form = ("{name:>16}{sep:1} {ecdh:>9{form}}{unit:1} "
ecdh_form = (
"{name:>16}{sep:1} {ecdh:>9{form}}{unit:1} "
"{ecdh_inv:>9{form_inv}}")

print(ecdh_form.format(ecdh="ecdh", ecdh_inv="ecdh/s", name="", sep="",
Expand Down
6 changes: 3 additions & 3 deletions src/ecdsa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .keys import SigningKey, VerifyingKey, BadSignatureError, BadDigestError,\
MalformedPointError
MalformedPointError
from .curves import NIST192p, NIST224p, NIST256p, NIST384p, NIST521p,\
SECP256k1, BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1,\
BRAINPOOLP256r1, BRAINPOOLP320r1, BRAINPOOLP384r1, BRAINPOOLP512r1
SECP256k1, BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1,\
BRAINPOOLP256r1, BRAINPOOLP320r1, BRAINPOOLP384r1, BRAINPOOLP512r1
from .ecdh import ECDH, NoKeyError, NoCurveError, InvalidCurveError, \
InvalidSharedSecretError
from .der import UnexpectedDER
Expand Down
3 changes: 2 additions & 1 deletion src/ecdsa/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def str_idx_as_int(string, index):
if sys.version_info < (3, 0):
def normalise_bytes(buffer_object):
"""Cast the input into array of bytes."""
return buffer(buffer_object)
# flake8 runs on py3 where `buffer` indeed doesn't exist...
return buffer(buffer_object) # noqa: F821

def hmac_compat(ret):
return ret
Expand Down
4 changes: 2 additions & 2 deletions src/ecdsa/curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
__all__ = ["UnknownCurveError", "orderlen", "Curve", "NIST192p",
"NIST224p", "NIST256p", "NIST384p", "NIST521p", "curves",
"find_curve", "SECP256k1", "BRAINPOOLP160r1", "BRAINPOOLP192r1",
"BRAINPOOLP224r1", "BRAINPOOLP256r1" "BRAINPOOLP320r1",
"BRAINPOOLP224r1", "BRAINPOOLP256r1", "BRAINPOOLP320r1",
"BRAINPOOLP384r1", "BRAINPOOLP512r1"]


Expand Down Expand Up @@ -101,7 +101,7 @@ def __repr__(self):


curves = [NIST192p, NIST224p, NIST256p, NIST384p, NIST521p, SECP256k1,
BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1, BRAINPOOLP256r1,
BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1, BRAINPOOLP256r1,
BRAINPOOLP320r1, BRAINPOOLP384r1, BRAINPOOLP512r1]


Expand Down
8 changes: 4 additions & 4 deletions src/ecdsa/ecdh.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class InvalidSharedSecretError(Exception):
class ECDH(object):
"""
Elliptic-curve Diffie-Hellman (ECDH). A key agreement protocol.
Allows two parties, each having an elliptic-curve public-private key
Allows two parties, each having an elliptic-curve public-private key
pair, to establish a shared secret over an insecure channel
"""""

Expand Down Expand Up @@ -283,8 +283,8 @@ def generate_sharedsecret_bytes(self):
:rtype: byte string
"""
return number_to_string(
self.generate_sharedsecret(),
self.private_key.curve.order)
self.generate_sharedsecret(),
self.private_key.curve.order)

def generate_sharedsecret(self):
"""
Expand Down
16 changes: 8 additions & 8 deletions src/ecdsa/ecdsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ def __init__(self, generator, point):
raise RuntimeError("Generator point has x or y out of range.")

def __eq__(self, other):
if isinstance(other, Public_key):
if isinstance(other, Public_key):
"""Return True if the points are identical, False otherwise."""
return self.curve == other.curve \
and self.point == other.point
and self.point == other.point
return NotImplemented

def verifies(self, hash, signature):
Expand Down Expand Up @@ -160,12 +160,12 @@ def __init__(self, public_key, secret_multiplier):

self.public_key = public_key
self.secret_multiplier = secret_multiplier

def __eq__(self, other):
if isinstance(other, Private_key):
if isinstance(other, Private_key):
"""Return True if the points are identical, False otherwise."""
return self.public_key == other.public_key \
and self.secret_multiplier == other.secret_multiplier
and self.secret_multiplier == other.secret_multiplier
return NotImplemented

def sign(self, hash, random_k):
Expand Down Expand Up @@ -198,8 +198,8 @@ def sign(self, hash, random_k):
r = p1.x() % n
if r == 0:
raise RSZeroError("amazingly unlucky random number r")
s = (numbertheory.inverse_mod(k, n) *
(hash + (self.secret_multiplier * r) % n)) % n
s = (numbertheory.inverse_mod(k, n)
* (hash + (self.secret_multiplier * r) % n)) % n
if s == 0:
raise RSZeroError("amazingly unlucky random number s")
return Signature(r, s)
Expand Down Expand Up @@ -330,7 +330,7 @@ def point_is_valid(generator, x, y):
curve_secp256k1 = ellipticcurve.CurveFp(_p, _a, _b)
generator_secp256k1 = ellipticcurve.Point(curve_secp256k1, _Gx, _Gy, _r)

# Brainpool P-160-r1
# Brainpool P-160-r1
_a = 0x340E7BE2A280EB74E2BE61BADA745D97E8F7C300
_b = 0x1E589A8595423412134FAA2DBDEC95C8D8675E58
_p = 0xE95E4A5F737059DC60DFC7AD95B3D8139515620F
Expand Down
14 changes: 7 additions & 7 deletions src/ecdsa/ellipticcurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ def __init__(self, p, a, b):
self.__p = p
self.__a = a
self.__b = b

def __eq__(self, other):
if isinstance(other, CurveFp):
if isinstance(other, CurveFp):
"""Return True if the curves are identical, False otherwise."""
return self.__p == other.__p \
and self.__a == other.__a \
and self.__b == other.__b
and self.__a == other.__a \
and self.__b == other.__b
return NotImplemented

def p(self):
Expand Down Expand Up @@ -87,10 +87,10 @@ def __init__(self, curve, x, y, order=None):

def __eq__(self, other):
"""Return True if the points are identical, False otherwise."""
if isinstance(other, Point):
if isinstance(other, Point):
return self.__curve == other.__curve \
and self.__x == other.__x \
and self.__y == other.__y
and self.__x == other.__x \
and self.__y == other.__y
return NotImplemented

def __neg__(self):
Expand Down
17 changes: 8 additions & 9 deletions src/ecdsa/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ def __repr__(self):
pub_key = self.to_string("compressed")
return "VerifyingKey.from_string({0!r}, {1!r}, {2})".format(
pub_key, self.curve, self.default_hashfunc().name)

def __eq__(self, other):
"""Return True if the points are identical, False otherwise."""
if isinstance(other, VerifyingKey):
if isinstance(other, VerifyingKey):
return self.curve == other.curve \
and self.pubkey == other.pubkey
return NotImplemented
Expand Down Expand Up @@ -232,9 +232,9 @@ def _from_hybrid(cls, string, curve, validate_point):
point = cls._from_raw_encoding(string[1:], curve, validate_point)

# but validate if it's self-consistent if we're asked to do that
if validate_point and \
(point.y() & 1 and string[:1] != b('\x07') or
(not point.y() & 1) and string[:1] != b('\x06')):
if validate_point \
and (point.y() & 1 and string[:1] != b('\x07')
or (not point.y() & 1) and string[:1] != b('\x06')):
raise MalformedPointError("Inconsistent hybrid point encoding")

return point
Expand Down Expand Up @@ -656,10 +656,10 @@ def __init__(self, _error__please_use_generate=None):
self.baselen = None
self.verifying_key = None
self.privkey = None

def __eq__(self, other):
"""Return True if the points are identical, False otherwise."""
if isinstance(other, SigningKey):
if isinstance(other, SigningKey):
return self.curve == other.curve \
and self.verifying_key == other.verifying_key \
and self.privkey == other.privkey
Expand Down Expand Up @@ -945,8 +945,7 @@ def to_der(self, point_encoding="uncompressed"):
der.encode_integer(1),
der.encode_octet_string(self.to_string()),
der.encode_constructed(0, self.curve.encoded_oid),
der.encode_constructed(1, der.encode_bitstring(encoded_vk, 0)),
)
der.encode_constructed(1, der.encode_bitstring(encoded_vk, 0)))

def get_verifying_key(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/ecdsa/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def entropy_to_bits(ent_256):
return ''.join(bin(ord(x))[2:].zfill(8) for x in ent_256)


if sys.version < '2.7': #Can't add a method to a built-in type so we are stuck with this
if sys.version < '2.7':
# Can't add a method to a built-in type so we are stuck with this
def bit_length(x):
return len(bin(x)) - 2
else:
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@ exclude = src/ecdsa/test*.py
# E305: expected 2 blank lines after class or function definition, found 1
# E501: line too long
# E502: the backslash is redundant between brackets
# E741: ambiguous variable name
# W391: blank line at end of file
ignore = E111,E114,E226,E231,E266,E302,E305,E501,E502,W391
# W503: line break before binary operator
ignore = E111,E114,E226,E231,E266,E302,E305,E501,E502,W391,E741,W503

0 comments on commit f1e4803

Please sign in to comment.