Skip to content
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

[k256] Make Proj point equality and is_identity faster #650

Merged
merged 2 commits into from
Sep 26, 2022

Conversation

LLFourn
Copy link
Contributor

@LLFourn LLFourn commented Sep 13, 2022

  1. ProjectivePoint::is_identity was slow because it did an equality check with identity rather than just checking z coordinate == 0
  2. Equality check was much slower than necessary because it converted to affine coords first. This algorithm does the check avoiding a modular inversion at the cost of a few multiplications. Around ~70 times faster.

I believe these changes are correct but please review carefully.

1. `ProjectivePoint::is_identity` was unnecessarily slow because it did
an equality check with identity rather than just checking z coordinate.
2. equality check was much slower than necessary because it converted to
affine coords first. This algorithm does the check avoiding a modular
inversion at the cost of a few multiplications. Around ~70 times faster.
@LLFourn
Copy link
Contributor Author

LLFourn commented Sep 13, 2022

I added another commit which adds a an fast equality check between projective and affine under the same reasoning.

This is more efficient than converting coordinate systems just to do equality.
LLFourn added a commit to LLFourn/secp256kfun that referenced this pull request Sep 14, 2022
This is more efficient than converting coordinate systems just to do
equality.
Some of the changes inspired by: RustCrypto/elliptic-curves#650
@tarcieri
Copy link
Member

Thank you! I'll try to review this soon.

@tarcieri
Copy link
Member

@fjarri might also be able to provide some input here

@tarcieri tarcieri requested a review from fjarri September 19, 2022 16:18
@fjarri
Copy link
Contributor

fjarri commented Sep 20, 2022

Looks good to me, but hopefully someone else can review too. Thanks for looking into this.

@tarcieri tarcieri merged commit c603ec5 into RustCrypto:master Sep 26, 2022
@tarcieri tarcieri mentioned this pull request Sep 27, 2022
@LLFourn LLFourn deleted the fast_proj_equality branch September 30, 2022 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants