crypto: Extract modexp_even()#1413
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extracts the modular exponentiation logic for even moduli into a separate modexp_even() function, improving code organization and reusability. The extraction follows the same pattern as the existing modexp_odd() and modexp_pow2() helper functions.
Key changes:
- Extracted inline even-modulus logic from
modexp_impl()into a newmodexp_even()template function - Simplified the
modexp_impl()function by replacing ~20 lines of inline code with a single function call - Added documentation referencing the Montgomery reduction algorithm paper
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| // Follow "Montgomery reduction with even modulus" by Çetin Kaya Koç. | ||
| // https://cetinkayakoc.net/docs/j34.pdf | ||
| assert(k != 0); |
There was a problem hiding this comment.
Consider adding an explanatory comment for the assertion, similar to the one in modexp_pow2 at line 77. This would clarify why k must be non-zero and improve code consistency.
| assert(k != 0); | |
| assert(k != 0); // k must be non-zero because the modulus has the form mod_odd * 2^k with k > 0; k == 0 is handled by the odd-modulus path. |
6bf47cf to
9be8a68
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1413 +/- ##
==========================================
+ Coverage 78.93% 81.67% +2.74%
==========================================
Files 151 152 +1
Lines 13543 13566 +23
Branches 3216 3217 +1
==========================================
+ Hits 10690 11080 +390
+ Misses 574 343 -231
+ Partials 2279 2143 -136
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
9be8a68 to
e66a260
Compare
No description provided.