diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/ChangeLog | 5 | ||||
-rw-r--r-- | common/convert.c | 32 | ||||
-rw-r--r-- | common/util.h | 1 |
3 files changed, 38 insertions, 0 deletions
diff --git a/common/ChangeLog b/common/ChangeLog index 0150658e0..61f6b292b 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -50,6 +50,11 @@ * session-env.c (update_var): Fix same value detection. Fixes bug#1311. +2011-01-10 Werner Koch <[email protected]> + + * session-env.c (update_var): Fix same value detection. Fixes + bug#1311. + 2010-12-17 Werner Koch <[email protected]> * asshelp.c (lock_spawning): Add arg VERBOSE. Improve timeout diff --git a/common/convert.c b/common/convert.c index aa3a3a809..5df6b335e 100644 --- a/common/convert.c +++ b/common/convert.c @@ -23,6 +23,7 @@ #include <ctype.h> #include "util.h" +#include "gcrypt.h" /* FIXME: really needed? */ #define tohex(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'A')) @@ -245,5 +246,36 @@ 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 ) +{ +#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; +} diff --git a/common/util.h b/common/util.h index f06701fc0..99d58e172 100644 --- a/common/util.h +++ b/common/util.h @@ -196,6 +196,7 @@ gpg_error_t get_pk_algo_from_canon_sexp (const unsigned char *keydata, int hex2bin (const char *string, void *buffer, size_t length); int hexcolon2bin (const char *string, void *buffer, size_t length); char *bin2hex (const void *buffer, size_t length, char *stringbuf); +char *mpi2hex (gcry_mpi_t m); char *bin2hexcolon (const void *buffer, size_t length, char *stringbuf); const char *hex2str (const char *hexstring, char *buffer, size_t bufsize, size_t *buflen); |