Skip to content

Commit 508a3db

Browse files
committed
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.
1 parent 1a9453d commit 508a3db

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

ecdsa/keys.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def from_public_point(klass, point, curve=NIST192p, hashfunc=sha1):
3030
return self
3131

3232
@classmethod
33-
def from_string(klass, string, curve=NIST192p, hashfunc=sha1):
33+
def from_string(klass, string, curve=NIST192p, hashfunc=sha1,
34+
validate_point=True):
3435
order = curve.order
3536
assert len(string) == curve.verifying_key_length, \
3637
(len(string), curve.verifying_key_length)
@@ -40,7 +41,8 @@ def from_string(klass, string, curve=NIST192p, hashfunc=sha1):
4041
assert len(ys) == curve.baselen, (len(ys), curve.baselen)
4142
x = string_to_number(xs)
4243
y = string_to_number(ys)
43-
assert ecdsa.point_is_valid(curve.generator, x, y)
44+
if validate_point:
45+
assert ecdsa.point_is_valid(curve.generator, x, y)
4446
from . import ellipticcurve
4547
point = ellipticcurve.Point(curve.curve, x, y, order)
4648
return klass.from_public_point(point, curve, hashfunc)

0 commit comments

Comments
 (0)