summaryrefslogtreecommitdiffstats
path: root/g10/ecdh.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2011-01-31 09:27:06 +0100
committerWerner Koch <wk@gnupg.org>2011-01-31 09:27:06 +0100
commit0fb0bb8d9a960a2473ab70a021d20639a43227e0 (patch)
tree8dcce4f17931a3da45890db635a6474231224db0 /g10/ecdh.c
parentUpdate gitignore (diff)
downloadgnupg2-0fb0bb8d9a960a2473ab70a021d20639a43227e0.tar.xz
gnupg2-0fb0bb8d9a960a2473ab70a021d20639a43227e0.zip
Reworked the ECC changes to better fit into the Libgcrypt API.
See ChangeLog for details. Key generation, signing and verification works. Encryption does not yet work. Requires latest Libgcrypt changes.
Diffstat (limited to 'g10/ecdh.c')
-rw-r--r--g10/ecdh.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/g10/ecdh.c b/g10/ecdh.c
index 95bd8668f..cf002b957 100644
--- a/g10/ecdh.c
+++ b/g10/ecdh.c
@@ -48,16 +48,17 @@ static const struct
-/* Returns allocated (binary) KEK parameters; the size is returned in
- sizeout. The caller must free the returned value. Returns NULL
- and sets ERRNO on error. */
-byte *
-pk_ecdh_default_params (unsigned int qbits, size_t *sizeout)
+/* Return KEK parameters as an opaque MPI The caller must free the
+ returned value. Returns NULL and sets ERRNO on error. */
+gcry_mpi_t
+pk_ecdh_default_params (unsigned int qbits)
{
- byte kek_params[4];
+ byte *kek_params;
int i;
- byte *buffer;
+ kek_params = xtrymalloc (4);
+ if (!kek_params)
+ return NULL;
kek_params[0] = 3; /* Number of bytes to follow. */
kek_params[1] = 1; /* Version for KDF+AESWRAP. */
@@ -78,12 +79,7 @@ pk_ecdh_default_params (unsigned int qbits, size_t *sizeout)
if (DBG_CIPHER)
log_printhex ("ECDH KEK params are", kek_params, sizeof(kek_params) );
- buffer = xtrymalloc (sizeof(kek_params));
- if (!buffer)
- return NULL;
- memcpy (buffer, kek_params, sizeof (kek_params));
- *sizeout = sizeof (kek_params);
- return buffer;
+ return gcry_mpi_set_opaque (NULL, kek_params, 4 * 8);
}
@@ -411,8 +407,8 @@ gen_k (unsigned nbits)
unsigned char *buffer;
if (gcry_mpi_aprint (GCRYMPI_FMT_HEX, &buffer, NULL, k))
BUG ();
- log_debug("ephemeral scalar MPI #0: %s\n", buffer);
- gcry_free( buffer );
+ log_debug ("ephemeral scalar MPI #0: %s\n", buffer);
+ gcry_free (buffer);
}
return k;