Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / nettle / testsuite / ecc-mul-g-test.c
blobc5319ed0d62e830335d0a9cfe73c30b090ae1481
1 #include "testutils.h"
3 void
4 test_main (void)
6 gmp_randstate_t state;
7 mpz_t r;
8 unsigned i;
10 gmp_randinit_default (state);
11 mpz_init (r);
13 for (i = 0; ecc_curves[i]; i++)
15 const struct ecc_curve *ecc = ecc_curves[i];
16 mp_size_t size = ecc_size (ecc);
17 mp_limb_t *p = xalloc_limbs (ecc_size_j (ecc));
18 mp_limb_t *q = xalloc_limbs (ecc_size_j (ecc));
19 mp_limb_t *n = xalloc_limbs (size);
20 mp_limb_t *scratch = xalloc_limbs (ecc_mul_g_itch (ecc));
22 mpn_zero (n, size);
24 n[0] = 1;
25 ecc_mul_g (ecc, p, n, scratch);
26 ecc_j_to_a (ecc, 1, p, p, scratch);
28 if (mpn_cmp (p, ecc->g, 2*size != 0))
30 fprintf (stderr, "ecc_mul_g with n = 1 failed.\n");
31 abort ();
34 for (n[0] = 2; n[0] <= 4; n[0]++)
36 ecc_mul_g (ecc, p, n, scratch);
37 test_ecc_mul_j (i, n[0], p);
40 /* (order - 1) * g = - g */
41 mpn_sub_1 (n, ecc->q, size, 1);
42 ecc_mul_g (ecc, p, n, scratch);
43 ecc_j_to_a (ecc, 1, p, p, scratch);
44 mpn_sub_n (p + size, ecc->p, p + size, size);
45 if (mpn_cmp (p, ecc->g, 2*size) != 0)
47 fprintf (stderr, "ecc_mul_g with n = order - 1 failed.\n");
48 abort ();
51 free (n);
52 free (p);
53 free (q);
54 free (scratch);
56 mpz_clear (r);
57 gmp_randclear (state);