1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-03-24 22:09:57 +01:00

* keydb.h, keyid.c (keystr_from_pk, keystr_from_sk): New functions to pull

a key string from a key in one step.  This isn't faster than before, but
makes for neater code.

* keylist.c (list_keyblock_print): Use keystr_from_xx here.
(print_key_data): No need to pass a keyid in.
This commit is contained in:
David Shaw 2004-03-06 17:12:44 +00:00
parent efec599797
commit b8cd31217e
4 changed files with 95 additions and 65 deletions

View File

@ -1,3 +1,12 @@
2004-03-06 David Shaw <dshaw@jabberwocky.com>
* keydb.h, keyid.c (keystr_from_pk, keystr_from_sk): New functions
to pull a key string from a key in one step. This isn't faster
than before, but makes for neater code.
* keylist.c (list_keyblock_print): Use keystr_from_xx here.
(print_key_data): No need to pass a keyid in.
2004-03-05 David Shaw <dshaw@jabberwocky.com>
* keyid.c (keyid_from_sk): Minor performance boost by caching
@ -9,7 +18,7 @@
* passphrase.c (passphrase_to_dek): Give a little more information
when we have room to do so.
2004-03-04 David Shaw <dshaw@jabberwocky.com>
* revoke.c (export_minimal_pk), export.c (do_export_stream),

View File

@ -241,10 +241,12 @@ int pubkey_letter( int algo );
void hash_public_key( MD_HANDLE md, PKT_public_key *pk );
size_t keystrlen(void);
const char *keystr(u32 *keyid);
const char *keystr_from_pk(PKT_public_key *pk);
const char *keystr_from_sk(PKT_secret_key *sk);
u32 keyid_from_sk( PKT_secret_key *sk, u32 *keyid );
u32 keyid_from_pk( PKT_public_key *pk, u32 *keyid );
u32 keyid_from_sig( PKT_signature *sig, u32 *keyid );
u32 keyid_from_fingerprint( const byte *fprint, size_t fprint_len, u32 *keyid );
u32 keyid_from_fingerprint(const byte *fprint, size_t fprint_len, u32 *keyid);
byte *namehash_from_uid(PKT_user_id *uid);
unsigned nbits_from_pk( PKT_public_key *pk );
unsigned nbits_from_sk( PKT_secret_key *sk );

View File

