diff options
Diffstat (limited to 'g10/pkglue.c')
-rw-r--r-- | g10/pkglue.c | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/g10/pkglue.c b/g10/pkglue.c index 0d18cb931..7dadeb44a 100644 --- a/g10/pkglue.c +++ b/g10/pkglue.c @@ -47,6 +47,26 @@ get_mpi_from_sexp (gcry_sexp_t sexp, const char *item, int mpifmt) } +static byte * +get_data_from_sexp (gcry_sexp_t sexp, const char *item, size_t *r_size) +{ + gcry_sexp_t list; + size_t valuelen; + const char *value; + byte *v; + + log_printsexp ("get_data_from_sexp:", sexp); + + list = gcry_sexp_find_token (sexp, item, 0); + log_assert (list); + value = gcry_sexp_nth_data (list, 1, &valuelen); + log_assert (value); + v = xtrymalloc (valuelen); + memcpy (v, value, valuelen); + gcry_sexp_release (list); + *r_size = valuelen; + return v; +} /**************** * Emulate our old PK interface here - sometime in the future we might @@ -332,15 +352,15 @@ pk_encrypt (pubkey_algo_t algo, gcry_mpi_t *resarr, gcry_mpi_t data, ; else if (algo == PUBKEY_ALGO_ECDH) { - gcry_mpi_t shared, public, result; + gcry_mpi_t public, result; byte fp[MAX_FINGERPRINT_LEN]; size_t fpn; + byte *shared; + size_t nshared; /* Get the shared point and the ephemeral public key. */ - shared = get_mpi_from_sexp (s_ciph, "s", GCRYMPI_FMT_OPAQUE); + shared = get_data_from_sexp (s_ciph, "s", &nshared); public = get_mpi_from_sexp (s_ciph, "e", GCRYMPI_FMT_OPAQUE); - gcry_sexp_release (s_ciph); - s_ciph = NULL; if (DBG_CRYPTO) { log_debug ("ECDH ephemeral key:"); @@ -353,9 +373,13 @@ pk_encrypt (pubkey_algo_t algo, gcry_mpi_t *resarr, gcry_mpi_t data, if (fpn != 20) rc = gpg_error (GPG_ERR_INV_LENGTH); else - rc = pk_ecdh_encrypt_with_shared_point (1 /*=encrypton*/, shared, - fp, data, pkey, &result); - gcry_mpi_release (shared); + { + unsigned int nbits; + byte *p = gcry_mpi_get_opaque (data, &nbits); + rc = pk_ecdh_encrypt_with_shared_point (1 /*=encrypton*/, shared, nshared, + fp, p, (nbits+7)/8, pkey, &result); + } + xfree (shared); if (!rc) { resarr[0] = public; |