-
Notifications
You must be signed in to change notification settings - Fork 320
eddsa: add support for point precomputation #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cefa2ef
to
43bb453
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of some details, though you're unlikely to find them blocking either.
src/ecdsa/ellipticcurve.py
Outdated
order = self.__order | ||
assert order | ||
precompute = [] | ||
i = 1 | ||
order *= 2 | ||
coord_x, coord_y, coord_z, coord_t = self.__coords | ||
prime = self.__curve.p() | ||
doubler = PointEdwards( | ||
self.__curve, coord_x, coord_y, coord_z, coord_t, order | ||
) | ||
order *= 2 | ||
coord_x, coord_y = doubler.x(), doubler.y() | ||
coord_t = coord_x * coord_y % prime | ||
precompute.append((coord_x, coord_y, coord_t)) | ||
|
||
while i < order: | ||
i *= 2 | ||
doubler = doubler.double().scale() | ||
coord_x, coord_y = doubler.x(), doubler.y() | ||
coord_t = coord_x * coord_y % prime | ||
precompute.append((coord_x, coord_y, coord_t)) | ||
|
||
self.__precompute = precompute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are two attempts to restructure the do-while awkwardness, with control flow
assert self.__order
precompute = []
prime = self.__curve.p()
doubler = PointEdwards(self.__curve, *self.__coords, self.__order * 2)
i = 1
while True:
doubler.scale()
coord_x, coord_y = doubler.x(), doubler.y()
coord_t = coord_x * coord_y % prime
precompute.append((coord_x, coord_y, coord_t))
if i >= self.__order * 4:
break
i *= 2
doubler = doubler.double()
self.__precompute = precompute
# assert self.__order * 8 < 2**len(precompute) < self.__order * 16
and with extracting scale-yield-double to a separate generator
def double_gen(p):
while True:
yield p.scale()
p = p.double()
assert self.__order
prime = self.__curve.p()
p1 = PointEdwards(self.__curve, *self.__coords, self.__order * 2)
import itertools
self.__precompute = list(itertools.islice(
((p.x(), p.y(), p.x() * p.y() % prime) for p in double_gen(p1)),
bit_length(self.__order) + 3
))
# assert self.__order * 8 < 2**len(self.__precompute) < self.__order * 16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, *self.__coords
is nice syntactic sugar, unfortunately doesn't work on python2, but yeah, could be rewritten
43bb453
to
e48d851
Compare
e48d851
to
67b1688
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r+ from me, I don't have any more good input
@t184256 thanks for the review! |
Significantly speed up all EdDSA operations by computing multiplication table of the generator point