Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions diff-instrumental.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
argv = sys.argv[1:]

opts, args = getopt.getopt(
argv, "s:r:",
["fail-under=", "max-difference=", "save=", "read="])
argv, "s:r:", ["fail-under=", "max-difference=", "save=", "read="]
)
if args:
raise ValueError("Unexpected parameters: {0}".format(args))
for opt, arg in opts:
Expand All @@ -20,9 +20,9 @@
elif opt == "-r" or opt == "--read":
read_location = arg
elif opt == "--fail-under":
fail_under = float(arg)/100.0
fail_under = float(arg) / 100.0
elif opt == "--max-difference":
max_difference = float(arg)/100.0
max_difference = float(arg) / 100.0
else:
raise ValueError("Unknown option: {0}".format(opt))

Expand All @@ -34,7 +34,7 @@
continue

fields = line.split()
hit, count = fields[1].split('/')
hit, count = fields[1].split("/")
total_hits += int(hit)
total_count += int(count)

Expand All @@ -43,16 +43,16 @@
if read_location:
with open(read_location, "r") as f:
old_coverage = float(f.read())
print("Old coverage: {0:6.2f}%".format(old_coverage*100))
print("Old coverage: {0:6.2f}%".format(old_coverage * 100))

if save_location:
with open(save_location, "w") as f:
f.write("{0:1.40f}".format(coverage))

print("Coverage: {0:6.2f}%".format(coverage*100))
print("Coverage: {0:6.2f}%".format(coverage * 100))

if read_location:
print("Difference: {0:6.2f}%".format((old_coverage - coverage)*100))
print("Difference: {0:6.2f}%".format((old_coverage - coverage) * 100))

if fail_under and coverage < fail_under:
print("ERROR: Insufficient coverage.", file=sys.stderr)
Expand Down
62 changes: 30 additions & 32 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,33 @@
with io.open(readme_path, encoding="utf-8") as read_file:
long_description = read_file.read()

setup(name="ecdsa",
version=versioneer.get_version(),
description="ECDSA cryptographic signature library (pure python)",
long_description=long_description,
long_description_content_type='text/markdown',
author="Brian Warner",
author_email="warner@lothar.com",
url="http://github.com/warner/python-ecdsa",
packages=["ecdsa"],
package_dir={"": "src"},
license="MIT",
cmdclass=commands,
python_requires=">=2.6, !=3.0.*, !=3.1.*, !=3.2.*",
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
install_requires=['six>=1.9.0'],
extras_require={
'gmpy2': 'gmpy2',
'gmpy': 'gmpy',
},
)
setup(
name="ecdsa",
version=versioneer.get_version(),
description="ECDSA cryptographic signature library (pure python)",
long_description=long_description,
long_description_content_type="text/markdown",
author="Brian Warner",
author_email="warner@lothar.com",
url="http://github.com/warner/python-ecdsa",
packages=["ecdsa"],
package_dir={"": "src"},
license="MIT",
cmdclass=commands,
python_requires=">=2.6, !=3.0.*, !=3.1.*, !=3.2.*",
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
install_requires=["six>=1.9.0"],
extras_require={"gmpy2": "gmpy2", "gmpy": "gmpy"},
)
88 changes: 65 additions & 23 deletions speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,42 @@
import timeit
from ecdsa.curves import curves


def do(setup_statements, statement):
# extracted from timeit.py
t = timeit.Timer(stmt=statement,
setup="\n".join(setup_statements))
t = timeit.Timer(stmt=statement, setup="\n".join(setup_statements))
# determine number so that 0.2 <= total time < 2.0
for i in range(1, 10):
number = 10**i
number = 10 ** i
x = t.timeit(number)
if x >= 0.2:
break
return x / number


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}}")
"{verify_inv:>9{form_inv}}"
)

print(prnt_form.format(siglen="siglen", keygen="keygen", keygen_inv="keygen/s",
sign="sign", sign_inv="sign/s", verify="verify",
verify_inv="verify/s", name="", sep="", unit="",
form="", form_inv=""))
print(
prnt_form.format(
siglen="siglen",
keygen="keygen",
keygen_inv="keygen/s",
sign="sign",
sign_inv="sign/s",
verify="verify",
verify_inv="verify/s",
name="",
sep="",
unit="",
form="",
form_inv="",
)
)

for curve in [i.name for i in curves]:
S1 = "import six; from ecdsa import SigningKey, %s" % curve
Expand All @@ -38,24 +52,44 @@ def do(setup_statements, statement):
# were changed to lazily calculate vk, we'd need to change this
# benchmark to loop over S5 instead of S2
keygen = do([S1], S2)
sign = do([S1,S2,S3], S4)
verf = do([S1,S2,S3,S4,S5,S6], S7)
sign = do([S1, S2, S3], S4)
verf = do([S1, S2, S3, S4, S5, S6], S7)
import ecdsa

c = getattr(ecdsa, curve)
sig = ecdsa.SigningKey.generate(c).sign(six.b("msg"))
print(prnt_form.format(
name=curve, sep=":", siglen=len(sig), unit="s", keygen=keygen,
keygen_inv=1.0/keygen, sign=sign, sign_inv=1.0/sign, verify=verf,
verify_inv=1.0/verf, form=".5f", form_inv=".2f"))
print(
prnt_form.format(
name=curve,
sep=":",
siglen=len(sig),
unit="s",
keygen=keygen,
keygen_inv=1.0 / keygen,
sign=sign,
sign_inv=1.0 / sign,
verify=verf,
verify_inv=1.0 / verf,
form=".5f",
form_inv=".2f",
)
)

