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

Added generic EC scalar rwnaf encoding for ec_nistp #1664

Merged
merged 5 commits into from
Jul 1, 2024

Conversation

dkostic
Copy link
Contributor

@dkostic dkostic commented Jun 25, 2024

Issues:

N/A

Description of changes:

Scalar encoding for scalar multiplication for curves P-384 and P-521
was implemented for each curve separately and with hard-coded
parameters. This commit refactors the encoding function to be
generic and uses removes the hard-coded ones.

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 25, 2024 21:38
@codecov-commenter
Copy link

codecov-commenter commented Jun 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.22%. Comparing base (88faaa2) to head (60221d8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1664      +/-   ##
==========================================
- Coverage   78.24%   78.22%   -0.02%     
==========================================
  Files         566      566              
  Lines       95185    95177       -8     
  Branches    13664    13663       -1     
==========================================
- Hits        74476    74454      -22     
- Misses      20116    20127      +11     
- Partials      593      596       +3     

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

crypto/fipsmodule/ec/ec_nistp.c Outdated Show resolved Hide resolved
crypto/fipsmodule/ec/ec_nistp.c Outdated Show resolved Hide resolved
crypto/fipsmodule/ec/ec_nistp.c Outdated Show resolved Hide resolved
crypto/fipsmodule/ec/p384.c Show resolved Hide resolved
samuel40791765
samuel40791765 previously approved these changes Jun 28, 2024
Comment on lines +264 to +274
static int16_t get_bit(const EC_SCALAR *in, size_t i) {
// |in->words| is an array of BN_ULONGs which can be either 8 or 4 bytes long.
#if defined(OPENSSL_64_BIT)
OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) == 8, bn_ulong_not_eight_bytes);
return (in->words[i >> 6] >> (i & 63)) & 1;
#else
OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) == 4, bn_ulong_not_four_bytes);
return (in->words[i >> 5] >> (i & 31)) & 1;
#endif
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Are any extra precautions needed to avoid the C-compiler attempting to optimize this logic?

static int16_t get_bit(const EC_SCALAR *in, size_t i) {
// |in->words| is an array of BN_ULONGs which can be either 8 or 4 bytes long.
#if defined(OPENSSL_64_BIT)
  OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) == 8, bn_ulong_not_eight_bytes);
  return (value_barrier_u64(in->words[i >> 6]) >> (i & 63)) & 1;
#else
  OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) == 4, bn_ulong_not_four_bytes);
  return (value_barrier_u32(in->words[i >> 5]) >> (i & 31)) & 1;
#endif
}

@dkostic dkostic merged commit dd7bb4a into aws:main Jul 1, 2024
96 of 99 checks passed
@dkostic dkostic deleted the ec-nistp-rwnaf-generic branch July 1, 2024 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants