diff options
author | David Shaw <[email protected]> | 2003-12-11 01:07:42 +0000 |
---|---|---|
committer | David Shaw <[email protected]> | 2003-12-11 01:07:42 +0000 |
commit | db5ab5e730c6cf2dd103967a305b3519c6c808b3 (patch) | |
tree | cc2192da8e6a9e685b64378c60bef5f40443a914 /g10/keyid.c | |
parent | * keyid.c (do_fingerprint_md): Remove the rules to hash the old v3 Elgamal (diff) | |
download | gnupg-db5ab5e730c6cf2dd103967a305b3519c6c808b3.tar.gz gnupg-db5ab5e730c6cf2dd103967a305b3519c6c808b3.zip |
* 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.
Diffstat (limited to '')
-rw-r--r-- | g10/keyid.c | 112 |
1 files changed, 66 insertions, 46 deletions
diff --git a/g10/keyid.c b/g10/keyid.c index 8641f7d94..3648e0579 100644 --- a/g10/keyid.c +++ b/g10/keyid.c @@ -47,59 +47,80 @@ pubkey_letter( int algo ) } } -static MD_HANDLE -do_fingerprint_md( PKT_public_key *pk ) +/* This function is useful for v4 fingerprints and v3 or v4 key + signing. */ +void +hash_public_key( MD_HANDLE 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 ); + 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 = md_open( DIGEST_ALGO_SHA1, 0); + md_putc( md, pk->timestamp >> 24 ); + md_putc( md, pk->timestamp >> 16 ); + md_putc( md, pk->timestamp >> 8 ); + md_putc( md, pk->timestamp ); - if(npkey==0 && pk->pkey[0] && mpi_is_opaque(pk->pkey[0])) + 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++ ) { - pp[0]=mpi_get_opaque(pk->pkey[0],&nn[0]); - n+=nn[0]; + md_putc( md, nb[i]>>8); + md_putc( md, nb[i] ); + md_write( md, pp[i], nn[i] ); + m_free(pp[i]); } - 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]); - } +static MD_HANDLE +do_fingerprint_md( PKT_public_key *pk ) +{ + MD_HANDLE md; - md_final( md ); + md = md_open( DIGEST_ALGO_SHA1, 0); + hash_public_key(md,pk); + 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. |