aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/math/bigint
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2020-03-06 07:07:29 -0500
committerJack Lloyd <[email protected]>2020-03-06 07:12:26 -0500
commit75287eb37f2816a3d7e48988573aee5de47a60cb (patch)
tree08d5277a9e6f4e693b8c6afafb8504125f1754d1 /src/lib/math/bigint
parent06a55af16fbee536cf3aa53370195b22327ca54f (diff)
Add BigInt::ct_cond_add
Also make low_zero_bits constant time.
Diffstat (limited to 'src/lib/math/bigint')
-rw-r--r--src/lib/math/bigint/bigint.cpp9
-rw-r--r--src/lib/math/bigint/bigint.h7
2 files changed, 15 insertions, 1 deletions
diff --git a/src/lib/math/bigint/bigint.cpp b/src/lib/math/bigint/bigint.cpp
index 3ada94dce..fac82defa 100644
--- a/src/lib/math/bigint/bigint.cpp
+++ b/src/lib/math/bigint/bigint.cpp
@@ -453,6 +453,15 @@ void BigInt::binary_decode(const uint8_t buf[], size_t length)
m_data.swap(reg);
}
+void BigInt::ct_cond_add(bool predicate, const BigInt& value)
+ {
+ this->grow_to(1 + value.sig_words());
+
+ bigint_cnd_add(static_cast<word>(predicate),
+ this->mutable_data(), this->size(),
+ value.data(), value.sig_words());
+ }
+
void BigInt::ct_cond_swap(bool predicate, BigInt& other)
{
const size_t max_words = std::max(size(), other.size());
diff --git a/src/lib/math/bigint/bigint.h b/src/lib/math/bigint/bigint.h
index ac0a57038..9fda4ceb0 100644
--- a/src/lib/math/bigint/bigint.h
+++ b/src/lib/math/bigint/bigint.h
@@ -721,6 +721,11 @@ class BOTAN_PUBLIC_API(2,0) BigInt final
void ct_cond_swap(bool predicate, BigInt& other);
/**
+ * If predicate is true add value to *this
+ */
+ void ct_cond_add(bool predicate, const BigInt& value);
+
+ /**
* If predicate is true flip the sign of *this
*/
void cond_flip_sign(bool predicate);
@@ -982,7 +987,7 @@ class BOTAN_PUBLIC_API(2,0) BigInt final
{
const word mask = (static_cast<word>(1) << (n % BOTAN_MP_WORD_BITS)) - 1;
const size_t len = size() - (top_word + 1);
- if (len > 0)
+ if(len > 0)
{
clear_mem(&m_reg[top_word+1], len);
}