Apply %restore_fcommon macro for Address Sanitizer
[platform/upstream/nettle.git] / testsuite / ecc-add-test.c
1 #include "testutils.h"
2
3 void
4 test_main (void)
5 {
6   unsigned i;
7
8   for (i = 0; ecc_curves[i]; i++)
9     {
10       const struct ecc_curve *ecc = ecc_curves[i];
11       mp_limb_t *g = xalloc_limbs (ecc_size_j (ecc));
12       mp_limb_t *g2 = xalloc_limbs (ecc_size_j (ecc));
13       mp_limb_t *g3 = xalloc_limbs (ecc_size_j (ecc));
14       mp_limb_t *p = xalloc_limbs (ecc_size_j (ecc));
15       mp_limb_t *scratch = xalloc_limbs (ECC_ADD_JJJ_ITCH(ecc->p.size));
16
17       if (ecc->p.bit_size == 255)
18         {
19           mp_limb_t *z = xalloc_limbs (ecc_size_j (ecc));
20           /* Zero point has x = 0, y = 1, z = 1 */
21           mpn_zero (z, 3*ecc->p.size);
22           z[ecc->p.size] = z[2*ecc->p.size] = 1;
23           
24           ecc_a_to_j (ecc, g, ecc->g);
25
26           ecc_add_ehh (ecc, p, z, z, scratch);
27           test_ecc_mul_h (i, 0, p);
28
29           ecc_add_eh (ecc, p, z, z, scratch);
30           test_ecc_mul_h (i, 0, p);
31
32           ecc_add_ehh (ecc, p, g, p, scratch);
33           test_ecc_mul_h (i, 1, p);
34
35           ecc_add_eh (ecc, p, z, g, scratch);
36           test_ecc_mul_h (i, 1, p);
37
38           ecc_add_ehh (ecc, g2, g, p, scratch);
39           test_ecc_mul_h (i, 2, g2);
40
41           ecc_add_eh (ecc, g2, g, g, scratch);
42           test_ecc_mul_h (i, 2, g2);
43
44           ecc_add_ehh (ecc, g3, g, g2, scratch);
45           test_ecc_mul_h (i, 3, g3);
46
47           ecc_add_eh (ecc, g3, g2, g, scratch);
48           test_ecc_mul_h (i, 3, g3);
49
50           ecc_add_ehh (ecc, p, g, g3, scratch);
51           test_ecc_mul_h (i, 4, p);
52
53           ecc_add_eh (ecc, p, g3, g, scratch);
54           test_ecc_mul_h (i, 4, p);
55
56           ecc_add_ehh (ecc, p, g2, g2, scratch);
57           test_ecc_mul_h (i, 4, p);
58
59           free (z);
60         }
61       else
62         {
63           ecc_a_to_j (ecc, g, ecc->g);
64
65           ecc_dup_jj (ecc, g2, g, scratch);
66           test_ecc_mul_h (i, 2, g2);
67
68           ecc_add_jjj (ecc, g3, g, g2, scratch);
69           test_ecc_mul_h (i, 3, g3);
70
71           ecc_add_jjj (ecc, g3, g2, g, scratch);
72           test_ecc_mul_h (i, 3, g3);
73
74           ecc_add_jjj (ecc, p, g, g3, scratch);
75           test_ecc_mul_h (i, 4, p);
76
77           ecc_add_jjj (ecc, p, g3, g, scratch);
78           test_ecc_mul_h (i, 4, p);
79
80           ecc_dup_jj (ecc, p, g2, scratch);
81           test_ecc_mul_h (i, 4, p);
82         }
83       free (g);
84       free (g2);
85       free (g3);
86       free (p);
87       free (scratch);
88     }
89 }