ecc-dup-test.c 932 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#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 *p = xalloc_limbs (ecc_size_j (ecc));
13 14 15
      mp_limb_t *scratch = xalloc_limbs (ecc->dup_itch);

      ecc_a_to_j (ecc, g, ecc->g);
16

Niels Möller's avatar
Niels Möller committed
17
      if (ecc->p.bit_size == 255)
18 19
	{
	  mp_limb_t *z = xalloc_limbs (ecc_size_j (ecc));
20 21 22

	  ASSERT (ecc->dup == ecc_dup_eh);

23
	  /* Zero point has x = 0, y = 1, z = 1 */
Niels Möller's avatar
Niels Möller committed
24 25
	  mpn_zero (z, 3*ecc->p.size);
	  z[ecc->p.size] = z[2*ecc->p.size] = 1;
26
	  
27
	  ecc->dup (ecc, p, z, scratch);
28
	  test_ecc_mul_h (i, 0, p);
29 30 31 32

	  free (z);
	}
      else
33
	ASSERT (ecc->dup == ecc_dup_jj);
34

35 36 37 38 39
      ecc->dup (ecc, p, g, scratch);
      test_ecc_mul_h (i, 2, p);

      ecc->dup (ecc, p, p, scratch);
      test_ecc_mul_h (i, 4, p);
40 41 42 43 44 45

      free (p);
      free (g);
      free (scratch);
    }
}