aboutsummaryrefslogtreecommitdiffstats
path: root/common/convert.c
diff options
context:
space:
mode:
authorAndrey Jivsov <[email protected]>2011-01-06 01:33:17 +0000
committerAndrey Jivsov <[email protected]>2011-01-06 01:33:17 +0000
commite0972d3d962548972872d889b362560e499340d1 (patch)
tree26c597a42968ecef26bb7c36b9850b26cb17ebf5 /common/convert.c
parentMake sure that --disable-optimization works in its attempt to replace -Ox wit... (diff)
downloadgnupg-e0972d3d962548972872d889b362560e499340d1.tar.gz
gnupg-e0972d3d962548972872d889b362560e499340d1.zip
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 <private key from http://sites.google.com/site/brainhub/pgpecckeys> ECDH doesn't work yet as the code must be re-written to adjust for gpg-agent refactoring.
Diffstat (limited to 'common/convert.c')
-rw-r--r--common/convert.c27
1 files changed, 27 insertions, 0 deletions
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 <ctype.h>
#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;
+}