summaryrefslogtreecommitdiff
path: root/testsuite/ecc-add-test.c
blob: 54fae31fa155857a9ae820348647bd6b68101202 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "testutils.h"

void
test_main (void)
{
  unsigned i;

  for (i = 0; ecc_curves[i]; i++)
    {
      const struct ecc_curve *ecc = ecc_curves[i];
      mp_limb_t *g = xalloc_limbs (ecc_size_j (ecc));
      mp_limb_t *g2 = xalloc_limbs (ecc_size_j (ecc));
      mp_limb_t *g3 = xalloc_limbs (ecc_size_j (ecc));
      mp_limb_t *p = xalloc_limbs (ecc_size_j (ecc));
      mp_limb_t *scratch = xalloc_limbs (ECC_ADD_JJJ_ITCH(ecc->p.size));

      if (ecc->p.bit_size == 255)
	{
	  mp_limb_t *z = xalloc_limbs (ecc_size_j (ecc));
	  /* Zero point has x = 0, y = 1, z = 1 */
	  mpn_zero (z, 3*ecc->p.size);
	  z[ecc->p.size] = z[2*ecc->p.size] = 1;
	  
	  ecc_a_to_j (ecc, g, ecc->g);

	  ecc_add_ehh (ecc, p, z, z, scratch);
	  test_ecc_mul_h (i, 0, p);

	  ecc_add_eh (ecc, p, z, z, scratch);
	  test_ecc_mul_h (i, 0, p);

	  ecc_add_ehh (ecc, p, g, p, scratch);
	  test_ecc_mul_h (i, 1, p);

	  ecc_add_eh (ecc, p, z, g, scratch);
	  test_ecc_mul_h (i, 1, p);

	  ecc_add_ehh (ecc, g2, g, p, scratch);
	  test_ecc_mul_h (i, 2, g2);

	  ecc_add_eh (ecc, g2, g, g, scratch);
	  test_ecc_mul_h (i, 2, g2);

	  ecc_add_ehh (ecc, g3, g, g2, scratch);
	  test_ecc_mul_h (i, 3, g3);

	  ecc_add_eh (ecc, g3, g2, g, scratch);
	  test_ecc_mul_h (i, 3, g3);

	  ecc_add_ehh (ecc, p, g, g3, scratch);
	  test_ecc_mul_h (i, 4, p);

	  ecc_add_eh (ecc, p, g3, g, scratch);
	  test_ecc_mul_h (i, 4, p);

	  ecc_add_ehh (ecc, p, g2, g2, scratch);
	  test_ecc_mul_h (i, 4, p);

	  free (z);
	}
      else
	{
	  ecc_a_to_j (ecc, g, ecc->g);

	  ecc_dup_jj (ecc, g2, g, scratch);
	  test_ecc_mul_h (i, 2, g2);

	  ecc_add_jjj (ecc, g3, g, g2, scratch);
	  test_ecc_mul_h (i, 3, g3);

	  ecc_add_jjj (ecc, g3, g2, g, scratch);
	  test_ecc_mul_h (i, 3, g3);

	  ecc_add_jjj (ecc, p, g, g3, scratch);
	  test_ecc_mul_h (i, 4, p);

	  ecc_add_jjj (ecc, p, g3, g, scratch);
	  test_ecc_mul_h (i, 4, p);

	  ecc_dup_jj (ecc, p, g2, scratch);
	  test_ecc_mul_h (i, 4, p);
	}
      free (g);
      free (g2);
      free (g3);
      free (p);
      free (scratch);
    }
}