aboutsummaryrefslogtreecommitdiffstats
path: root/g10/sign.c
diff options
context:
space:
mode:
authorDavid Shaw <[email protected]>2002-11-25 04:06:04 +0000
committerDavid Shaw <[email protected]>2002-11-25 04:06:04 +0000
commit8b9e9d33c15ceb660d440acc45ab95b3ff54ebac (patch)
tree4dd9eda56ddbfc39b17f11c80970cfcf0a6bb799 /g10/sign.c
parent* g10.c (main), keydb.c (keydb_add_resource, keydb_locate_writable): (diff)
downloadgnupg-8b9e9d33c15ceb660d440acc45ab95b3ff54ebac.tar.gz
gnupg-8b9e9d33c15ceb660d440acc45ab95b3ff54ebac.zip
* sign.c (hash_for): If --digest-algo is not set, but
--personal-digest-preferences is, then use the first hash algorithm in the personal list. If the signing algorithm is DSA, then use the first 160-bit hash algorithm in the personal list. If --pgp2 is set and it's a v3 RSA key, use MD5.
Diffstat (limited to 'g10/sign.c')
-rw-r--r--g10/sign.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/g10/sign.c b/g10/sign.c
index 047dd13fc..8e444ddda 100644
--- a/g10/sign.c
+++ b/g10/sign.c
@@ -332,14 +332,38 @@ complete_sig( PKT_signature *sig, PKT_secret_key *sk, MD_HANDLE md )
static int
hash_for(int pubkey_algo, int packet_version )
{
- if( opt.def_digest_algo )
- return opt.def_digest_algo;
- if( recipient_digest_algo )
- return recipient_digest_algo;
- if( pubkey_algo == PUBKEY_ALGO_DSA )
- return DIGEST_ALGO_SHA1;
- if( pubkey_algo == PUBKEY_ALGO_RSA && packet_version < 4 )
- return DIGEST_ALGO_MD5;
+ if( opt.def_digest_algo )
+ return opt.def_digest_algo;
+ else if( recipient_digest_algo )
+ return recipient_digest_algo;
+ else if(opt.pgp2 && pubkey_algo == PUBKEY_ALGO_RSA && packet_version < 4 )
+ {
+ /* Old-style PGP only understands MD5 */
+ return DIGEST_ALGO_MD5;
+ }
+ else if( pubkey_algo == PUBKEY_ALGO_DSA )
+ {
+ /* We need a 160-bit hash for DSA, so we can't just take the first
+ in the pref list */
+
+ if(opt.personal_digest_prefs)
+ {
+ prefitem_t *prefs;
+
+ for(prefs=opt.personal_digest_prefs;prefs->type;prefs++)
+ if(md_digest_length(prefs->value)==20)
+ return prefs->value;
+ }
+
+ return DIGEST_ALGO_SHA1;
+ }
+ else if( opt.personal_digest_prefs )
+ {
+ /* It's not DSA, so we can use whatever the first hash algorithm
+ is in the pref list */
+ return opt.personal_digest_prefs[0].value;
+ }
+ else
return DEFAULT_DIGEST_ALGO;
}