1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

* packet.h, build-packet.c (hash_public_key): Remove function ...

* keydb.h, keyid.c (hash_public_key, do_fingerprint_md): ... and make a
new one here that shares code with the fingerprint calculations.  This
removes some duplicated functionality, and is also around 14% faster.
(Every bit helps).

* import.c (import_one): No longer need the Elgamal import warning.

* getkey.c (get_pubkey_fast): This one is sort of obscure. get_pubkey_fast
returns the primary key when requesting a subkey, so if a user has a key
signed by a subkey (we don't do this, but used to), AND that key is not
self-signed, AND the algorithm of the subkey in question is not present in
GnuPG, AND the algorithm of the primary key that owns the subkey in
question is present in GnuPG, then we will try and verify the subkey
signature using the primary key algorithm and hit a BUG().  The fix is to
not return a hit if the keyid is not the primary.  All other users of
get_pubkey_fast already expect a primary only.
This commit is contained in:
David Shaw 2003-12-11 01:07:42 +00:00
parent 888a6c2980
commit db5ab5e730
7 changed files with 108 additions and 143 deletions

View file

@ -47,59 +47,80 @@ pubkey_letter( int algo )
}
}
/* This function is useful for v4 fingerprints and v3 or v4 key
signing. */
void
hash_public_key( MD_HANDLE md, PKT_public_key *pk )
{
unsigned n=6;
unsigned nb[PUBKEY_MAX_NPKEY];
unsigned nn[PUBKEY_MAX_NPKEY];
byte *pp[PUBKEY_MAX_NPKEY];
int i;
int npkey = pubkey_get_npkey( pk->pubkey_algo );
/* Two extra bytes for the expiration date in v3 */
if(pk->version<4)
n+=2;
if(npkey==0 && pk->pkey[0] && mpi_is_opaque(pk->pkey[0]))
{
pp[0]=mpi_get_opaque(pk->pkey[0],&nn[0]);
n+=nn[0];
}
else
for(i=0; i < npkey; i++ )
{
nb[i] = mpi_get_nbits(pk->pkey[i]);
pp[i] = mpi_get_buffer( pk->pkey[i], nn+i, NULL );
n += 2 + nn[i];
}
md_putc( md, 0x99 ); /* ctb */
/* What does it mean if n is greater than than 0xFFFF ? */
md_putc( md, n >> 8 ); /* 2 byte length header */
md_putc( md, n );
md_putc( md, pk->version );
md_putc( md, pk->timestamp >> 24 );
md_putc( md, pk->timestamp >> 16 );
md_putc( md, pk->timestamp >> 8 );
md_putc( md, pk->timestamp );
if(pk->version<4)
{
u16 days=0;
if(pk->expiredate)
days=(u16)((pk->expiredate - pk->timestamp) / 86400L);
md_putc( md, days >> 8 );
md_putc( md, days );
}
md_putc( md, pk->pubkey_algo );
if(npkey==0 && pk->pkey[0] && mpi_is_opaque(pk->pkey[0]))
md_write(md,pp[0],nn[0]);
else
for(i=0; i < npkey; i++ )
{
md_putc( md, nb[i]>>8);
md_putc( md, nb[i] );
md_write( md, pp[i], nn[i] );
m_free(pp[i]);
}
}
static MD_HANDLE
do_fingerprint_md( PKT_public_key *pk )
{
MD_HANDLE md;
unsigned n=6;
unsigned nb[PUBKEY_MAX_NPKEY];
unsigned nn[PUBKEY_MAX_NPKEY];
byte *pp[PUBKEY_MAX_NPKEY];
int i;
int npkey = pubkey_get_npkey( pk->pubkey_algo );
MD_HANDLE md;
md = md_open( DIGEST_ALGO_SHA1, 0);
md = md_open( DIGEST_ALGO_SHA1, 0);
hash_public_key(md,pk);
md_final( md );
if(npkey==0 && pk->pkey[0] && mpi_is_opaque(pk->pkey[0]))
{
pp[0]=mpi_get_opaque(pk->pkey[0],&nn[0]);
n+=nn[0];
}
else
for(i=0; i < npkey; i++ )
{
nb[i] = mpi_get_nbits(pk->pkey[i]);
pp[i] = mpi_get_buffer( pk->pkey[i], nn+i, NULL );
n += 2 + nn[i];
}
md_putc( md, 0x99 ); /* ctb */
/* What does it mean if n is greater than than 0xFFFF ? */
md_putc( md, n >> 8 ); /* 2 byte length header */
md_putc( md, n );
md_putc( md, 4 );
md_putc( md, pk->timestamp >> 24 );
md_putc( md, pk->timestamp >> 16 );
md_putc( md, pk->timestamp >> 8 );
md_putc( md, pk->timestamp );
md_putc( md, pk->pubkey_algo );
if(npkey==0 && pk->pkey[0] && mpi_is_opaque(pk->pkey[0]))
md_write(md,pp[0],nn[0]);
else
for(i=0; i < npkey; i++ )
{
md_putc( md, nb[i]>>8);
md_putc( md, nb[i] );
md_write( md, pp[i], nn[i] );
m_free(pp[i]);
}
md_final( md );
return md;
return md;
}
static MD_HANDLE
@ -122,7 +143,6 @@ do_fingerprint_md_sk( PKT_secret_key *sk )
return do_fingerprint_md( &pk );
}
/****************
* Get the keyid from the secret key and put it into keyid
* if this is not NULL. Return the 32 low bits of the keyid.