mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-07 00:56:14 +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:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user