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. */
42 /* FIXME: Remove ecc.h include, once prototypes of more internal
43 functions are moved to ecc-internal.h */
45 #include "ecc-internal.h"
51 #if HAVE_NATIVE_ecc_192_modp
53 #define ecc_192_modp nettle_ecc_192_modp
55 ecc_192_modp (const struct ecc_modulo *m, mp_limb_t *rp);
57 /* Use that p = 2^{192} - 2^64 - 1, to eliminate 128 bits at a time. */
59 #elif GMP_NUMB_BITS == 32
60 /* p is 6 limbs, p = B^6 - B^2 - 1 */
62 ecc_192_modp (const struct ecc_modulo *m UNUSED, mp_limb_t *rp)
66 /* Reduce from 12 to 9 limbs (top limb small)*/
67 cy = mpn_add_n (rp + 2, rp + 2, rp + 8, 4);
68 cy = sec_add_1 (rp + 6, rp + 6, 2, cy);
69 cy += mpn_add_n (rp + 4, rp + 4, rp + 8, 4);
74 /* Reduce from 9 to 6 limbs */
75 cy = mpn_add_n (rp, rp, rp + 6, 3);
76 cy = sec_add_1 (rp + 3, rp + 3, 2, cy);
77 cy += mpn_add_n (rp + 2, rp + 2, rp + 6, 3);
78 cy = sec_add_1 (rp + 5, rp + 5, 1, cy);
81 cy = cnd_add_n (cy, rp, ecc_Bmodp, 6);
84 #elif GMP_NUMB_BITS == 64
85 /* p is 3 limbs, p = B^3 - B - 1 */
87 ecc_192_modp (const struct ecc_modulo *m UNUSED, mp_limb_t *rp)
91 /* Reduce from 6 to 5 limbs (top limb small)*/
92 cy = mpn_add_n (rp + 1, rp + 1, rp + 4, 2);
93 cy = sec_add_1 (rp + 3, rp + 3, 1, cy);
94 cy += mpn_add_n (rp + 2, rp + 2, rp + 4, 2);
99 /* Reduce from 5 to 4 limbs (high limb small) */
100 cy = mpn_add_n (rp, rp, rp + 3, 2);
101 cy = sec_add_1 (rp + 2, rp + 2, 1, cy);
102 cy += mpn_add_n (rp + 1, rp + 1, rp + 3, 2);
105 cy = cnd_add_n (cy, rp, ecc_Bmodp, 3);
110 #define ecc_192_modp ecc_mod
113 const struct ecc_curve nettle_secp_192r1 =
120 ECC_MOD_INV_ITCH (ECC_LIMB_SIZE),
139 ECC_MOD_INV_ITCH (ECC_LIMB_SIZE),
158 ECC_ADD_JJJ_ITCH (ECC_LIMB_SIZE),
159 ECC_MUL_A_ITCH (ECC_LIMB_SIZE),
160 ECC_MUL_G_ITCH (ECC_LIMB_SIZE),
161 ECC_J_TO_A_ITCH (ECC_LIMB_SIZE),