mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-28 02:27:19 +02:00
Everywhere: Hoist the Libraries folder to the top-level
This commit is contained in:
committed by
Andreas Kling
parent
950e819ee7
commit
93712b24bf
Notes:
github-actions[bot]
2024-11-10 11:51:52 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/93712b24bf2 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2256 Reviewed-by: https://github.com/sideshowbarker
46
Libraries/LibCrypto/BigInt/Algorithms/Multiplication.cpp
Normal file
46
Libraries/LibCrypto/BigInt/Algorithms/Multiplication.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
|
||||
* Copyright (c) 2020-2021, Dex♪ <dexes.ttp@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "UnsignedBigIntegerAlgorithms.h"
|
||||
|
||||
namespace Crypto {
|
||||
|
||||
/**
|
||||
* Complexity: O(N^2) where N is the number of words in the larger number
|
||||
* Multiplication method:
|
||||
* An integer is equal to the sum of the powers of two
|
||||
* according to the indices of its 'on' bits.
|
||||
* So to multiple x*y, we go over each '1' bit in x (say the i'th bit),
|
||||
* and add y<<i to the result.
|
||||
*/
|
||||
FLATTEN void UnsignedBigIntegerAlgorithms::multiply_without_allocation(
|
||||
UnsignedBigInteger const& left,
|
||||
UnsignedBigInteger const& right,
|
||||
UnsignedBigInteger& temp_shift_result,
|
||||
UnsignedBigInteger& temp_shift_plus,
|
||||
UnsignedBigInteger& temp_shift,
|
||||
UnsignedBigInteger& output)
|
||||
{
|
||||
output.set_to_0();
|
||||
|
||||
// iterate all bits
|
||||
for (size_t word_index = 0; word_index < left.length(); ++word_index) {
|
||||
for (size_t bit_index = 0; bit_index < UnsignedBigInteger::BITS_IN_WORD; ++bit_index) {
|
||||
// If the bit is off - skip over it
|
||||
if (!(left.m_words[word_index] & (1 << bit_index)))
|
||||
continue;
|
||||
|
||||
size_t shift_amount = word_index * UnsignedBigInteger::BITS_IN_WORD + bit_index;
|
||||
|
||||
// output += (right << shift_amount);
|
||||
shift_left_without_allocation(right, shift_amount, temp_shift_result, temp_shift_plus, temp_shift);
|
||||
add_into_accumulator_without_allocation(output, temp_shift);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user