aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/math/numbertheory/numthry.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/math/numbertheory/numthry.cpp')
-rw-r--r--src/lib/math/numbertheory/numthry.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/lib/math/numbertheory/numthry.cpp b/src/lib/math/numbertheory/numthry.cpp
index 31dd72feb..982e9264a 100644
--- a/src/lib/math/numbertheory/numthry.cpp
+++ b/src/lib/math/numbertheory/numthry.cpp
@@ -74,8 +74,6 @@ BigInt lcm(const BigInt& a, const BigInt& b)
return ((a * b) / gcd(a, b));
}
-namespace {
-
/*
* If the modulus is odd, then we can avoid computing A and C. This is
* a critical path algorithm in some instances and an odd modulus is
@@ -84,6 +82,11 @@ namespace {
*/
BigInt inverse_mod_odd_modulus(const BigInt& n, const BigInt& mod)
{
+ if(n.is_negative() || mod.is_negative())
+ throw Invalid_Argument("inverse_mod_odd_modulus: arguments must be non-negative");
+ if(mod < 3 || mod.is_even())
+ throw Invalid_Argument("Bad modulus to inverse_mod_odd_modulus");
+
BigInt u = mod, v = n;
BigInt B = 0, D = 1;
@@ -120,8 +123,6 @@ BigInt inverse_mod_odd_modulus(const BigInt& n, const BigInt& mod)
return D;
}
-}
-
/*
* Find the Modular Inverse
*/