diff options
author | Brian Warner <warner@lothar.com> | 2014-03-10 15:45:39 -0700 |
---|---|---|
committer | Brian Warner <warner@lothar.com> | 2014-03-10 15:45:39 -0700 |
commit | 508a3dbc31c2db4fd1c1ce4fc9c1ad1b0c85ab27 (patch) | |
tree | 6a6b590bcfafd82a46ca58d7d3034cf059bbb758 | |
parent | 1a9453dbe2f62a4de376dc08278a36eeadc3cb40 (diff) | |
download | ecdsa-508a3dbc31c2db4fd1c1ce4fc9c1ad1b0c85ab27.tar.gz |
VerifyingKey.from_string(): add validate_point= argument
Normally, this defaults to "True", which makes sure that the claimed
verifying key is actually a group element. If you've already validate
this key once (say, before writing it to disk), it is safe to skip this
step, so setting "validate_point=False" will shave a significant amount
of time from the constructor (measured at 26ms per key by @sigmunau).
Closes #19.
-rw-r--r-- | ecdsa/keys.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/ecdsa/keys.py b/ecdsa/keys.py index 6e80dcb..75042f6 100644 --- a/ecdsa/keys.py +++ b/ecdsa/keys.py @@ -30,7 +30,8 @@ class VerifyingKey: return self @classmethod - def from_string(klass, string, curve=NIST192p, hashfunc=sha1): + def from_string(klass, string, curve=NIST192p, hashfunc=sha1, + validate_point=True): order = curve.order assert len(string) == curve.verifying_key_length, \ (len(string), curve.verifying_key_length) @@ -40,7 +41,8 @@ class VerifyingKey: assert len(ys) == curve.baselen, (len(ys), curve.baselen) x = string_to_number(xs) y = string_to_number(ys) - assert ecdsa.point_is_valid(curve.generator, x, y) + if validate_point: + assert ecdsa.point_is_valid(curve.generator, x, y) from . import ellipticcurve point = ellipticcurve.Point(curve.curve, x, y, order) return klass.from_public_point(point, curve, hashfunc) |