mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-07 11:42:51 +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
|
@ -203,7 +203,7 @@ FLATTEN void UnsignedBigIntegerAlgorithms::shift_left_without_allocation(
|
|||
}
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void UnsignedBigIntegerAlgorithms::shift_left_by_n_words(
|
||||
void UnsignedBigIntegerAlgorithms::shift_left_by_n_words(
|
||||
UnsignedBigInteger const& number,
|
||||
size_t number_of_words,
|
||||
UnsignedBigInteger& output)
|
||||
|
@ -216,6 +216,17 @@ ALWAYS_INLINE void UnsignedBigIntegerAlgorithms::shift_left_by_n_words(
|
|||
__builtin_memcpy(&output.m_words.data()[number_of_words], number.m_words.data(), number.m_words.size() * sizeof(unsigned));
|
||||
}
|
||||
|
||||
void UnsignedBigIntegerAlgorithms::shift_right_by_n_words(
|
||||
UnsignedBigInteger const& number,
|
||||
size_t number_of_words,
|
||||
UnsignedBigInteger& output)
|
||||
{
|
||||
// shifting right by N words means just not copying the first words
|
||||
output.set_to_0();
|
||||
output.m_words.resize_and_keep_capacity(number.length() - number_of_words);
|
||||
__builtin_memcpy(output.m_words.data(), &number.m_words.data()[number_of_words], (number.m_words.size() - number_of_words) * sizeof(unsigned));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the word at a requested index in the result of a shift operation
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue