forked from tlsfuzzer/python-ecdsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·97 lines (89 loc) · 3.41 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
try:
# try setuptools, so devs can run bdist_wheel
from setuptools import setup, Command
except ImportError:
# but most users really don't require it
from distutils.core import setup, Command
import timeit
import versioneer
versioneer.versionfile_source = "ecdsa/_version.py"
versioneer.versionfile_build = versioneer.versionfile_source
versioneer.tag_prefix = "python-ecdsa-"
versioneer.parentdir_prefix = "ecdsa-"
versioneer.VCS = "git"
commands = versioneer.get_cmdclass().copy()
class Test(Command):
description = "run unit tests"
user_options = []
boolean_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
from ecdsa import numbertheory
numbertheory.__main__()
from ecdsa import ellipticcurve
ellipticcurve.__main__()
from ecdsa import ecdsa
ecdsa.__main__()
from ecdsa import test_pyecdsa
test_pyecdsa.unittest.main(module=test_pyecdsa, argv=["dummy"])
# all tests os.exit(1) upon failure
commands["test"] = Test
class Speed(Test):
description = "run benchmark suite"
def run(self):
def do(setup_statements, statement):
# extracted from timeit.py
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
x = t.timeit(number)
if x >= 0.2:
break
return x / number
for curve in ["NIST192p", "NIST224p", "NIST256p", "SECP256k1",
"NIST384p", "NIST521p"]:
S1 = "from ecdsa import six, SigningKey, %s" % curve
S2 = "sk = SigningKey.generate(%s)" % curve
S3 = "msg = six.b('msg')"
S4 = "sig = sk.sign(msg)"
S5 = "vk = sk.get_verifying_key()"
S6 = "vk.verify(sig, msg)"
# We happen to know that .generate() also calculates the
# verifying key, which is the time-consuming part. If the code
# 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)
import ecdsa
c = getattr(ecdsa, curve)
sig = ecdsa.SigningKey.generate(c).sign(ecdsa.six.b("msg"))
print("%9s: siglen=%3d, keygen=%.3fs, sign=%.3fs, verify=%.3fs" \
% (curve, len(sig), keygen, sign, verf))
commands["speed"] = Speed
setup(name="ecdsa",
version=versioneer.get_version(),
description="ECDSA cryptographic signature library (pure python)",
author="Brian Warner",
author_email="[email protected]",
url="http://github.com/warner/python-ecdsa",
packages=["ecdsa"],
license="MIT",
cmdclass=commands,
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.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
],
)