From cce7792516e6307a831802bc40bbb6a21a593cea Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Thu, 10 Oct 2019 09:32:57 +0200 Subject: [PATCH] add ability to precompute for verification --- speed.py | 5 +++-- src/ecdsa/keys.py | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/speed.py b/speed.py index 686ebf52..a74fcd7f 100644 --- a/speed.py +++ b/speed.py @@ -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")) diff --git a/src/ecdsa/keys.py b/src/ecdsa/keys.py index 2bfe8062..165d51fa 100644 --- a/src/ecdsa/keys.py +++ b/src/ecdsa/keys.py @@ -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