From 36714fc8ee8764b2ae624d3c9dfdb1d798bb2924 Mon Sep 17 00:00:00 2001 From: Daniel Hirche Date: Tue, 20 Feb 2018 12:43:43 +0100 Subject: [PATCH] Remove redundant length-check in |ec_wNAF_mul|. Right now, |g_wNAF| and |p_wNAF| are of same size. This change makes GCC's "-Werror=logical-op" happy and adds a compile-time assertion in case the initial size of either array ever changes. Change-Id: I29e39a7a121a0a9d016c53da6b7c25675ddecbdc Reviewed-on: https://boringssl-review.googlesource.com/26104 Reviewed-by: David Benjamin Commit-Queue: David Benjamin CQ-Verified: CQ bot account: commit-bot@chromium.org --- crypto/fipsmodule/ec/wnaf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crypto/fipsmodule/ec/wnaf.c b/crypto/fipsmodule/ec/wnaf.c index c8bdadd9..7bc0bc7b 100644 --- a/crypto/fipsmodule/ec/wnaf.c +++ b/crypto/fipsmodule/ec/wnaf.c @@ -73,6 +73,7 @@ #include #include #include +#include #include "internal.h" #include "../bn/internal.h" @@ -250,8 +251,12 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const EC_SCALAR *g_scalar, size_t wsize = window_bits_for_scalar_size(bits); size_t wNAF_len = bits + 1; size_t precomp_len = (size_t)1 << (wsize - 1); + + OPENSSL_COMPILE_ASSERT( + OPENSSL_ARRAY_SIZE(g_wNAF) == OPENSSL_ARRAY_SIZE(p_wNAF), + g_wNAF_and_p_wNAF_are_different_sizes); + if (wNAF_len > OPENSSL_ARRAY_SIZE(g_wNAF) || - wNAF_len > OPENSSL_ARRAY_SIZE(p_wNAF) || 2 * precomp_len > OPENSSL_ARRAY_SIZE(precomp_storage)) { OPENSSL_PUT_ERROR(EC, ERR_R_INTERNAL_ERROR); goto err;