Index: libgcrypt-1.2.2-pkhash/cipher/pubkey.c =================================================================== --- libgcrypt-1.2.2-pkhash/cipher/pubkey.c +++ libgcrypt-1.2.2-pkhash/cipher/pubkey.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "g10lib.h" #include "mpi.h" @@ -1086,7 +1087,7 @@ passing to the low level functions. We currently support the old style way of passing just a MPI and the modern interface which allows to pass flags so that we can choose between raw and pkcs1 - padding - may be more padding options later. + padding - may be more padding options later. () or @@ -1095,11 +1096,11 @@ [(hash )] [(value )] ) - + Either the VALUE or the HASH element must be present for use with signatures. VALUE is used for encryption. - NBITS is the length of the key in bits. + NBITS is the length of the key in bits. */ static gcry_err_code_t @@ -1241,6 +1242,24 @@ rc = GPG_ERR_INV_OBJ; else { + /* + * Having the hashes hard coded like this seems + * odd. It means that hash algorithms which are + * dynamically added cannot be part of a signature + * mechanism. + * + * Given that the name->id mapping can be done via + * the gcry_md_map_name(), it seems better to + * ask the MD registry for algorithm details rather + * than maintain the data in 2 separate places. + * + * You could, of course, just prepare the data to + * be signed outside of this routine and pass it + * as a single (mpi) sexp, but that's clearly legacy + * behaviour, and building new dependencies on it + * seems like a bad idea. + */ +#if 0 static struct { const char *name; int algo; } hashnames[] = { { "sha1", GCRY_MD_SHA1 }, { "md5", GCRY_MD_MD5 }, @@ -1254,14 +1273,15 @@ { "haval", GCRY_MD_HAVAL }, { NULL } }; - int algo; +#endif byte asn[100]; byte *frame = NULL; size_t nframe = (nbits+7) / 8; const void * value; size_t valuelen; - size_t asnlen, dlen; - + size_t asnlen, dlen = 0; + int algo; +#if 0 for (i=0; hashnames[i].name; i++) { if ( strlen (hashnames[i].name) == n @@ -1275,6 +1295,19 @@ if (!hashnames[i].name) rc = GPG_ERR_DIGEST_ALGO; + +#else + char *hname; + + hname = gcry_xmalloc( n + 1 ); + for(i=0; i