Skip to content

Commit 20f0051

Browse files
committed
document VerifyingKey.precompute add lazy option
as we now precompute lazily, force the precomputation to happen when we call the method, now then it's first used; allow also the lazy option to delay it to the first time point is used (at the price of first verification latency)
1 parent 73f3d3e commit 20f0051

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/ecdsa/keys.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,33 @@ def from_public_point(
201201
self.pubkey.order = curve.order
202202
return self
203203

204-
def precompute(self):
204+
def precompute(self, lazy=False):
205+
"""
206+
Precompute multiplication tables for faster signature verification.
207+
208+
Calling this method will cause the library to precompute the
209+
scalar multiplication tables, used in signature verification.
210+
While it's an expensive operation (comparable to performing
211+
as many signatures as the bit size of the curve, i.e. 256 for NIST256p)
212+
it speeds up verification 2 times. You should call this method
213+
if you expect to verify hundreds of signatures (or more) using the same
214+
VerifyingKey object.
215+
216+
Note: You should call this method only once, this method generates a
217+
new precomputation table every time it's called.
218+
219+
:param bool lazy: whether to calculate the precomputation table now
220+
(if set to False) or if it should be delayed to the time of first
221+
use (when set to True)
222+
"""
205223
self.pubkey.point = ellipticcurve.PointJacobi.from_affine(
206224
self.pubkey.point, True
207225
)
226+
# as precomputation in now delayed to the time of first use of the
227+
# point and we were asked specifically to precompute now, make
228+
# sure the precomputation is performed now to preserve the behaviour
229+
if not lazy:
230+
self.pubkey.point * 2
208231

209232
@staticmethod
210233
def _from_raw_encoding(string, curve):

0 commit comments

Comments
 (0)