aboutsummaryrefslogtreecommitdiff
path: root/test_crypto.c
blob: 67894ebe0be7dedc0b7b57e18c032d68351e38d9 (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
#include "brandt.h"
#include "crypto.h"
#include "test.h"

int
test_brandt_ec_keypair_create ()
{
	gcry_mpi_t skey;
	gcry_mpi_t x1 = gcry_mpi_new(0);
	gcry_mpi_t x2 = gcry_mpi_new(0);
	gcry_mpi_t y1 = gcry_mpi_new(0);
	gcry_mpi_t y2 = gcry_mpi_new(0);
	gcry_mpi_point_t pkey1;
	gcry_mpi_point_t pkey2 = gcry_mpi_point_new(0);

	brandt_ec_keypair_create (&pkey1, &skey);
	check(skey, "no sec key created");
	check(pkey1, "no pub key created");
	check(pkey2, "could not init pkey2");
	check(x1, "could not init x1");
	check(x2, "could not init x2");
	check(y1, "could not init y1");
	check(y2, "could not init y2");

	gcry_mpi_ec_mul(pkey2, skey, ec_gen, ec_ctx);
	check(!gcry_mpi_ec_get_affine(x1, y1, pkey1, ec_ctx), "could not get affine coords for pkey1");
	check(!gcry_mpi_ec_get_affine(x2, y2, pkey2, ec_ctx), "could not get affine coords for pkey1");
	check(!gcry_mpi_cmp(x1, x2), "x component does not match");
	check(!gcry_mpi_cmp(y1, y2), "y component does not match");

	gcry_mpi_release(skey);
	gcry_mpi_release(x1);
	gcry_mpi_release(x2);
	gcry_mpi_release(y1);
	gcry_mpi_release(y2);
	gcry_mpi_point_release(pkey1);
	gcry_mpi_point_release(pkey2);
}

int
main (int argc, char *argv[])
{
	int repeat = 100;
	int i;

	BRANDT_init();

	for (i = 0; i < repeat; i++)
	{
		run(test_brandt_ec_keypair_create);
	}

	if (!ret)
	{
		fputs("All tests passed", stderr);
	}
	return ret;
}