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

ec_nistp table generation for scalar multiplication #1669

Merged
merged 8 commits into from
Jul 8, 2024

Conversation

dkostic
Copy link
Contributor

@dkostic dkostic commented Jun 27, 2024

Issues:

N/A

Description of changes:

Generating the precomputed table for scalar multiplication for curves
P-384 and P-521 was implemented for each curve separately.
This commit refactors the code such that a single implementation
can be used with both curves. It is a step towards moving the whole
scalar multiplication code to ec_nistp.c.

Call-outs:

Point out areas that need special attention or support during the review process. Discuss architecture or design changes.

Testing:

How is this change tested (unit tests, fuzz tests, etc.)? Are there any testing steps to be verified by the reviewer?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@dkostic dkostic requested a review from a team as a code owner June 27, 2024 20:59
@codecov-commenter
Copy link

codecov-commenter commented Jun 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.21%. Comparing base (05d3bfd) to head (e994d45).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1669      +/-   ##
==========================================
- Coverage   78.27%   78.21%   -0.06%     
==========================================
  Files         567      571       +4     
  Lines       95227    95464     +237     
  Branches    13671    13704      +33     
==========================================
+ Hits        74538    74670     +132     
- Misses      20095    20185      +90     
- Partials      594      609      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dkostic dkostic force-pushed the ec-nistp-scalar-mul-gen-table branch from f9276cb to c72f9a0 Compare July 1, 2024 21:18
@dkostic dkostic requested a review from nebeid July 2, 2024 21:42
@torben-hansen torben-hansen self-requested a review July 2, 2024 21:52
const size_t felem_num_bytes = felem_num_limbs * sizeof(ec_nistp_felem_limb);

// table[0] <-- P.
OPENSSL_memcpy(&table[felem_num_limbs * 0], x_in, felem_num_bytes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
OPENSSL_memcpy(&table[felem_num_limbs * 0], x_in, felem_num_bytes);
OPENSSL_memcpy(&table[0], x_in, felem_num_bytes);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all redundant multiplications...

crypto/fipsmodule/ec/ec_nistp.c Outdated Show resolved Hide resolved
// table[0] <-- P.
OPENSSL_memcpy(&table[felem_num_limbs * 0], x_in, felem_num_bytes);
OPENSSL_memcpy(&table[felem_num_limbs * 1], y_in, felem_num_bytes);
OPENSSL_memcpy(&table[felem_num_limbs * 2], z_in, felem_num_bytes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

precompute index since it's the same 3 times in a row.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it more clear this way. what's the reason you'd like it precomputed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x_index, y_index, z_index. That seems more clear to me being able to name it. And it's faster.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

crypto/fipsmodule/ec/ec_nistp.c Show resolved Hide resolved
crypto/fipsmodule/ec/ec_nistp.c Show resolved Hide resolved
crypto/fipsmodule/ec/p521.c Show resolved Hide resolved
@dkostic dkostic merged commit 240ad03 into aws:main Jul 8, 2024
96 of 100 checks passed
@dkostic dkostic deleted the ec-nistp-scalar-mul-gen-table branch July 8, 2024 17:54
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.

5 participants