mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibCrypto: Make ModularFunctions.h compile as part of Lagom
Compiler was complaining about two ambiguous overloads. Also make some functions "inline" to fix warnings about unused functions.
This commit is contained in:
parent
75b4cc13a0
commit
fbb1d9afe5
Notes:
sideshowbarker
2024-07-19 05:46:38 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/fbb1d9afe58 Pull-request: https://github.com/SerenityOS/serenity/pull/2509 Reviewed-by: https://github.com/alimpfard
1 changed files with 8 additions and 8 deletions
|
@ -34,7 +34,7 @@
|
|||
namespace Crypto {
|
||||
namespace NumberTheory {
|
||||
|
||||
static auto ModularInverse(const UnsignedBigInteger& a_, const UnsignedBigInteger& b) -> UnsignedBigInteger
|
||||
inline UnsignedBigInteger ModularInverse(const UnsignedBigInteger& a_, const UnsignedBigInteger& b)
|
||||
{
|
||||
if (b == 1)
|
||||
return { 1 };
|
||||
|
@ -121,7 +121,7 @@ static auto ModularInverse(const UnsignedBigInteger& a_, const UnsignedBigIntege
|
|||
return temp_remainder;
|
||||
}
|
||||
|
||||
static auto ModularPower(const UnsignedBigInteger& b, const UnsignedBigInteger& e, const UnsignedBigInteger& m) -> UnsignedBigInteger
|
||||
static UnsignedBigInteger ModularPower(const UnsignedBigInteger& b, const UnsignedBigInteger& e, const UnsignedBigInteger& m)
|
||||
{
|
||||
if (m == 1)
|
||||
return 0;
|
||||
|
@ -165,18 +165,18 @@ static auto ModularPower(const UnsignedBigInteger& b, const UnsignedBigInteger&
|
|||
// it will allocate and free a lot of memory!
|
||||
// Please use |ModularPower| if your use-case is modexp.
|
||||
template<typename IntegerType>
|
||||
static auto Power(const IntegerType& b, const IntegerType& e) -> IntegerType
|
||||
static IntegerType Power(const IntegerType& b, const IntegerType& e)
|
||||
{
|
||||
IntegerType ep { e };
|
||||
IntegerType base { b };
|
||||
IntegerType exp { 1 };
|
||||
|
||||
while (!(ep < 1)) {
|
||||
while (!(ep < IntegerType { 1 })) {
|
||||
if (ep.words()[0] % 2 == 1)
|
||||
exp.set_to(exp.multiplied_by(base));
|
||||
|
||||
// ep = ep / 2;
|
||||
ep.set_to(ep.divided_by(2).quotient);
|
||||
ep.set_to(ep.divided_by(IntegerType { 2 }).quotient);
|
||||
|
||||
// base = base * base
|
||||
base.set_to(base.multiplied_by(base));
|
||||
|
@ -220,7 +220,7 @@ static void GCD_without_allocation(
|
|||
}
|
||||
}
|
||||
|
||||
static UnsignedBigInteger GCD(const UnsignedBigInteger& a, const UnsignedBigInteger& b)
|
||||
inline UnsignedBigInteger GCD(const UnsignedBigInteger& a, const UnsignedBigInteger& b)
|
||||
{
|
||||
UnsignedBigInteger temp_a;
|
||||
UnsignedBigInteger temp_b;
|
||||
|
@ -237,7 +237,7 @@ static UnsignedBigInteger GCD(const UnsignedBigInteger& a, const UnsignedBigInte
|
|||
return output;
|
||||
}
|
||||
|
||||
static auto LCM(const UnsignedBigInteger& a, const UnsignedBigInteger& b) -> UnsignedBigInteger
|
||||
inline UnsignedBigInteger LCM(const UnsignedBigInteger& a, const UnsignedBigInteger& b)
|
||||
{
|
||||
UnsignedBigInteger temp_a;
|
||||
UnsignedBigInteger temp_b;
|
||||
|
@ -338,7 +338,7 @@ static bool is_probably_prime(const UnsignedBigInteger& p)
|
|||
return MR_primality_test(p, tests);
|
||||
}
|
||||
|
||||
static UnsignedBigInteger random_big_prime(size_t bits)
|
||||
inline static UnsignedBigInteger random_big_prime(size_t bits)
|
||||
{
|
||||
ASSERT(bits >= 33);
|
||||
UnsignedBigInteger min = UnsignedBigInteger::from_base10("6074001000").shift_left(bits - 33);
|
||||
|
|
Loading…
Add table
Reference in a new issue