Skip to content

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

Merged
merged 1 commit into from
Oct 26, 2021

Conversation

tomato42
Copy link
Member

Significantly speed up all EdDSA operations by computing multiplication table of the generator point

@tomato42 tomato42 added the feature functionality to be implemented label Aug 13, 2021
@tomato42 tomato42 added this to the v0.18.0 milestone Aug 13, 2021
@tomato42 tomato42 self-assigned this Aug 13, 2021
@tomato42 tomato42 mentioned this pull request Aug 13, 2021
3 tasks
@tomato42 tomato42 force-pushed the edwards-precompute branch from cefa2ef to 43bb453 Compare August 13, 2021 19:22
@tomato42 tomato42 requested a review from t184256 August 17, 2021 12:13
Copy link
Contributor

@t184256 t184256 left a 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.

Comment on lines 1342 to 1367
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
Copy link
Contributor

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

Copy link
Member Author

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

@tomato42 tomato42 force-pushed the edwards-precompute branch from 43bb453 to e48d851 Compare August 19, 2021 23:55
@tomato42 tomato42 requested a review from t184256 October 15, 2021 19:12
Copy link
Contributor

@t184256 t184256 left a 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

@tomato42 tomato42 merged commit 357fb84 into tlsfuzzer:master Oct 26, 2021
@tomato42 tomato42 deleted the edwards-precompute branch October 26, 2021 22:54
@tomato42
Copy link
Member Author

@t184256 thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature functionality to be implemented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants