Commit 0276b45a authored by Niels Möller's avatar Niels Möller

ecc_25519_modq: Access q via the ecc struct.

parent 1e14955a
2014-08-28 Niels Möller <nisse@lysator.liu.se> 2014-08-28 Niels Möller <nisse@lysator.liu.se>
* ecc-25519.c (ecc_25519_modq): Access q via the ecc struct.
* ecc-eh-to-a.c (ecc_eh_to_a): Analogous change as for ecc_j_to_a. * ecc-eh-to-a.c (ecc_eh_to_a): Analogous change as for ecc_j_to_a.
The modulo q case (op == 2) is hardcoded for curve25519. The modulo q case (op == 2) is hardcoded for curve25519.
......
...@@ -86,20 +86,18 @@ ecc_25519_modq (const struct ecc_curve *ecc, mp_limb_t *rp) ...@@ -86,20 +86,18 @@ ecc_25519_modq (const struct ecc_curve *ecc, mp_limb_t *rp)
/* n is the offset where we add in the next term */ /* n is the offset where we add in the next term */
for (n = ECC_LIMB_SIZE; n-- > 0;) for (n = ECC_LIMB_SIZE; n-- > 0;)
{ {
mp_limb_t cy;
cy = mpn_submul_1 (rp + n, cy = mpn_submul_1 (rp + n,
ecc->Bmodq_shifted, ECC_LIMB_SIZE, ecc->Bmodq_shifted, ECC_LIMB_SIZE,
rp[n + ECC_LIMB_SIZE]); rp[n + ECC_LIMB_SIZE]);
/* Top limb of mBmodq_shifted is zero, so we get cy == 0 or 1 */ /* Top limb of mBmodq_shifted is zero, so we get cy == 0 or 1 */
assert (cy < 2); assert (cy < 2);
cnd_add_n (cy, rp+n, ecc_q, ECC_LIMB_SIZE); cnd_add_n (cy, rp+n, ecc->q, ECC_LIMB_SIZE);
} }
cy = mpn_submul_1 (rp, ecc_q, ECC_LIMB_SIZE, cy = mpn_submul_1 (rp, ecc->q, ECC_LIMB_SIZE,
rp[ECC_LIMB_SIZE-1] >> (GMP_NUMB_BITS - QHIGH_BITS)); rp[ECC_LIMB_SIZE-1] >> (GMP_NUMB_BITS - QHIGH_BITS));
assert (cy < 2); assert (cy < 2);
cnd_add_n (cy, rp, ecc_q, ECC_LIMB_SIZE); cnd_add_n (cy, rp, ecc->q, ECC_LIMB_SIZE);
} }
/* Needs 2*ecc->size limbs at rp, and 2*ecc->size additional limbs of /* Needs 2*ecc->size limbs at rp, and 2*ecc->size additional limbs of
......
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