From 172448b05931e791ce3470b45afe8de4cdffaaad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Sun, 1 Nov 2020 10:22:48 +0100 Subject: Separate result area for ecc_mod_mul and ecc_mod_sqr. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ecc-mod-arith.c (ecc_mod_mul, ecc_mod_sqr): Separate argument for scratch area, reducing required size of result area. Update all callers to naïvely keep using result in scratch area. (ecc_mod_pow_2k, ecc_mod_pow_2k_mul): Simplified, also reducing required size of result area. --- ecc-internal.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'ecc-internal.h') diff --git a/ecc-internal.h b/ecc-internal.h index b2ee8350..52bea1c9 100644 --- a/ecc-internal.h +++ b/ecc-internal.h @@ -255,23 +255,26 @@ void ecc_mod_submul_1 (const struct ecc_modulo *m, mp_limb_t *rp, const mp_limb_t *ap, mp_limb_t b); -/* The mul and sqr functions need 2*m->size limbs at rp */ +/* The mul and sqr function need 2*m->size limbs at tp. rp may overlap + ap or bp, and may equal tp or tp + m->size, but no other overlap + with tp is allowed. */ void ecc_mod_mul (const struct ecc_modulo *m, mp_limb_t *rp, - const mp_limb_t *ap, const mp_limb_t *bp); + const mp_limb_t *ap, const mp_limb_t *bp, mp_limb_t *tp); void ecc_mod_sqr (const struct ecc_modulo *m, mp_limb_t *rp, - const mp_limb_t *ap); + const mp_limb_t *ap, mp_limb_t *tp); -/* The pow functions needs 2*m->size limbs at both rp and tp. */ -/* R <-- X^{2^k} */ +/* R <-- X^{2^k} mod M. Needs 2*ecc->size limbs of scratch space, same + overlap requirements as mul and sqr above. */ void ecc_mod_pow_2k (const struct ecc_modulo *m, mp_limb_t *rp, const mp_limb_t *xp, unsigned k, mp_limb_t *tp); -/* R <-- X^{2^k} Y */ +/* R <-- X^{2^k} Y mod M. Similar requirements as ecc_mod_pow_2k, but + rp and yp can't overlap. */ void ecc_mod_pow_2k_mul (const struct ecc_modulo *m, mp_limb_t *rp, const mp_limb_t *xp, -- cgit v1.2.1