summaryrefslogtreecommitdiffstats
path: root/crypto/bn
diff options
context:
space:
mode:
authorPauli <ppzgs1@gmail.com>2021-11-24 11:38:51 +1000
committerPauli <pauli@openssl.org>2021-12-13 09:35:21 +1100
commit23effeb81fbcdc436b1e871e7fff34456d6bfbaf (patch)
tree551426af4c2e6ce8009012d4d7da4f41eab02800 /crypto/bn
parent391ce6d980c4f8f474ed28d1ea83849cc9a00100 (diff)
Fix Coverity 1494385 logically dead code.
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> (Merged from https://github.com/openssl/openssl/pull/17123)
Diffstat (limited to 'crypto/bn')
-rw-r--r--crypto/bn/rsaz_exp_x2.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/crypto/bn/rsaz_exp_x2.c b/crypto/bn/rsaz_exp_x2.c
index 93f104f68e..3371b6c6d7 100644
--- a/crypto/bn/rsaz_exp_x2.c
+++ b/crypto/bn/rsaz_exp_x2.c
@@ -15,6 +15,7 @@
*/
#include <openssl/opensslconf.h>
+#include <openssl/crypto.h>
#include "rsaz_exp.h"
#ifndef RSAZ_ENABLED
@@ -404,14 +405,23 @@ int RSAZ_mod_exp_x2_ifma256(BN_ULONG *out,
/* Exponentiation */
{
- int rem = modulus_bitsize % exp_win_size;
- int delta = rem ? rem : exp_win_size;
- BN_ULONG table_idx_mask = exp_win_mask;
+ const int rem = modulus_bitsize % exp_win_size;
+ const BN_ULONG table_idx_mask = exp_win_mask;
- int exp_bit_no = modulus_bitsize - delta;
+ int exp_bit_no = modulus_bitsize - rem;
int exp_chunk_no = exp_bit_no / 64;
int exp_chunk_shift = exp_bit_no % 64;
+ /*
+ * If rem == 0, then
+ * exp_bit_no = modulus_bitsize - exp_win_size
+ * However, this isn't possible because rem is { 1024, 1536, 2048 } % 5
+ * which is { 4, 1, 3 } respectively.
+ *
+ * If this assertion ever fails the fix above is easy.
+ */
+ OPENSSL_assert(rem != 0);
+
/* Process 1-st exp window - just init result */
BN_ULONG red_table_idx_0 = expz[exp_chunk_no + 0 * (exp_digits + 1)];
BN_ULONG red_table_idx_1 = expz[exp_chunk_no + 1 * (exp_digits + 1)];