Commit e775f329 authored by Niels Möller's avatar Niels Möller

Make cnd_swap non-static.

parent eee1f125
2014-09-09 Niels Möller <nisse@lysator.liu.se>
* gmp-glue.c (cnd_swap): Moved function here, made non-static.
Changed cnd type to mp_limb_t, for consistency with GMP
mpn_cnd_add_n.
* sec-modinv.c (cnd_swap): ... old location.
* gmp-glue.h (cnd_swap): Declare function.
2014-09-06 Niels Möller <nisse@lysator.liu.se>
* examples/hogweed-benchmark.c (bench_curve25519_mul_g)
......
......@@ -142,6 +142,22 @@ mpn_zero (mp_ptr ptr, mp_size_t n)
}
#endif /* !GMP_HAVE_mpn_copyd */
void
cnd_swap (mp_limb_t cnd, mp_limb_t *ap, mp_limb_t *bp, mp_size_t n)
{
mp_limb_t mask = - (mp_limb_t) (cnd != 0);
mp_size_t i;
for (i = 0; i < n; i++)
{
mp_limb_t a, b, t;
a = ap[i];
b = bp[i];
t = (a ^ b) & mask;
ap[i] = a ^ t;
bp[i] = b ^ t;
}
}
/* Additional convenience functions. */
int
......
......@@ -66,6 +66,7 @@
#define mpn_sqr(rp, ap, n) mpn_mul_n((rp), (ap), (ap), (n))
#endif
#define cnd_swap _nettle_cnd_swap
#define mpz_limbs_cmp _nettle_mpz_limbs_cmp
#define mpz_limbs_read_n _nettle_mpz_limbs_read_n
#define mpz_limbs_copy _nettle_mpz_limbs_copy
......@@ -143,6 +144,9 @@ void
mpn_zero (mp_ptr ptr, mp_size_t n);
#endif /* !GMP_HAVE_mpn_copyd */
void
cnd_swap (mp_limb_t cnd, mp_limb_t *ap, mp_limb_t *bp, mp_size_t n);
/* Convenience functions */
int
mpz_limbs_cmp (mpz_srcptr a, const mp_limb_t *bp, mp_size_t bn);
......
......@@ -54,22 +54,6 @@ cnd_neg (int cnd, mp_limb_t *rp, const mp_limb_t *ap, mp_size_t n)
}
}
static void
cnd_swap (int cnd, mp_limb_t *ap, mp_limb_t *bp, mp_size_t n)
{
mp_limb_t mask = - (mp_limb_t) (cnd != 0);
mp_size_t i;
for (i = 0; i < n; i++)
{
mp_limb_t a, b, t;
a = ap[i];
b = bp[i];
t = (a ^ b) & mask;
ap[i] = a ^ t;
bp[i] = b ^ t;
}
}
/* Compute a^{-1} mod m, with running time depending only on the size.
Returns zero if a == 0 (mod m), to be consistent with a^{phi(m)-1}.
Also needs (m+1)/2, and m must be odd. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment