aboutsummaryrefslogtreecommitdiffstats
path: root/src/math/bigint
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-08-01 14:48:45 +0000
committerlloyd <[email protected]>2012-08-01 14:48:45 +0000
commit3e4ecea6915f4ceb3c0426cf6d179fcc078dd8df (patch)
tree7ffda5d9c17247b83b8f1f1761cfd4aace1e9e3c /src/math/bigint
parent10e7da367713352975c684d18d1377559c71ea24 (diff)
Remove BigInt(NumberType type, size_t n) and replace it with a static
BigInt function power_of_2. (Power2 was the only available NumberType)
Diffstat (limited to 'src/math/bigint')
-rw-r--r--src/math/bigint/big_ops2.cpp5
-rw-r--r--src/math/bigint/big_ops3.cpp3
-rw-r--r--src/math/bigint/big_rand.cpp13
-rw-r--r--src/math/bigint/bigint.h27
4 files changed, 18 insertions, 30 deletions
diff --git a/src/math/bigint/big_ops2.cpp b/src/math/bigint/big_ops2.cpp
index f47cbb4e8..37b6a5df1 100644
--- a/src/math/bigint/big_ops2.cpp
+++ b/src/math/bigint/big_ops2.cpp
@@ -132,7 +132,7 @@ BigInt& BigInt::operator*=(const BigInt& y)
*/
BigInt& BigInt::operator/=(const BigInt& y)
{
- if(y.sig_words() == 1 && power_of_2(y.word_at(0)))
+ if(y.sig_words() == 1 && is_power_of_2(y.word_at(0)))
(*this) >>= (y.bits() - 1);
else
(*this) = (*this) / y;
@@ -154,7 +154,8 @@ word BigInt::operator%=(word mod)
{
if(mod == 0)
throw BigInt::DivideByZero();
- if(power_of_2(mod))
+
+ if(is_power_of_2(mod))
{
word result = (word_at(0) & (mod - 1));
clear();
diff --git a/src/math/bigint/big_ops3.cpp b/src/math/bigint/big_ops3.cpp
index acd139716..cad730197 100644
--- a/src/math/bigint/big_ops3.cpp
+++ b/src/math/bigint/big_ops3.cpp
@@ -137,7 +137,8 @@ word operator%(const BigInt& n, word mod)
{
if(mod == 0)
throw BigInt::DivideByZero();
- if(power_of_2(mod))
+
+ if(is_power_of_2(mod))
return (n.word_at(0) & (mod - 1));
word remainder = 0;
diff --git a/src/math/bigint/big_rand.cpp b/src/math/bigint/big_rand.cpp
index a6776a296..78b9ee244 100644
--- a/src/math/bigint/big_rand.cpp
+++ b/src/math/bigint/big_rand.cpp
@@ -11,19 +11,6 @@
namespace Botan {
/*
-* Construct a BigInt of a specific form
-*/
-BigInt::BigInt(NumberType type, size_t bits)
- {
- set_sign(Positive);
-
- if(type == Power2)
- set_bit(bits);
- else
- throw Invalid_Argument("BigInt(NumberType): Unknown type");
- }
-
-/*
* Randomize this number
*/
void BigInt::randomize(RandomNumberGenerator& rng,
diff --git a/src/math/bigint/bigint.h b/src/math/bigint/bigint.h
index a4918509f..4d3e37708 100644
--- a/src/math/bigint/bigint.h
+++ b/src/math/bigint/bigint.h
@@ -33,11 +33,6 @@ class BOTAN_DLL BigInt
enum Sign { Negative = 0, Positive = 1 };
/**
- * Number types (currently only power-of-2 supported)
- */
- enum NumberType { Power2 };
-
- /**
* DivideByZero Exception
*/
struct BOTAN_DLL DivideByZero : public Exception
@@ -368,6 +363,19 @@ class BOTAN_DLL BigInt
const BigInt& min,
const BigInt& max);
+
+ /**
+ * Create a power of two
+ * @param n the power of two to create
+ * @return bigint representing 2^n
+ */
+ static BigInt power_of_2(size_t n)
+ {
+ BigInt b;
+ b.set_bit(n);
+ return b;
+ }
+
/**
* Encode the integer value from a BigInt to a std::vector of bytes
* @param n the BigInt to use as integer source
@@ -495,15 +503,6 @@ class BOTAN_DLL BigInt
BigInt(Sign sign, size_t n);
/**
- * Create a number of the specified type and size
- * @param type the type of number to create. For Power2,
- * will create the integer 2^n
- * @param n a size/length parameter, interpretation depends upon
- * the value of type
- */
- BigInt(NumberType type, size_t n);
-
- /**
* Move constructor
*/
BigInt(BigInt&& other)