mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:37:35 +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
1 changed files with 8 additions and 8 deletions
|
@ -34,7 +34,7 @@
|
||||||
namespace Crypto {
|
namespace Crypto {
|
||||||
namespace NumberTheory {
|
namespace NumberTheory {
|
||||||
|
|
||||||
static auto ModularInverse(const UnsignedBigInteger& a_, const UnsignedBigInteger& b) -> UnsignedBigInteger
|
inline UnsignedBigInteger ModularInverse(const UnsignedBigInteger& a_, const UnsignedBigInteger& b)
|
||||||
{
|
{
|
||||||
if (b == 1)
|
if (b == 1)
|
||||||
return { 1 };
|
return { 1 };
|
||||||
|
@ -121,7 +121,7 @@ static auto ModularInverse(const UnsignedBigInteger& a_, const UnsignedBigIntege
|
||||||
return temp_remainder;
|
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)
|
if (m == 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -165,18 +165,18 @@ static auto ModularPower(const UnsignedBigInteger& b, const UnsignedBigInteger&
|
||||||
// it will allocate and free a lot of memory!
|
// it will allocate and free a lot of memory!
|
||||||
// Please use |ModularPower| if your use-case is modexp.
|
// Please use |ModularPower| if your use-case is modexp.
|
||||||
template<typename IntegerType>
|
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 ep { e };
|
||||||
IntegerType base { b };
|
IntegerType base { b };
|
||||||
IntegerType exp { 1 };
|
IntegerType exp { 1 };
|
||||||
|
|
||||||
while (!(ep < 1)) {
|
while (!(ep < IntegerType { 1 })) {
|
||||||
if (ep.words()[0] % 2 == 1)
|
if (ep.words()[0] % 2 == 1)
|
||||||
exp.set_to(exp.multiplied_by(base));
|
exp.set_to(exp.multiplied_by(base));
|
||||||
|
|
||||||
// ep = ep / 2;
|
// ep = ep / 2;
|
||||||
ep.set_to(ep.divided_by(2).quotient);
|
ep.set_to(ep.divided_by(IntegerType { 2 }).quotient);
|
||||||
|
|
||||||
// base = base * base
|
// base = base * base
|
||||||
base.set_to(base.multiplied_by(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_a;
|
||||||
UnsignedBigInteger temp_b;
|
UnsignedBigInteger temp_b;
|
||||||
|
@ -237,7 +237,7 @@ static UnsignedBigInteger GCD(const UnsignedBigInteger& a, const UnsignedBigInte
|
||||||
return output;
|
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_a;
|
||||||
UnsignedBigInteger temp_b;
|
UnsignedBigInteger temp_b;
|
||||||
|
@ -338,7 +338,7 @@ static bool is_probably_prime(const UnsignedBigInteger& p)
|
||||||
return MR_primality_test(p, tests);
|
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);
|
ASSERT(bits >= 33);
|
||||||
UnsignedBigInteger min = UnsignedBigInteger::from_base10("6074001000").shift_left(bits - 33);
|
UnsignedBigInteger min = UnsignedBigInteger::from_base10("6074001000").shift_left(bits - 33);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue