3 Compile time constant (but machine dependent) tables.
5 Copyright (C) 2013, 2014 Niels Möller
7 This file is part of GNU Nettle.
9 GNU Nettle is free software: you can redistribute it and/or
10 modify it under the terms of either:
12 * the GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
18 * the GNU General Public License as published by the Free
19 Software Foundation; either version 2 of the License, or (at your
20 option) any later version.
22 or both in parallel, as here.
24 GNU Nettle is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 General Public License for more details.
29 You should have received copies of the GNU General Public License and
30 the GNU Lesser General Public License along with this program. If
31 not, see http://www.gnu.org/licenses/.
34 /* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
41 #include "ecc-internal.h"
47 #if HAVE_NATIVE_ecc_521_modp
48 #define ecc_521_modp nettle_ecc_521_modp
50 ecc_521_modp (const struct ecc_modulo *m, mp_limb_t *rp);
54 #define B_SHIFT (521 % GMP_NUMB_BITS)
55 #define BMODP_SHIFT (GMP_NUMB_BITS - B_SHIFT)
56 #define BMODP ((mp_limb_t) 1 << BMODP_SHIFT)
58 /* Result may be *slightly* larger than 2^521 */
60 ecc_521_modp (const struct ecc_modulo *m UNUSED, mp_limb_t *rp)
62 /* FIXME: Should use mpn_addlsh_n_ip1 */
64 /* Reduce from 2*ECC_LIMB_SIZE to ECC_LIMB_SIZE + 1 */
66 = mpn_addmul_1 (rp, rp + ECC_LIMB_SIZE, ECC_LIMB_SIZE, BMODP);
67 hi = mpn_addmul_1 (rp, rp + ECC_LIMB_SIZE, 1, BMODP);
68 hi = sec_add_1 (rp + 1, rp + 1, ECC_LIMB_SIZE - 1, hi);
70 /* Combine hi with top bits, and add in. */
71 hi = (hi << BMODP_SHIFT) | (rp[ECC_LIMB_SIZE-1] >> B_SHIFT);
72 rp[ECC_LIMB_SIZE-1] = (rp[ECC_LIMB_SIZE-1]
73 & (((mp_limb_t) 1 << B_SHIFT)-1))
74 + sec_add_1 (rp, rp, ECC_LIMB_SIZE - 1, hi);
78 const struct ecc_curve nettle_secp_521r1 =
85 ECC_MOD_INV_ITCH (ECC_LIMB_SIZE),
104 ECC_MOD_INV_ITCH (ECC_LIMB_SIZE),
123 ECC_ADD_JJJ_ITCH (ECC_LIMB_SIZE),
124 ECC_MUL_A_ITCH (ECC_LIMB_SIZE),
125 ECC_MUL_G_ITCH (ECC_LIMB_SIZE),
126 ECC_J_TO_A_ITCH (ECC_LIMB_SIZE),