Skip to content

Commit

Permalink
add ability to precompute for verification
Browse files Browse the repository at this point in the history
  • Loading branch information
tomato42 committed Oct 10, 2019
1 parent 0699935 commit cce7792
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ def do(setup_statements, statement):
S3 = "msg = six.b('msg')"
S4 = "sig = sk.sign(msg)"
S5 = "vk = sk.get_verifying_key()"
S6 = "vk.verify(sig, msg)"
S6 = "vk.precompute()"
S7 = "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)
verf = do([S1,S2,S3,S4,S5,S6], S7)
import ecdsa
c = getattr(ecdsa, curve)
sig = ecdsa.SigningKey.generate(c).sign(six.b("msg"))
Expand Down
4 changes: 4 additions & 0 deletions src/ecdsa/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def from_public_point(klass, point, curve=NIST192p, hashfunc=sha1):
self.pubkey.order = curve.order
return self

def precompute(self):
self.pubkey.point = ellipticcurve.PointJacobi.from_weierstrass(
self.pubkey.point, True)

@staticmethod
def _from_raw_encoding(string, curve, validate_point):
order = curve.order
Expand Down

0 comments on commit cce7792

Please sign in to comment.