Hello, again for _gcry_mpih_cmp_ui,

Jussi Kivilinna <jussi.kivili...@iki.fi> wrote:
> * mpi/mpih-const-time.c (_gcry_mpih_cmp_ui): Avoid conditional
> branches for return value selection.

After the commit of this, I realize that there is a thinko.

When IS_ALL_ZERO (meaning all the limbs sans the least one are zero)
is false, the function should return 1 (instead of 0).

Something like this:

diff --git a/mpi/mpih-const-time.c b/mpi/mpih-const-time.c
index d8b66c46..a6314932 100644
--- a/mpi/mpih-const-time.c
+++ b/mpi/mpih-const-time.c
@@ -232,5 +232,5 @@ _gcry_mpih_cmp_ui (mpi_ptr_t up, mpi_size_t usize, unsigned 
long v)
   for (i = 1; i < usize; i++)
     is_all_zero &= ct_ulong_gen_mask(mpih_limb_is_zero (up[i]));
 
-  return cmp0 & (int)is_all_zero;
+  return (cmp0 & (int)is_all_zero) | (~is_all_zero & 1);
 }

-- 

_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@gnupg.org
https://lists.gnupg.org/mailman/listinfo/gcrypt-devel

Reply via email to