1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-03 22:48:03 +02:00

2003-08-14 Timo Schulz <twoaday@freakmail.de>

* pksign.c: do_encode_md: Due to the fact pkcs#1 padding
        is now in Libgcrypt, use the new interface.
This commit is contained in:
Timo Schulz 2003-08-14 19:06:46 +00:00
parent abbb66e037
commit 7abac1ad8e
2 changed files with 26 additions and 46 deletions

View File

@ -1,3 +1,8 @@
2003-08-14 Timo Schulz <twoaday@freakmail.de>
* pksign.c: do_encode_md: Due to the fact pkcs#1 padding
is now in Libgcrypt, use the new interface.
2003-07-31 Werner Koch <wk@gnupg.org> 2003-07-31 Werner Koch <wk@gnupg.org>
* Makefile.am (gpg_agent_LDADD): Added INTLLIBS. * Makefile.am (gpg_agent_LDADD): Added INTLLIBS.

View File

@ -32,54 +32,32 @@
static int static int
do_encode_md (const unsigned char *digest, size_t digestlen, int algo, do_encode_md (const byte * md, size_t mdlen, int algo, gcry_sexp_t * r_hash)
unsigned int nbits, gcry_mpi_t *r_val)
{ {
int nframe = (nbits+7) / 8; gcry_sexp_t hash;
byte *frame; const char * s;
int i, n; char * p, tmp[16];
byte asn[100]; int i, rc;
size_t asnlen;
asnlen = DIM(asn); p = xmalloc (64+mdlen);
if (gcry_md_algo_info (algo, GCRYCTL_GET_ASNOID, asn, &asnlen)) s = gcry_md_algo_name (algo);
if (s && strlen (s) < 16)
{ {
log_error ("no object identifier for algo %d\n", algo); for (i=0; i < strlen (s); i++)
return gpg_error (GPG_ERR_INTERNAL); tmp[i] = tolower (s[i]);
tmp[i] = '\0';
} }
sprintf (p, "(data\n (flags pkcs1)\n (hash %s #", tmp);
if (digestlen + asnlen + 4 > nframe ) for (i=0; i < mdlen; i++)
{ {
log_error ("can't encode a %d bit MD into a %d bits frame\n", sprintf (tmp, "%02x", md[i]);
(int)(digestlen*8), (int)nbits); strcat (p, tmp);
return gpg_error (GPG_ERR_INTERNAL);
} }
strcat (p, "#))\n");
/* We encode the MD in this way: rc = gcry_sexp_sscan (&hash, NULL, p, strlen (p));
* xfree (p);
* 0 1 PAD(n bytes) 0 ASN(asnlen bytes) MD(len bytes) *r_hash = hash;
* return rc;
* PAD consists of FF bytes.
*/
frame = xtrymalloc (nframe);
if (!frame)
return out_of_core ();
n = 0;
frame[n++] = 0;
frame[n++] = 1; /* block type */
i = nframe - digestlen - asnlen -3 ;
assert ( i > 1 );
memset ( frame+n, 0xff, i ); n += i;
frame[n++] = 0;
memcpy ( frame+n, asn, asnlen ); n += asnlen;
memcpy ( frame+n, digest, digestlen ); n += digestlen;
assert ( n == nframe );
if (DBG_CRYPTO)
log_printhex ("encoded hash:", frame, nframe);
gcry_mpi_scan (r_val, GCRYMPI_FMT_USG, frame, n, &nframe);
xfree (frame);
return 0;
} }
@ -132,12 +110,9 @@ agent_pksign (CTRL ctrl, FILE *outfp, int ignore_cache)
rc = do_encode_md (ctrl->digest.value, rc = do_encode_md (ctrl->digest.value,
ctrl->digest.valuelen, ctrl->digest.valuelen,
ctrl->digest.algo, ctrl->digest.algo,
gcry_pk_get_nbits (s_skey), &s_hash);
&frame);
if (rc) if (rc)
goto leave; goto leave;
if ( gcry_sexp_build (&s_hash, NULL, "%m", frame) )
BUG ();
if (DBG_CRYPTO) if (DBG_CRYPTO)
{ {