LibCrypto: Implement arbitrarily sized right shifts

Previously we could only shift by words at a time
This commit is contained in:
Hendiadyoin1
2024-03-18 00:40:03 +01:00
committed by Andrew Kaster
parent 9045840e33
commit 1af9fa1968
6 changed files with 34 additions and 0 deletions

View File

@@ -6,6 +6,7 @@
*/
#include "UnsignedBigIntegerAlgorithms.h"
#include <AK/BigIntBase.h>
#include <AK/BuiltinWrappers.h>
#include <AK/NumericLimits.h>
@@ -207,6 +208,15 @@ FLATTEN void UnsignedBigIntegerAlgorithms::shift_left_without_allocation(
}
}
FLATTEN void UnsignedBigIntegerAlgorithms::shift_right_without_allocation(
UnsignedBigInteger const& number,
size_t num_bits,
UnsignedBigInteger& output)
{
output.m_words.resize_and_keep_capacity(number.length() - (num_bits / UnsignedBigInteger::BITS_IN_WORD));
Ops::shift_right(number.words_span(), num_bits, output.words_span());
}
void UnsignedBigIntegerAlgorithms::shift_left_by_n_words(
UnsignedBigInteger const& number,
size_t number_of_words,