mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-17 16:42:54 +00:00
LibCrypto: Add the montgomery modular power algorithm
This algorithm allows for much faster computations of modular powers (around a 5x-10x speedup of the Crypto test). However, it is only valid for odd modulo values, and therefore the old algorithm must be kept for computations involving even modulo values.
This commit is contained in:
parent
5071989545
commit
485adb5e29
Notes:
sideshowbarker
2024-07-18 18:13:40 +09:00
Author: https://github.com/Dexesttp
Commit: 485adb5e29
Pull-request: https://github.com/SerenityOS/serenity/pull/7067
Reviewed-by: https://github.com/alimpfard
5 changed files with 264 additions and 2 deletions
|
@ -37,6 +37,20 @@ UnsignedBigInteger ModularPower(const UnsignedBigInteger& b, const UnsignedBigIn
|
|||
if (m == 1)
|
||||
return 0;
|
||||
|
||||
if (m.is_odd()) {
|
||||
UnsignedBigInteger temp_z0 { 0 };
|
||||
UnsignedBigInteger temp_rr { 0 };
|
||||
UnsignedBigInteger temp_one { 0 };
|
||||
UnsignedBigInteger temp_z { 0 };
|
||||
UnsignedBigInteger temp_zz { 0 };
|
||||
UnsignedBigInteger temp_x { 0 };
|
||||
UnsignedBigInteger temp_extra { 0 };
|
||||
|
||||
UnsignedBigInteger result;
|
||||
UnsignedBigIntegerAlgorithms::montgomery_modular_power_with_minimal_allocations(b, e, m, temp_z0, temp_rr, temp_one, temp_z, temp_zz, temp_x, temp_extra, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
UnsignedBigInteger ep { e };
|
||||
UnsignedBigInteger base { b };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue