aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-08-23 10:02:18 -0400
committerJack Lloyd <[email protected]>2018-08-23 10:02:18 -0400
commit2de92b238374fd37ba5001aaabac68782bae77b1 (patch)
tree562e93078cbdef4e4ca5872cff5b7de6d441b33e /src
parentc784b6a77f99512ae53de55fd0b5fe78c473cfdd (diff)
parent265e0ca5af869710804dc1b7870a27d4e0ffe1b6 (diff)
Merge GH #1656 Add operator*(BigInt,word)
Diffstat (limited to 'src')
-rw-r--r--src/lib/math/bigint/big_ops3.cpp18
-rw-r--r--src/lib/math/bigint/bigint.h3
2 files changed, 21 insertions, 0 deletions
diff --git a/src/lib/math/bigint/big_ops3.cpp b/src/lib/math/bigint/big_ops3.cpp
index 492a69ad0..3f34e0bf1 100644
--- a/src/lib/math/bigint/big_ops3.cpp
+++ b/src/lib/math/bigint/big_ops3.cpp
@@ -126,6 +126,24 @@ BigInt operator*(const BigInt& x, const BigInt& y)
}
/*
+* Multiplication Operator
+*/
+BigInt operator*(const BigInt& x, word y)
+ {
+ const size_t x_sw = x.sig_words();
+
+ BigInt z(BigInt::Positive, x_sw + 1);
+
+ if(x_sw && y)
+ {
+ bigint_linmul3(z.mutable_data(), x.data(), x_sw, y);
+ z.set_sign(x.sign());
+ }
+
+ return z;
+ }
+
+/*
* Division Operator
*/
BigInt operator/(const BigInt& x, const BigInt& y)
diff --git a/src/lib/math/bigint/bigint.h b/src/lib/math/bigint/bigint.h
index 0d35cbbeb..8a434e6bb 100644
--- a/src/lib/math/bigint/bigint.h
+++ b/src/lib/math/bigint/bigint.h
@@ -842,6 +842,9 @@ BigInt BOTAN_PUBLIC_API(2,0) operator-(const BigInt& x, const BigInt& y);
BigInt BOTAN_PUBLIC_API(2,7) operator-(const BigInt& x, word y);
BigInt BOTAN_PUBLIC_API(2,0) operator*(const BigInt& x, const BigInt& y);
+BigInt BOTAN_PUBLIC_API(2,8) operator*(const BigInt& x, word y);
+inline BigInt operator*(word x, const BigInt& y) { return y*x; }
+
BigInt BOTAN_PUBLIC_API(2,0) operator/(const BigInt& x, const BigInt& d);
BigInt BOTAN_PUBLIC_API(2,0) operator%(const BigInt& x, const BigInt& m);
word BOTAN_PUBLIC_API(2,0) operator%(const BigInt& x, word m);