diff --git a/ChangeLog b/ChangeLog index 4d53b8969fb386a4fe6b962d95c602ad935882cd..be68bab2708b9cd25b905869f4244863fca3a137 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2023-11-12 Niels Möller <nisse@lysator.liu.se> + + * gmp-glue.h (GMP_LIMB_BITS) [NETTLE_USE_MINI_GMP]: Define as alias for + GMP_NUMB_BITS. + (is_zero_limb): Move inline function here. Add static, for + compatibility with c89. and mini-gmp builds. + * gmp-glue.c (sec_zero_p): Use is_zero_limb. + 2023-11-06 Niels Möller <nisse@lysator.liu.se> Avoid comparison like cnd = (x == 0) in code intended to be diff --git a/ecc-internal.h b/ecc-internal.h index 2a5e3ae10f0049586af4f3e42c288bf57c59b6d8..53359b57e2bae0bd3bcb561c5d571161442e7997 100644 --- a/ecc-internal.h +++ b/ecc-internal.h @@ -85,13 +85,6 @@ #define curve25519_eh_to_x _nettle_curve25519_eh_to_x #define curve448_eh_to_x _nettle_curve448_eh_to_x -inline int -is_zero_limb (mp_limb_t x) -{ - x |= (x << 1); - return ((x >> 1) - 1) >> (GMP_LIMB_BITS - 1); -} - extern const struct ecc_curve _nettle_secp_192r1; extern const struct ecc_curve _nettle_secp_224r1; extern const struct ecc_curve _nettle_secp_256r1; diff --git a/gmp-glue.c b/gmp-glue.c index ffce6c306bee08d245f9918c9a0786b9bffa9075..45189cdc16044a6b994e63b7aac1ef298368a2d6 100644 --- a/gmp-glue.c +++ b/gmp-glue.c @@ -130,7 +130,7 @@ sec_zero_p (const mp_limb_t *ap, mp_size_t n) for (i = 0, w = 0; i < n; i++) w |= ap[i]; - return w == 0; + return is_zero_limb (w); } /* Additional convenience functions. */ diff --git a/gmp-glue.h b/gmp-glue.h index dc0ede2abd8cdb3f520c7a798e83a34148484c2b..afe946355032851575621b293b2d58b69dc8ccc1 100644 --- a/gmp-glue.h +++ b/gmp-glue.h @@ -56,6 +56,8 @@ #define TMP_GMP_FREE(name) (gmp_free(name, tmp_##name##_size)) #if NETTLE_USE_MINI_GMP +#define GMP_LIMB_BITS GMP_NUMB_BITS + mp_limb_t mpn_cnd_add_n (mp_limb_t cnd, mp_limb_t *rp, const mp_limb_t *ap, const mp_limb_t *bp, mp_size_t n); @@ -72,6 +74,13 @@ mpn_sec_tabselect (volatile mp_limb_t *rp, volatile const mp_limb_t *table, mp_size_t rn, unsigned tn, unsigned k); #endif +static inline int +is_zero_limb (mp_limb_t x) +{ + x |= (x << 1); + return ((x >> 1) - 1) >> (GMP_LIMB_BITS - 1); +} + /* Side-channel silent variant of mpn_zero_p. */ int sec_zero_p (const mp_limb_t *ap, mp_size_t n);