-
Notifications
You must be signed in to change notification settings - Fork 121
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
51e9056
to
fd41d29
Compare
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 | ||
} | ||
|
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.
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
}
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.