From 99fe4abbb6b799c7cb07cb29641aefcd888cbdd4 Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Sat, 30 Nov 2019 16:44:30 +0100 Subject: [PATCH 01/14] actually export all brainpool curves --- src/ecdsa/curves.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecdsa/curves.py b/src/ecdsa/curves.py index 098a2911..b956aa5b 100644 --- a/src/ecdsa/curves.py +++ b/src/ecdsa/curves.py @@ -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"] From 116e6842ac05cbefdabed2a194eddb91199631af Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Sat, 30 Nov 2019 16:45:41 +0100 Subject: [PATCH 02/14] pyflakes in speed.py --- speed.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/speed.py b/speed.py index ea855e37..bb9bf1e8 100644 --- a/speed.py +++ b/speed.py @@ -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}}") @@ -49,7 +50,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="", From a3eb0a3d3ede2699b17e6890393e9b6b34f3a959 Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Sat, 30 Nov 2019 16:48:21 +0100 Subject: [PATCH 03/14] variable names are part of API, can't change 'em --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 58280226..c6e127e4 100644 --- a/tox.ini +++ b/tox.ini @@ -91,5 +91,6 @@ 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 +ignore = E111,E114,E226,E231,E266,E302,E305,E501,E502,W391,E741 From 33adacb6722a3ee894e79b078902f69312be25cb Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Sat, 30 Nov 2019 16:50:42 +0100 Subject: [PATCH 04/14] ellipticcurve.py: fix pyflakes --- src/ecdsa/ellipticcurve.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ecdsa/ellipticcurve.py b/src/ecdsa/ellipticcurve.py index e15d5b0f..7fb74d9a 100644 --- a/src/ecdsa/ellipticcurve.py +++ b/src/ecdsa/ellipticcurve.py @@ -37,13 +37,13 @@ try: from gmpy2 import mpz - GMPY=True + GMPY = True except ImportError: try: from gmpy import mpz - GMPY=True + GMPY = True except ImportError: - GMPY=False + GMPY = False from six import python_2_unicode_compatible @@ -84,13 +84,13 @@ def __init__(self, p, a, b, h=None): self.__a = a self.__b = b self.__h = h - + 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 __hash__(self): @@ -155,7 +155,7 @@ def __init__(self, curve, x, y, z, order=None, generator=False): self.__y = y self.__z = z self.__order = order - self.__precompute=[] + self.__precompute = [] if generator: assert order i = 1 @@ -192,7 +192,7 @@ def __eq__(self, other): # compare the fractions by bringing them to the same denominator # depend on short-circuit to save 4 multiplications in case of inequality return (x1 * zz2 - x2 * zz1) % p == 0 and \ - (y1 * zz2 * z2 - y2 * zz1 * z1) % p == 0 + (y1 * zz2 * z2 - y2 * zz1 * z1) % p == 0 def order(self): """Return the order of the point. @@ -604,10 +604,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): From 6daa6dea0b91a042bad56864bab2a6f3219fd6ea Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Sat, 30 Nov 2019 16:51:56 +0100 Subject: [PATCH 05/14] __init__.py: fix pyflakes --- src/ecdsa/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ecdsa/__init__.py b/src/ecdsa/__init__.py index 4f914088..eef5fe38 100644 --- a/src/ecdsa/__init__.py +++ b/src/ecdsa/__init__.py @@ -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 From b25e282e5acf4683d5d9672c3f65a08d9bdfc5f8 Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Sat, 30 Nov 2019 16:55:19 +0100 Subject: [PATCH 06/14] curves.py: fix flakes --- src/ecdsa/curves.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecdsa/curves.py b/src/ecdsa/curves.py index b956aa5b..173a2cda 100644 --- a/src/ecdsa/curves.py +++ b/src/ecdsa/curves.py @@ -115,7 +115,7 @@ def __repr__(self): curves = [NIST192p, NIST224p, NIST256p, NIST384p, NIST521p, SECP256k1, - BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1, BRAINPOOLP256r1, + BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1, BRAINPOOLP256r1, BRAINPOOLP320r1, BRAINPOOLP384r1, BRAINPOOLP512r1] From bf13df23c09eae5069806c55460a12a90a18b5f4 Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Sat, 30 Nov 2019 16:55:37 +0100 Subject: [PATCH 07/14] _compat.py: fix flakes --- src/ecdsa/_compat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ecdsa/_compat.py b/src/ecdsa/_compat.py index 143c867e..965d8c47 100644 --- a/src/ecdsa/_compat.py +++ b/src/ecdsa/_compat.py @@ -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 From 2a58dda43557be73c58eb7eca4ce716666bada57 Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Sat, 30 Nov 2019 16:59:20 +0100 Subject: [PATCH 08/14] ecdsa.py: fix flakes --- src/ecdsa/ecdsa.py | 20 ++++++++++---------- tox.ini | 3 ++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/ecdsa/ecdsa.py b/src/ecdsa/ecdsa.py index 42c49b37..4e9bab08 100644 --- a/src/ecdsa/ecdsa.py +++ b/src/ecdsa/ecdsa.py @@ -139,10 +139,10 @@ def __init__(self, generator, point, verify=True): raise InvalidPointError("Generator point order is bad.") 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): @@ -182,12 +182,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): @@ -220,8 +220,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) @@ -277,8 +277,8 @@ def point_is_valid(generator, x, y): if not curve.contains_point(x, y): return False if curve.cofactor() != 1 and \ - not n * ellipticcurve.PointJacobi(curve, x, y, 1)\ - == ellipticcurve.INFINITY: + not n * ellipticcurve.PointJacobi(curve, x, y, 1)\ + == ellipticcurve.INFINITY: return False return True @@ -361,7 +361,7 @@ def point_is_valid(generator, x, y): generator_secp256k1 = ellipticcurve.PointJacobi( curve_secp256k1, _Gx, _Gy, 1, _r, generator=True) - # Brainpool P-160-r1 +# Brainpool P-160-r1 _a = 0x340E7BE2A280EB74E2BE61BADA745D97E8F7C300 _b = 0x1E589A8595423412134FAA2DBDEC95C8D8675E58 _p = 0xE95E4A5F737059DC60DFC7AD95B3D8139515620F diff --git a/tox.ini b/tox.ini index c6e127e4..23d401f9 100644 --- a/tox.ini +++ b/tox.ini @@ -93,4 +93,5 @@ exclude = src/ecdsa/test*.py # 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,E741 +# W503: line break before binary operator +ignore = E111,E114,E226,E231,E266,E302,E305,E501,E502,W391,E741,W503 From 9f6525083e9b1764114d1396ec47dc1e86d9bed1 Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Sat, 30 Nov 2019 17:01:17 +0100 Subject: [PATCH 09/14] keys.py: fix flakes --- src/ecdsa/keys.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ecdsa/keys.py b/src/ecdsa/keys.py index b7a6959a..172fdf58 100644 --- a/src/ecdsa/keys.py +++ b/src/ecdsa/keys.py @@ -142,7 +142,7 @@ def __repr__(self): 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 @@ -245,9 +245,9 @@ def _from_hybrid(cls, string, curve, validate_point): point = cls._from_raw_encoding(string[1:], curve) # 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 @@ -677,10 +677,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 @@ -967,8 +967,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): """ From 3229fcebf4a384aaf47d811e87284a1c517bcb9a Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Sat, 30 Nov 2019 17:02:27 +0100 Subject: [PATCH 10/14] ecdh.py: fix flakes --- src/ecdsa/ecdh.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ecdsa/ecdh.py b/src/ecdsa/ecdh.py index e578fb8c..88848f55 100644 --- a/src/ecdsa/ecdh.py +++ b/src/ecdsa/ecdh.py @@ -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 """"" @@ -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): """ From 1f2c000894a23c815c55e7b98c09ec4dec8f6a74 Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Sat, 30 Nov 2019 17:03:05 +0100 Subject: [PATCH 11/14] util.py: fix flakes --- src/ecdsa/util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ecdsa/util.py b/src/ecdsa/util.py index dbf99266..5f1c7500 100644 --- a/src/ecdsa/util.py +++ b/src/ecdsa/util.py @@ -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: From c41ab5b3c0a71b8ff0aae980503a1f346e3c494e Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Sat, 30 Nov 2019 17:04:08 +0100 Subject: [PATCH 12/14] include codechecks in CI --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2b516ae2..5a4dbd57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,6 +43,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 From d647e36de6b03716dba28274b23d2263137254ab Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Tue, 17 Dec 2019 15:02:36 +0100 Subject: [PATCH 13/14] numbertheory.py: fix flakes --- src/ecdsa/numbertheory.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ecdsa/numbertheory.py b/src/ecdsa/numbertheory.py index 88f7cbbc..b300440c 100644 --- a/src/ecdsa/numbertheory.py +++ b/src/ecdsa/numbertheory.py @@ -19,15 +19,15 @@ xrange = range try: from gmpy2 import powmod - GMPY2=True - GMPY=False + GMPY2 = True + GMPY = False except ImportError: - GMPY2=False + GMPY2 = False try: from gmpy import mpz - GMPY=True + GMPY = True except ImportError: - GMPY=False + GMPY = False import math import warnings From b653c2c650842d200f28e2087c3ec51e9e66b10b Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Tue, 17 Dec 2019 15:03:40 +0100 Subject: [PATCH 14/14] setup.py: fix flakes --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 0800d71e..a6abc4ec 100755 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ ], install_requires=['six>=1.9.0'], extras_require={ - 'gmpy2': 'gmpy2', - 'gmpy': 'gmpy', - }, + 'gmpy2': 'gmpy2', + 'gmpy': 'gmpy', + }, )