Example #1
0
static char *test_serialization()
{
	struct gotr_dhe_skey priv;
	struct gotr_dhe_pkey pub;
	gcry_mpi_t x1, x2, y1, y2;
	gcry_mpi_point_t p1, p2;
	unsigned char *ser;

	gotr_ecdhe_key_create(&priv);
	gotr_ecdhe_key_get_public(&priv, &pub);

	p1 = deserialize_point(pub.q_y, 32);
	ser = serialize_point(p1);
	mu_assert("ERROR: deserialization->serialization failed", memcmp(pub.q_y, ser, 32) == 0);

	x1 = gcry_mpi_new(0);
	x2 = gcry_mpi_new(0);
	y1 = gcry_mpi_new(0);
	y2 = gcry_mpi_new(0);
	p2 = deserialize_point(ser, 32);
	free(ser);
	gcry_mpi_ec_get_affine(x1, y1, p1, edctx);
	gcry_mpi_ec_get_affine(x2, y2, p2, edctx);
	int res = gcry_mpi_cmp(x1, x2) || gcry_mpi_cmp(y1, y2);
	gcry_mpi_point_release(p1);
	gcry_mpi_point_release(p2);

	mu_assert("ERROR: serialization->deserialization failed", res == 0);
	return 0;
}
Example #2
0
File: gka.c Project: totakura/gotr
void gotr_ecbd_gen_keypair(gcry_mpi_t* privkey, gcry_mpi_point_t* pubkey)
{
	struct gotr_dhe_skey priv;
	struct gotr_dhe_pkey pub;

	gotr_rand_poll();
	gotr_ecdhe_key_create(&priv);
	gotr_mpi_scan_unsigned(privkey, priv.d, sizeof(priv.d));

	gotr_ecdhe_key_get_public(&priv, &pub);
	*pubkey = deserialize_point((struct gotr_point*)pub.q_y, sizeof(pub.q_y));
}