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:
Linus Groh 2020-06-06 01:13:58 +01:00 committed by Andreas Kling
parent 75b4cc13a0
commit fbb1d9afe5
Notes: sideshowbarker 2024-07-19 05:46:38 +09:00

View file

@ -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);