summaryrefslogtreecommitdiffstats
path: root/g10/pkglue.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2020-06-09 08:45:51 +0200
committerNIIBE Yutaka <gniibe@fsij.org>2020-06-09 08:45:51 +0200
commitda5e0bc31b4c6f16ed5ff9b35063f3b03eb7ff16 (patch)
tree54a549895066f5d2663bb601d5dd36aa70a8b8f0 /g10/pkglue.c
parentgpg: Add X448 support. (diff)
downloadgnupg2-da5e0bc31b4c6f16ed5ff9b35063f3b03eb7ff16.tar.xz
gnupg2-da5e0bc31b4c6f16ed5ff9b35063f3b03eb7ff16.zip
gpg: Use bytes for ECDH.
* g10/ecdh.c (extract_secret_x): Use byte * instead of MPI. (prepare_ecdh_with_shared_point): Use char * instead of MPI. (pk_ecdh_encrypt_with_shared_point): Likewise. (pk_ecdh_decrypt): Likewise. * g10/pkglue.h (pk_ecdh_encrypt_with_shared_point, pk_ecdh_decrypt): Change declaration. * g10/pkglue.c (get_data_from_sexp): New. (pk_encrypt): Use get_data_from_sexp instead of get_mpi_from_sexp. Follow the change of pk_ecdh_encrypt_with_shared_point. * g10/pubkey-enc.c (get_it): Follow the change of pk_ecdh_decrypt. Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'g10/pkglue.c')
-rw-r--r--g10/pkglue.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/g10/pkglue.c b/g10/pkglue.c
index 741a93735..a659a5b06 100644
--- a/g10/pkglue.c
+++ b/g10/pkglue.c
@@ -98,6 +98,28 @@ sexp_extract_param_sos (gcry_sexp_t sexp, const char *param, gcry_mpi_t *r_sos)
}
+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
* change the internal design to directly fit to libgcrypt.
@@ -382,12 +404,14 @@ 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_USG);
+ shared = get_data_from_sexp (s_ciph, "s", &nshared);
rc = sexp_extract_param_sos (s_ciph, "e", &public);
gcry_sexp_release (s_ciph);
s_ciph = NULL;
@@ -404,9 +428,13 @@ pk_encrypt (pubkey_algo_t algo, gcry_mpi_t *resarr, gcry_mpi_t data,
rc = gpg_error (GPG_ERR_INV_LENGTH);
if (!rc)
- rc = pk_ecdh_encrypt_with_shared_point (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 (shared, nshared, fp, p,
+ (nbits+7)/8, pkey, &result);
+ }
+ xfree (shared);
if (!rc)
{
resarr[0] = public;