Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / nettle / ecc-192.c
blob5026b1eb301bd4a7e4d93eddabda6f8229b1f317
1 /* ecc-192.c */
3 /* Compile time constant (but machine dependent) tables. */
5 /* nettle, low-level cryptographics library
7 * Copyright (C) 2013 Niels Möller
8 *
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,
22 * MA 02111-1301, USA.
25 /* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
27 #if HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <assert.h>
33 #include "ecc-internal.h"
35 #define USE_REDC 0
37 #include "ecc-192.h"
39 #if HAVE_NATIVE_ecc_192_modp
41 #define ecc_192_modp nettle_ecc_192_modp
42 void
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 */
49 static void
50 ecc_192_modp (const struct ecc_curve *ecc UNUSED, mp_limb_t *rp)
52 mp_limb_t cy;
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);
58 assert (cy <= 2);
60 rp[8] = cy;
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);
68 assert (cy <= 1);
69 cy = cnd_add_n (cy, rp, ecc_Bmodp, 6);
70 assert (cy == 0);
72 #elif GMP_NUMB_BITS == 64
73 /* p is 3 limbs, p = B^3 - B - 1 */
74 static void
75 ecc_192_modp (const struct ecc_curve *ecc UNUSED, mp_limb_t *rp)
77 mp_limb_t cy;
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);
83 assert (cy <= 2);
85 rp[4] = cy;
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);
92 assert (cy <= 1);
93 cy = cnd_add_n (cy, rp, ecc_Bmodp, 3);
94 assert (cy == 0);
97 #else
98 #define ecc_192_modp ecc_generic_modp
99 #endif
101 const struct ecc_curve nettle_secp_192r1 =
103 192,
104 ECC_LIMB_SIZE,
105 ECC_BMODP_SIZE,
106 ECC_BMODQ_SIZE,
107 USE_REDC,
108 ECC_REDC_SIZE,
109 ECC_PIPPENGER_K,
110 ECC_PIPPENGER_C,
111 ecc_p,
112 ecc_b,
113 ecc_q,
114 ecc_g,
115 ecc_redc_g,
116 ecc_192_modp,
117 ecc_generic_redc,
118 ecc_192_modp,
119 ecc_generic_modq,
120 ecc_Bmodp,
121 ecc_Bmodp_shifted,
122 ecc_pp1h,
123 ecc_redc_ppm1,
124 ecc_unit,
125 ecc_Bmodq,
126 ecc_Bmodq_shifted,
127 ecc_qp1h,
128 ecc_table