diff options
author | Niels Möller <nisse@lysator.liu.se> | 2014-08-28 11:25:48 +0200 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2014-08-28 11:25:48 +0200 |
commit | 91784d65b7cd71a4128ee6d74043178f3aa2d09f (patch) | |
tree | 4b26e8fc37643f0f7c38bfd9a22433da947d55ca /ecc-j-to-a.c | |
parent | a67a7286c9ea748652d463160a5f863de10ae644 (diff) | |
download | nettle-91784d65b7cd71a4128ee6d74043178f3aa2d09f.tar.gz |
ecc_j_to_a interface change, optionally reduce x mod q.
Diffstat (limited to 'ecc-j-to-a.c')
-rw-r--r-- | ecc-j-to-a.c | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/ecc-j-to-a.c b/ecc-j-to-a.c index 0c0c8485..e945929d 100644 --- a/ecc-j-to-a.c +++ b/ecc-j-to-a.c @@ -47,7 +47,7 @@ ecc_j_to_a_itch (const struct ecc_curve *ecc) void ecc_j_to_a (const struct ecc_curve *ecc, - int flags, + int op, mp_limb_t *r, const mp_limb_t *p, mp_limb_t *scratch) { @@ -79,17 +79,12 @@ ecc_j_to_a (const struct ecc_curve *ecc, ecc_modp_inv (ecc, izp, up, up + ecc->size); - if (flags & 1) - { - /* Divide this common factor by B */ - mpn_copyi (izBp, izp, ecc->size); - mpn_zero (izBp + ecc->size, ecc->size); - ecc->redc (ecc, izBp); + /* Divide this common factor by B */ + mpn_copyi (izBp, izp, ecc->size); + mpn_zero (izBp + ecc->size, ecc->size); + ecc->redc (ecc, izBp); - ecc_modp_mul (ecc, iz2p, izp, izBp); - } - else - ecc_modp_sqr (ecc, iz2p, izp); + ecc_modp_mul (ecc, iz2p, izp, izBp); } else { @@ -107,10 +102,19 @@ ecc_j_to_a (const struct ecc_curve *ecc, cy = mpn_sub_n (r, iz3p, ecc->p, ecc->size); cnd_copy (cy, r, iz3p, ecc->size); - if (flags & 2) - /* Skip y coordinate */ - return; - + if (op) + { + /* Skip y coordinate */ + if (op > 1) + { + /* Also reduce the x coordinate mod ecc->q. It should + already be < 2*ecc->q, so one subtraction should + suffice. */ + cy = mpn_sub_n (scratch, r, ecc->q, ecc->size); + cnd_copy (cy == 0, r, scratch, ecc->size); + } + return; + } ecc_modp_mul (ecc, iz3p, iz2p, izp); ecc_modp_mul (ecc, tp, iz3p, p + ecc->size); /* And a similar subtraction. */ |