aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-08-23 05:08:33 -0400
committerJack Lloyd <[email protected]>2018-08-23 05:08:33 -0400
commit265e0ca5af869710804dc1b7870a27d4e0ffe1b6 (patch)
tree9667e4fa4b9337a1dd56ad001d6059eb19538039 /src/lib
parente53a1393687d8f33ab7230fc1dc2a062c28925c0 (diff)
Add operator*(BigInt, word)
Gets hit about 2 million times in the test suite, avoids creating a temp BigInt (with alloc+free) or checking size of y.
Diffstat (limited to 'src/lib')
-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);