@ -196,6 +196,21 @@ keystr(u32 *keyid)
return keyid_str;
}
const char *
keystr_from_pk(PKT_public_key *pk)
{
keyid_from_pk(pk,NULL);
return keystr(pk->keyid);
}
const char *
keystr_from_sk(PKT_secret_key *sk)
{
keyid_from_sk(sk,NULL);
return keystr(sk->keyid);
}
/****************
* Get the keyid from the secret key and put it into keyid
@ -258,43 +273,50 @@ keyid_from_sk( PKT_secret_key *sk, u32 *keyid )
u32
keyid_from_pk( PKT_public_key *pk, u32 *keyid )
{
u32 lowbits;
u32 dummy_keyid[2];
u32 lowbits;
u32 dummy_keyid[2];
if( !keyid )
keyid = dummy_keyid;
if( !keyid )
keyid = dummy_keyid;
if( pk->keyid[0] || pk->keyid[1] ) {
keyid[0] = pk->keyid[0];
keyid[1] = pk->keyid[1];
lowbits = keyid[1];
if( pk->keyid[0] || pk->keyid[1] )
{
keyid[0] = pk->keyid[0];
keyid[1] = pk->keyid[1];
lowbits = keyid[1];
}
else if( pk->version < 4 )
{
if( is_RSA(pk->pubkey_algo) )
{
lowbits = pubkey_get_npkey(pk->pubkey_algo) ?
mpi_get_keyid( pk->pkey[0], keyid ) : 0 ; /* from n */
pk->keyid[0] = keyid[0];
pk->keyid[1] = keyid[1];
}
else
pk->keyid[0]=pk->keyid[1]=keyid[0]=keyid[1]=lowbits=0;
}
else {
const byte *dp;
MD_HANDLE md;
md = do_fingerprint_md(pk);
dp = md_read( md, 0 );
keyid[0] = dp[12] << 24 | dp[13] << 16 | dp[14] << 8 | dp[15] ;
keyid[1] = dp[16] << 24 | dp[17] << 16 | dp[18] << 8 | dp[19] ;
lowbits = keyid[1];
md_close(md);
pk->keyid[0] = keyid[0];
pk->keyid[1] = keyid[1];
else if( pk->version < 4 )
{
if( is_RSA(pk->pubkey_algo) )
{
lowbits = pubkey_get_npkey(pk->pubkey_algo) ?
mpi_get_keyid( pk->pkey[0], keyid ) : 0 ; /* from n */
pk->keyid[0] = keyid[0];
pk->keyid[1] = keyid[1];
}
else
pk->keyid[0]=pk->keyid[1]=keyid[0]=keyid[1]=lowbits=0;
}
else
{
const byte *dp;
MD_HANDLE md;
md = do_fingerprint_md(pk);
if(md)
{
dp = md_read( md, 0 );
keyid[0] = dp[12] << 24 | dp[13] << 16 | dp[14] << 8 | dp[15] ;
keyid[1] = dp[16] << 24 | dp[17] << 16 | dp[18] << 8 | dp[19] ;
lowbits = keyid[1];
md_close(md);
pk->keyid[0] = keyid[0];
pk->keyid[1] = keyid[1];
}
else
pk->keyid[0]=pk->keyid[1]=keyid[0]=keyid[1]=lowbits=0;
}
return lowbits;
return lowbits;
}

View File

