3 Copyright (C) 2013, 2014 Niels Möller
5 This file is part of GNU Nettle.
7 GNU Nettle is free software: you can redistribute it and/or
8 modify it under the terms of either:
10 * the GNU Lesser General Public License as published by the Free
11 Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
16 * the GNU General Public License as published by the Free
17 Software Foundation; either version 2 of the License, or (at your
18 option) any later version.
20 or both in parallel, as here.
22 GNU Nettle is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
27 You should have received copies of the GNU General Public License and
28 the GNU Lesser General Public License along with this program. If
29 not, see http://www.gnu.org/licenses/.
32 /* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
41 #include "ecc-internal.h"
44 ecc_mul_g_eh (const struct ecc_curve *ecc, mp_limb_t *r,
45 const mp_limb_t *np, mp_limb_t *scratch)
47 /* Scratch need determined by the ecc_add_eh call. Current total is
48 9 * ecc->p.size, at most 648 bytes. */
50 #define scratch_out (scratch + 3*ecc->p.size)
59 bit_rows = (ecc->p.bit_size + k - 1) / k;
61 /* x = 0, y = 1, z = 1 */
62 mpn_zero (r, 3*ecc->p.size);
63 r[ecc->p.size] = r[2*ecc->p.size] = 1;
65 for (i = k; i-- > 0; )
67 ecc_dup_eh (ecc, r, r, scratch);
68 for (j = 0; j * c < bit_rows; j++)
71 /* Avoid the mp_bitcnt_t type for compatibility with older GMP
75 /* Extract c bits from n, stride k, starting at i + kcj,
76 ending at i + k (cj + c - 1)*/
77 for (bits = 0, bit_index = i + k*(c*j+c); bit_index > i + k*c*j; )
84 limb_index = bit_index / GMP_NUMB_BITS;
85 if (limb_index >= ecc->p.size)
88 shift = bit_index % GMP_NUMB_BITS;
89 bits = (bits << 1) | ((np[limb_index] >> shift) & 1);
91 sec_tabselect (tp, 2*ecc->p.size,
93 + (2*ecc->p.size * (mp_size_t) j << c)),
96 ecc_add_eh (ecc, r, r, tp, scratch_out);