3 /* Compile time constant (but machine dependent) tables. */
5 /* nettle, low-level cryptographics library
7 * Copyright (C) 2013 Niels Möller
9 * The nettle library is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or (at your
12 * option) any later version.
14 * The nettle library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 * License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with the nettle library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 /* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
33 #include "ecc-internal.h"
39 #if HAVE_NATIVE_ecc_192_modp
41 #define ecc_192_modp nettle_ecc_192_modp
43 ecc_192_modp (const struct ecc_curve
*ecc
, mp_limb_t
*rp
);
45 /* Use that p = 2^{192} - 2^64 - 1, to eliminate 128 bits at a time. */
47 #elif GMP_NUMB_BITS == 32
48 /* p is 6 limbs, p = B^6 - B^2 - 1 */
50 ecc_192_modp (const struct ecc_curve
*ecc UNUSED
, mp_limb_t
*rp
)
54 /* Reduce from 12 to 9 limbs (top limb small)*/
55 cy
= mpn_add_n (rp
+ 2, rp
+ 2, rp
+ 8, 4);
56 cy
= sec_add_1 (rp
+ 6, rp
+ 6, 2, cy
);
57 cy
+= mpn_add_n (rp
+ 4, rp
+ 4, rp
+ 8, 4);
62 /* Reduce from 9 to 6 limbs */
63 cy
= mpn_add_n (rp
, rp
, rp
+ 6, 3);
64 cy
= sec_add_1 (rp
+ 3, rp
+ 3, 2, cy
);
65 cy
+= mpn_add_n (rp
+ 2, rp
+ 2, rp
+ 6, 3);
66 cy
= sec_add_1 (rp
+ 5, rp
+ 5, 1, cy
);
69 cy
= cnd_add_n (cy
, rp
, ecc_Bmodp
, 6);
72 #elif GMP_NUMB_BITS == 64
73 /* p is 3 limbs, p = B^3 - B - 1 */
75 ecc_192_modp (const struct ecc_curve
*ecc UNUSED
, mp_limb_t
*rp
)
79 /* Reduce from 6 to 5 limbs (top limb small)*/
80 cy
= mpn_add_n (rp
+ 1, rp
+ 1, rp
+ 4, 2);
81 cy
= sec_add_1 (rp
+ 3, rp
+ 3, 1, cy
);
82 cy
+= mpn_add_n (rp
+ 2, rp
+ 2, rp
+ 4, 2);
87 /* Reduce from 5 to 4 limbs (high limb small) */
88 cy
= mpn_add_n (rp
, rp
, rp
+ 3, 2);
89 cy
= sec_add_1 (rp
+ 2, rp
+ 2, 1, cy
);
90 cy
+= mpn_add_n (rp
+ 1, rp
+ 1, rp
+ 3, 2);
93 cy
= cnd_add_n (cy
, rp
, ecc_Bmodp
, 3);
98 #define ecc_192_modp ecc_generic_modp
101 const struct ecc_curve nettle_secp_192r1
=