From 5be9a0c16d68f9967564b2d46fe0cc4fc6d63b85 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Fri, 14 Dec 2018 07:32:55 -0500 Subject: Simplify the const time lookup in ECC scalar mul Code is easier to understand and it may let the CPU interleave the loads and logical ops better. Slightly faster on my machine. --- src/lib/pubkey/ec_group/point_mul.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src/lib/pubkey') diff --git a/src/lib/pubkey/ec_group/point_mul.cpp b/src/lib/pubkey/ec_group/point_mul.cpp index 49d2f7be6..f5b621dda 100644 --- a/src/lib/pubkey/ec_group/point_mul.cpp +++ b/src/lib/pubkey/ec_group/point_mul.cpp @@ -141,18 +141,15 @@ PointGFp PointGFp_Base_Point_Precompute::mul(const BigInt& k, for(size_t j = 0; j != elem_size; ++j) { - const word w1 = m_W[base_addr + 0*elem_size + j]; - const word w2 = m_W[base_addr + 1*elem_size + j]; - const word w3 = m_W[base_addr + 2*elem_size + j]; - const word w4 = m_W[base_addr + 3*elem_size + j]; - const word w5 = m_W[base_addr + 4*elem_size + j]; - const word w6 = m_W[base_addr + 5*elem_size + j]; - const word w7 = m_W[base_addr + 6*elem_size + j]; - - const word wl = w_is_1.select(w1, w_is_2.select(w2, w_is_3.select(w3, 0))); - const word wr = w_is_4.select(w4, w_is_5.select(w5, w_is_6.select(w6, w_is_7.select(w7, 0)))); - - Wt[j] = wl | wr; + const word w1 = w_is_1.if_set_return(m_W[base_addr + 0*elem_size + j]); + const word w2 = w_is_2.if_set_return(m_W[base_addr + 1*elem_size + j]); + const word w3 = w_is_3.if_set_return(m_W[base_addr + 2*elem_size + j]); + const word w4 = w_is_4.if_set_return(m_W[base_addr + 3*elem_size + j]); + const word w5 = w_is_5.if_set_return(m_W[base_addr + 4*elem_size + j]); + const word w6 = w_is_6.if_set_return(m_W[base_addr + 5*elem_size + j]); + const word w7 = w_is_7.if_set_return(m_W[base_addr + 6*elem_size + j]); + + Wt[j] = w1 | w2 | w3 | w4 | w5 | w6 | w7; } R.add_affine(&Wt[0], m_p_words, &Wt[m_p_words], m_p_words, ws); -- cgit v1.2.3