From e0972d3d962548972872d889b362560e499340d1 Mon Sep 17 00:00:00 2001 From: Andrey Jivsov Date: Wed, 5 Jan 2011 17:33:17 -0800 Subject: Integrating http://code.google.com/p/gnupg-ecc/source/detail?r=15 . The following works: gpg2 --gen-key (ECC) gpg2 --list-keys gpg2 --list-packets ~/.gnupg/pubring.gpg gpg2 --list-packets ECDH doesn't work yet as the code must be re-written to adjust for gpg-agent refactoring. --- common/convert.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'common/convert.c') diff --git a/common/convert.c b/common/convert.c index aa3a3a809..0a0c46f8e 100644 --- a/common/convert.c +++ b/common/convert.c @@ -23,6 +23,7 @@ #include #include "util.h" +#include "gcrypt.h" #define tohex(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'A')) @@ -245,5 +246,31 @@ hex2str_alloc (const char *hexstring, size_t *r_count) return result; } +/* returns hex representation of the MPI; + * caller must free with xfree + * Returns NULL on error, never throws + */ +char *mpi2hex( gcry_mpi_t m ) { + size_t nbytes; + size_t nbytes2; + int rc; + byte *p; + + nbytes = (mpi_get_nbits ( m )+7)/8; + if( nbytes == 0 ) + return NULL; + p = xtrymalloc( nbytes*3+1 ); + if( p==NULL ) + return NULL; + rc = gcry_mpi_print (GCRYMPI_FMT_USG, p+2*nbytes+1, nbytes, &nbytes2, m); + if( rc ) { + xfree( p ); + return NULL; + } + bin2hex( p+2*nbytes+1, nbytes2, p ); + p[nbytes2*2] = '\0'; +//printf("%s:%d>>>> Created the string %s from %d bytes %02x %02x ..., MPI was %d bytes\n", __FILE__, __LINE__, p, nbytes2, p[2*nbytes+1], p[2*nbytes+2], nbytes); + return p; +} -- cgit v1.2.3 From 90b0ff23b7e51332592668e4034967c1aac1c593 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 21 Jan 2011 12:00:57 +0100 Subject: Editorial changes and allow building with old libgcrypts. Changed order of some conditional to make to put the special case into the true branch. Indentation changes. Minor other changes to make the ECC code more similar to the rest of our code. It builds but many sefltests still fail. Need to fix that before using it with an ECDH enabled libgcrypt. [/] 2011-01-21 Werner Koch * configure.ac: Need Libgcrypt 1.4.6 due to AESWRAP. (HAVE_GCRY_PK_ECDH): Add new test. [agent/] 2011-01-21 Werner Koch * cvt-openpgp.c (GCRY_PK_ECDH) [!HAVE_GCRY_PK_ECDH]: New. [include/] 2011-01-21 Werner Koch * cipher.h (GCRY_PK_USAGE_CERT): Remove compatibility macros because we now require libgcrypt 1.4.6. (GCRY_PK_ECDH): Add replacement. --- common/convert.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'common/convert.c') diff --git a/common/convert.c b/common/convert.c index 0a0c46f8e..5df6b335e 100644 --- a/common/convert.c +++ b/common/convert.c @@ -23,7 +23,7 @@ #include #include "util.h" -#include "gcrypt.h" +#include "gcrypt.h" /* FIXME: really needed? */ #define tohex(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'A')) @@ -250,7 +250,10 @@ hex2str_alloc (const char *hexstring, size_t *r_count) * caller must free with xfree * Returns NULL on error, never throws */ -char *mpi2hex( gcry_mpi_t m ) { +char * +mpi2hex( gcry_mpi_t m ) +{ +#warning we have code for this in libcrypt size_t nbytes; size_t nbytes2; int rc; @@ -270,7 +273,9 @@ char *mpi2hex( gcry_mpi_t m ) { bin2hex( p+2*nbytes+1, nbytes2, p ); p[nbytes2*2] = '\0'; -//printf("%s:%d>>>> Created the string %s from %d bytes %02x %02x ..., MPI was %d bytes\n", __FILE__, __LINE__, p, nbytes2, p[2*nbytes+1], p[2*nbytes+2], nbytes); + /*printf("%s:%d>>>> Created the string %s from %d bytes %02x %02x + ..., MPI was %d bytes\n", __FILE__, __LINE__, p, nbytes2, + p[2*nbytes+1], p[2*nbytes+2], nbytes); */ return p; } -- cgit v1.2.3 From e0d4139e19ceed9375cc7e7ba801a965d3376f7d Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 31 Jan 2011 18:19:14 +0100 Subject: Move OpenPGP OID helpers to common/. This is needed so that the agent will be able to export and import OpenPGP secret keys. Add test case. Removed unused function. --- common/convert.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'common/convert.c') diff --git a/common/convert.c b/common/convert.c index 5df6b335e..c314ec9a6 100644 --- a/common/convert.c +++ b/common/convert.c @@ -245,37 +245,3 @@ hex2str_alloc (const char *hexstring, size_t *r_count) BUG (); return result; } - -/* returns hex representation of the MPI; - * caller must free with xfree - * Returns NULL on error, never throws - */ -char * -mpi2hex( gcry_mpi_t m ) -{ -#warning we have code for this in libcrypt - size_t nbytes; - size_t nbytes2; - int rc; - byte *p; - - nbytes = (mpi_get_nbits ( m )+7)/8; - if( nbytes == 0 ) - return NULL; - p = xtrymalloc( nbytes*3+1 ); - if( p==NULL ) - return NULL; - rc = gcry_mpi_print (GCRYMPI_FMT_USG, p+2*nbytes+1, nbytes, &nbytes2, m); - if( rc ) { - xfree( p ); - return NULL; - } - - bin2hex( p+2*nbytes+1, nbytes2, p ); - p[nbytes2*2] = '\0'; - /*printf("%s:%d>>>> Created the string %s from %d bytes %02x %02x - ..., MPI was %d bytes\n", __FILE__, __LINE__, p, nbytes2, - p[2*nbytes+1], p[2*nbytes+2], nbytes); */ - return p; -} - -- cgit v1.2.3 From 0b5bcb40cf17a0e1032c113af6024c08b47d7a5c Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 3 Feb 2011 16:31:42 +0100 Subject: Finished ECC integration. Wrote the ChangeLog 2011-01-13 entry for Andrey's orginal work modulo the cleanups I did in the last week. Adjusted my own ChangeLog entries to be consistent with that entry. Nuked quite some trailing spaces; again sorry for that, I will better take care of not saving them in the future. "git diff -b" is useful to read the actual changes ;-). The ECC-INTEGRATION-2-1 branch can be closed now. --- common/convert.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'common/convert.c') diff --git a/common/convert.c b/common/convert.c index c314ec9a6..78a16c957 100644 --- a/common/convert.c +++ b/common/convert.c @@ -23,7 +23,6 @@ #include #include "util.h" -#include "gcrypt.h" /* FIXME: really needed? */ #define tohex(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'A')) @@ -107,14 +106,14 @@ do_bin2hex (const void *buffer, size_t length, char *stringbuf, int with_colon) { const unsigned char *s; char *p; - + if (!stringbuf) { /* Not really correct for with_colon but we don't care about the one wasted byte. */ - size_t n = with_colon? 3:2; - size_t nbytes = n * length + 1; - if (length && (nbytes-1) / n != length) + size_t n = with_colon? 3:2; + size_t nbytes = n * length + 1; + if (length && (nbytes-1) / n != length) { gpg_err_set_errno (ENOMEM); return NULL; @@ -123,7 +122,7 @@ do_bin2hex (const void *buffer, size_t length, char *stringbuf, int with_colon) if (!stringbuf) return NULL; } - + for (s = buffer, p = stringbuf; length; length--, s++) { if (with_colon && s != buffer) @@ -172,7 +171,7 @@ bin2hexcolon (const void *buffer, size_t length, char *stringbuf) buffer, the function returns NULL and won't change the existing conent of buffer. In-place conversion is possible as long as BUFFER points to HEXSTRING. - + If BUFFER is NULL and bufsize is 0 the function scans HEXSTRING but does not store anything. This may be used to find the end of hexstring. @@ -205,7 +204,7 @@ hex2str (const char *hexstring, char *buffer, size_t bufsize, size_t *buflen) { if (count > bufsize) return NULL; /* Too long. */ - + for (s=hexstring, idx=0; hexdigitp (s) && hexdigitp (s+1); s += 2) ((unsigned char*)buffer)[idx++] = xtoi_2 (s); if (need_nul) -- cgit v1.2.3