print('')
print("")

ecdh_form = (
"{name:>16}{sep:1} {ecdh:>9{form}}{unit:1} "
"{ecdh_inv:>9{form_inv}}")
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="",
unit="", form="", form_inv=""))
print(
ecdh_form.format(
ecdh="ecdh",
ecdh_inv="ecdh/s",
name="",
sep="",
unit="",
form="",
form_inv="",
)
)

for curve in [i.name for i in curves]:
S1 = "from ecdsa import SigningKey, ECDH, {0}".format(curve)
Expand All @@ -64,6 +98,14 @@ def do(setup_statements, statement):
S4 = "ecdh = ECDH(private_key=our, public_key=remote)"
S5 = "ecdh.generate_sharedsecret_bytes()"
ecdh = do([S1, S2, S3, S4], S5)
print(ecdh_form.format(
name=curve, sep=":", unit="s", form=".5f", form_inv=".2f",
ecdh=ecdh, ecdh_inv=1.0/ecdh))
print(
ecdh_form.format(
name=curve,
sep=":",
unit="s",
form=".5f",
form_inv=".2f",
ecdh=ecdh,
ecdh_inv=1.0 / ecdh,
)
)
85 changes: 68 additions & 17 deletions src/ecdsa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,76 @@
from .keys import SigningKey, VerifyingKey, BadSignatureError, BadDigestError,\
MalformedPointError
from .curves import NIST192p, NIST224p, NIST256p, NIST384p, NIST521p,\
SECP256k1, BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1,\
BRAINPOOLP256r1, BRAINPOOLP320r1, BRAINPOOLP384r1, BRAINPOOLP512r1
from .ecdh import ECDH, NoKeyError, NoCurveError, InvalidCurveError, \
InvalidSharedSecretError
from .keys import (
SigningKey,
VerifyingKey,
BadSignatureError,
BadDigestError,
MalformedPointError,
)
from .curves import (
NIST192p,
NIST224p,
NIST256p,
NIST384p,
NIST521p,
SECP256k1,
BRAINPOOLP160r1,
BRAINPOOLP192r1,
BRAINPOOLP224r1,
BRAINPOOLP256r1,
BRAINPOOLP320r1,
BRAINPOOLP384r1,
BRAINPOOLP512r1,
)
from .ecdh import (
ECDH,
NoKeyError,
NoCurveError,
InvalidCurveError,
InvalidSharedSecretError,
)
from .der import UnexpectedDER

# This code comes from http://github.com/warner/python-ecdsa
from ._version import get_versions
__version__ = get_versions()['version']

__version__ = get_versions()["version"]
del get_versions

__all__ = ["curves", "der", "ecdsa", "ellipticcurve", "keys", "numbertheory",
"test_pyecdsa", "util", "six"]
__all__ = [
"curves",
"der",
"ecdsa",
"ellipticcurve",
"keys",
"numbertheory",
"test_pyecdsa",
"util",
"six",
]

_hush_pyflakes = [SigningKey, VerifyingKey, BadSignatureError, BadDigestError,
MalformedPointError, UnexpectedDER, InvalidCurveError,
NoKeyError, InvalidSharedSecretError, ECDH, NoCurveError,
NIST192p, NIST224p, NIST256p, NIST384p, NIST521p, SECP256k1,
BRAINPOOLP160r1, BRAINPOOLP192r1, BRAINPOOLP224r1,
BRAINPOOLP256r1, BRAINPOOLP320r1, BRAINPOOLP384r1,
BRAINPOOLP512r1]
_hush_pyflakes = [
SigningKey,
VerifyingKey,
BadSignatureError,
BadDigestError,
MalformedPointError,
UnexpectedDER,
InvalidCurveError,
NoKeyError,
InvalidSharedSecretError,
ECDH,
NoCurveError,
NIST192p,
NIST224p,
NIST256p,
NIST384p,
NIST521p,
SECP256k1,
BRAINPOOLP160r1,
BRAINPOOLP192r1,
BRAINPOOLP224r1,
BRAINPOOLP256r1,
BRAINPOOLP320r1,
BRAINPOOLP384r1,
BRAINPOOLP512r1,
]
del _hush_pyflakes
6 changes: 5 additions & 1 deletion src/ecdsa/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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."""
# flake8 runs on py3 where `buffer` indeed doesn't exist...
Expand All @@ -22,6 +23,7 @@ def normalise_bytes(buffer_object):
def hmac_compat(ret):
return ret


else:
if sys.version_info < (3, 4):
# on python 3.3 hmac.hmac.update() accepts only bytes, on newer
Expand All @@ -30,10 +32,12 @@ def hmac_compat(data):
if not isinstance(data, bytes):
return bytes(data)
return data

else:

def hmac_compat(data):
return data

def normalise_bytes(buffer_object):
"""Cast the input into array of bytes."""
return memoryview(buffer_object).cast('B')
return memoryview(buffer_object).cast("B")
1 change: 1 addition & 0 deletions src/ecdsa/_rwlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def writer_release(self):
class _LightSwitch:
"""An auxiliary "light switch"-like object. The first thread turns on the
"switch", the last one turns it off (see [1, sec. 4.2.2] for details)."""

def __init__(self):
self.__counter = 0
self.__mutex = threading.Lock()
Expand Down
Loading