diff options
author | Jack Lloyd <[email protected]> | 2018-11-28 10:35:17 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-11-28 10:35:17 -0500 |
commit | 007314c530eb12d414ced07515f8cbc25a0f64f5 (patch) | |
tree | dc887f97efa0248aa5e7b8468c94145f6a1305f8 /src/lib/math/bigint/bigint.cpp | |
parent | b03f38f57d4f50ace1ed8b57d83ba70eb5bc1dfb (diff) |
Add CT::Mask type
Diffstat (limited to 'src/lib/math/bigint/bigint.cpp')
-rw-r--r-- | src/lib/math/bigint/bigint.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/lib/math/bigint/bigint.cpp b/src/lib/math/bigint/bigint.cpp index 2cb9394ce..667035686 100644 --- a/src/lib/math/bigint/bigint.cpp +++ b/src/lib/math/bigint/bigint.cpp @@ -146,7 +146,7 @@ bool BigInt::is_equal(const BigInt& other) const return false; return bigint_ct_is_eq(this->data(), this->sig_words(), - other.data(), other.sig_words()); + other.data(), other.sig_words()).is_set(); } bool BigInt::is_less_than(const BigInt& other) const @@ -160,11 +160,11 @@ bool BigInt::is_less_than(const BigInt& other) const if(other.is_negative() && this->is_negative()) { return !bigint_ct_is_lt(other.data(), other.sig_words(), - this->data(), this->sig_words(), true); + this->data(), this->sig_words(), true).is_set(); } return bigint_ct_is_lt(this->data(), this->sig_words(), - other.data(), other.sig_words()); + other.data(), other.sig_words()).is_set(); } void BigInt::encode_words(word out[], size_t size) const @@ -187,7 +187,7 @@ size_t BigInt::Data::calc_sig_words() const for(size_t i = 0; i != m_reg.size(); ++i) { const word w = m_reg[m_reg.size() - i - 1]; - sub &= CT::is_zero(w); + sub &= CT::Mask<word>::is_zero(w).value(); sig -= sub; } @@ -393,13 +393,18 @@ void BigInt::ct_cond_assign(bool predicate, BigInt& other) const size_t t_words = size(); const size_t o_words = other.size(); + if(o_words < t_words) + grow_to(o_words); + const size_t r_words = std::max(t_words, o_words); - const word mask = CT::expand_mask<word>(predicate); + const auto mask = CT::Mask<word>::expand(predicate); for(size_t i = 0; i != r_words; ++i) { - this->set_word_at(i, CT::select<word>(mask, other.word_at(i), this->word_at(i))); + const word o_word = other.word_at(i); + const word t_word = this->word_at(i); + this->set_word_at(i, mask.select(o_word, t_word)); } } @@ -430,10 +435,13 @@ void BigInt::const_time_lookup(secure_vector<word>& output, BOTAN_ASSERT(vec[i].size() >= words, "Word size as expected in const_time_lookup"); - const word mask = CT::is_equal(i, idx); + const auto mask = CT::Mask<word>::is_equal(i, idx); for(size_t w = 0; w != words; ++w) - output[w] |= CT::select<word>(mask, vec[i].word_at(w), 0); + { + const word viw = vec[i].word_at(w); + output[w] = mask.if_set_return(viw); + } } CT::unpoison(idx); |