aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-12-14 08:59:05 -0500
committerJack Lloyd <[email protected]>2018-12-14 08:59:05 -0500
commitfd88c08eec57d0d73071d9c3f61171b04d965df6 (patch)
treec5c93f6c12e065e1817ab8314e1c8b674478f8f3
parent9eac2cccf6a1bc3c3a9de646e86d6e992e32188d (diff)
In PointGFp addition, prevent all_zeros from being shortcircuited
This doesn't matter much but it causes confusing valgrind output when const-time checking since it distinguishes between the two possible conditional returns.
-rw-r--r--src/lib/pubkey/ec_group/point_gfp.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/lib/pubkey/ec_group/point_gfp.cpp b/src/lib/pubkey/ec_group/point_gfp.cpp
index df9afa18d..5574a360c 100644
--- a/src/lib/pubkey/ec_group/point_gfp.cpp
+++ b/src/lib/pubkey/ec_group/point_gfp.cpp
@@ -11,6 +11,7 @@
#include <botan/numthry.h>
#include <botan/rng.h>
#include <botan/internal/rounding.h>
+#include <botan/internal/ct_utils.h>
namespace Botan {
@@ -76,12 +77,12 @@ inline void resize_ws(std::vector<BigInt>& ws_bn, size_t cap_size)
ws_bn[i].get_word_vector().resize(cap_size);
}
-inline bool all_zeros(const word x[], size_t len)
+inline word all_zeros(const word x[], size_t len)
{
word z = 0;
for(size_t i = 0; i != len; ++i)
z |= x[i];
- return (z == 0);
+ return CT::Mask<word>::is_zero(z).value();
}
}
@@ -90,8 +91,10 @@ void PointGFp::add_affine(const word x_words[], size_t x_size,
const word y_words[], size_t y_size,
std::vector<BigInt>& ws_bn)
{
- if(all_zeros(x_words, x_size) && all_zeros(y_words, y_size))
+ if(all_zeros(x_words, x_size) & all_zeros(y_words, y_size))
+ {
return;
+ }
if(is_zero())
{
@@ -172,7 +175,7 @@ void PointGFp::add(const word x_words[], size_t x_size,
const word z_words[], size_t z_size,
std::vector<BigInt>& ws_bn)
{
- if(all_zeros(x_words, x_size) && all_zeros(z_words, z_size))
+ if(all_zeros(x_words, x_size) & all_zeros(z_words, z_size))
return;
if(is_zero())