@ -460,7 +460,7 @@ list_one( STRLIST names, int secret )
}
static void
print_key_data( PKT_public_key *pk, u32 *keyid )
print_key_data( PKT_public_key *pk )
{
int n = pk ? pubkey_get_npkey( pk->pubkey_algo ) : 0;
int i;
@ -600,7 +600,6 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
KBNODE node;
PKT_public_key *pk;
PKT_secret_key *sk;
u32 keyid[2];
int any=0;
struct sig_stats *stats=opaque;
int skip_sigs=0;
@ -621,12 +620,11 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
{
pk = NULL;
sk = node->pkt->pkt.secret_key;
keyid_from_sk( sk, keyid );
printf("sec%c %4u%c/%s %s%s",(sk->protect.s2k.mode==1001)?'#':
(sk->protect.s2k.mode==1002)?'>':' ',
nbits_from_sk( sk ),pubkey_letter( sk->pubkey_algo ),
keystr(keyid),datestr_from_sk( sk ),newformat?"":" " );
keystr_from_sk(sk),datestr_from_sk( sk ),newformat?"":" " );
if(newformat && sk->expiredate )
printf(_(" [expires: %s]"), expirestr_from_sk( sk ) );
@ -638,7 +636,6 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
#endif
pk = node->pkt->pkt.public_key;
sk = NULL;
keyid_from_pk( pk, keyid );
#if 0
validity=get_validity(pk,NULL);
@ -648,7 +645,7 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
printf("pub %4u%c/%s %s%s",
nbits_from_pk(pk),pubkey_letter(pk->pubkey_algo),
keystr(keyid),datestr_from_pk( pk ),newformat?"":" " );
keystr_from_pk(pk),datestr_from_pk( pk ),newformat?"":" " );
/* We didn't include this before in the key listing, but there
is room in the new format, so why not? */
@ -721,15 +718,15 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
if( fpr )
print_fingerprint( pk, sk, 0 );
if( opt.with_key_data )
print_key_data( pk, keyid );
print_key_data( pk );
any = 1;
}
if((opt.list_options&LIST_SHOW_PHOTOS) && uid->attribs!=NULL)
show_photos(uid->attribs,uid->numattribs,pk,sk);
}
else if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
u32 keyid2[2];
else if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY )
{
PKT_public_key *pk2 = node->pkt->pkt.public_key;
if((pk2->is_revoked || pk2->has_expired)
@ -741,52 +738,52 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
else
skip_sigs=0;
if( !any ) {
if( !any )
{
putchar('\n');
if( fpr )
print_fingerprint( pk, sk, 0 ); /* of the main key */
print_fingerprint( pk, sk, 0 ); /* of the main key */
any = 1;
}
}
keyid_from_pk( pk2, keyid2 );
printf("sub %4u%c/%s %s",
nbits_from_pk( pk2 ),pubkey_letter( pk2->pubkey_algo ),
keystr(keyid2),datestr_from_pk(pk2));
keystr_from_pk(pk2),datestr_from_pk(pk2));
if( pk2->is_revoked )
printf(_(" [revoked: %s]"), revokestr_from_pk(pk2));
else if( pk2->has_expired )
printf(_(" [expired: %s]"), expirestr_from_pk( pk2 ) );
printf(_(" [expired: %s]"), expirestr_from_pk( pk2 ) );
else if( pk2->expiredate )
printf(_(" [expires: %s]"), expirestr_from_pk( pk2 ) );
printf(_(" [expires: %s]"), expirestr_from_pk( pk2 ) );
putchar('\n');
if( fpr > 1 )
print_fingerprint( pk2, NULL, 0 );
print_fingerprint( pk2, NULL, 0 );
if( opt.with_key_data )
print_key_data( pk2, keyid2 );
}
else if( node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
u32 keyid2[2];
print_key_data( pk2 );
}
else if( node->pkt->pkttype == PKT_SECRET_SUBKEY )
{
PKT_secret_key *sk2 = node->pkt->pkt.secret_key;
if( !any ) {
if( !any )
{
putchar('\n');
if( fpr )
print_fingerprint( pk, sk, 0 ); /* of the main key */
print_fingerprint( pk, sk, 0 ); /* of the main key */
any = 1;
}
}
keyid_from_sk( sk2, keyid2 );
printf("ssb%c %4u%c/%s %s",
(sk->protect.s2k.mode==1001)?'#':
(sk->protect.s2k.mode==1002)?'>':' ',
nbits_from_sk( sk2 ),pubkey_letter( sk2->pubkey_algo ),
keystr(keyid2),datestr_from_sk( sk2 ) );
keystr_from_sk(sk2),datestr_from_sk( sk2 ) );
if( sk2->expiredate )
printf(_(" [expires: %s]"), expirestr_from_sk( sk2 ) );
putchar('\n');
if( fpr > 1 )
print_fingerprint( NULL, sk2, 0 );
}
print_fingerprint( NULL, sk2, 0 );
}
else if( opt.list_sigs
&& node->pkt->pkttype == PKT_SIGNATURE
&& !skip_sigs ) {
@ -980,7 +977,7 @@ list_keyblock_colon( KBNODE keyblock, int secret, int fpr )
if( fpr )
print_fingerprint( pk, sk, 0 );
if( opt.with_key_data )
print_key_data( pk, keyid );
print_key_data( pk );
any = 1;
}
@ -1040,7 +1037,7 @@ list_keyblock_colon( KBNODE keyblock, int secret, int fpr )
if( fpr )
print_fingerprint( pk, sk, 0 );
if( opt.with_key_data )
print_key_data( pk, keyid );
print_key_data( pk );
any = 1;
}
}
@ -1086,7 +1083,7 @@ list_keyblock_colon( KBNODE keyblock, int secret, int fpr )
if( fpr > 1 )
print_fingerprint( pk2, NULL, 0 );
if( opt.with_key_data )
print_key_data( pk2, keyid2 );
print_key_data( pk2 );
}
else if( node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
u32 keyid2[2];