aboutsummaryrefslogtreecommitdiff
path: root/crypto.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto.c')
-rw-r--r--crypto.c48
1 files changed, 45 insertions, 3 deletions
diff --git a/crypto.c b/crypto.c
index e78032e..7f2940a 100644
--- a/crypto.c
+++ b/crypto.c
@@ -243,17 +243,19 @@ brandt_ec_skey_create (gcry_mpi_t* skey)
{
gcry_sexp_t s_keyparam;
gcry_sexp_t priv_sexp;
- gcry_mpi_t d;
gcry_error_t rc;
rc = gcry_sexp_build (&s_keyparam, NULL, "(genkey(ecc(curve \"" CURVE "\")"
"(flags)))");
brandt_assert_gpgerr (rc);
+
rc = gcry_pk_genkey (&priv_sexp, s_keyparam);
brandt_assert_gpgerr (rc);
gcry_sexp_release (s_keyparam);
+
rc = key_from_sexp (skey, priv_sexp, "private-key", "d");
brandt_assert_gpgerr (rc);
+
gcry_sexp_release (priv_sexp);
}
@@ -268,10 +270,10 @@ brandt_ec_pkey_compute (gcry_mpi_point_t* pkey, const gcry_mpi_t skey)
void
brandt_ec_keypair_create (gcry_mpi_point_t* pkey, gcry_mpi_t* skey)
{
- gcry_error_t rc;
+ gcry_ctx_t ctx;
gcry_sexp_t s_keyparam;
gcry_sexp_t priv_sexp;
- gcry_ctx_t ctx;
+ gcry_error_t rc;
rc = gcry_sexp_build (&s_keyparam, NULL, "(genkey(ecc(curve \"" CURVE "\")"
"(flags)))");
@@ -294,6 +296,46 @@ brandt_ec_keypair_create (gcry_mpi_point_t* pkey, gcry_mpi_t* skey)
}
+void
+brandt_ec_keypair_create_base (gcry_mpi_point_t* pkey, gcry_mpi_t* skey, const gcry_mpi_point_t base)
+{
+ brandt_ec_skey_create(skey);
+ brandt_assert(*skey);
+ *pkey = gcry_mpi_point_new(0);
+ brandt_assert(*pkey);
+ gcry_mpi_ec_mul(*pkey, *skey, base, ec_ctx);
+}
+
+
+int
+brandt_ec_point_cmp (const gcry_mpi_point_t a, const gcry_mpi_point_t b)
+{
+ int ret = 1;
+ gcry_mpi_t ax = gcry_mpi_new(0);
+ gcry_mpi_t bx = gcry_mpi_new(0);
+ gcry_mpi_t ay = gcry_mpi_new(0);
+ gcry_mpi_t by = gcry_mpi_new(0);
+
+ brandt_assert (a && b);
+ if (!ax || !bx || !ay || !by)
+ {
+ weprintf("could not init point in point_cmp");
+ return 1;
+ }
+
+ if (!gcry_mpi_ec_get_affine(ax, ay, a, ec_ctx) && !gcry_mpi_ec_get_affine(bx, by, b, ec_ctx))
+ {
+ ret = gcry_mpi_cmp(ax, bx) || gcry_mpi_cmp(ay, by);
+ }
+
+ gcry_mpi_release(ax);
+ gcry_mpi_release(bx);
+ gcry_mpi_release(ay);
+ gcry_mpi_release(by);
+ return ret;
+}
+
+
/**
* Convert the given private key from the network format to the
* S-expression that can be used by libgcrypt.