From 1bb4d7dd79940edd1a83a9c1517c947b12ee7400 Mon Sep 17 00:00:00 2001 From: Andreas Steffen Date: Sat, 6 Jun 2009 14:41:26 +0200 Subject: [PATCH] fixed OpenPGPv3 fingerprint computation --- .../plugins/gmp/gmp_rsa_public_key.c | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c b/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c index 4c779703b..76495c7f5 100644 --- a/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c +++ b/src/libstrongswan/plugins/gmp/gmp_rsa_public_key.c @@ -371,21 +371,33 @@ static size_t get_keysize(private_gmp_rsa_public_key_t *this) static identification_t* gmp_rsa_build_pgp_v3_keyid(mpz_t n, mpz_t e) { identification_t *keyid; - chunk_t modulus, exponent, hash; + chunk_t modulus, mod, exponent, exp, hash; hasher_t *hasher; hasher= lib->crypto->create_hasher(lib->crypto, HASH_MD5); if (hasher == NULL) { - DBG1("computation of PGP V3 key ID failed, no MD5 hasher is available"); + DBG1("computation of PGP V3 keyid failed, no MD5 hasher is available"); return NULL; } - modulus = gmp_mpz_to_chunk(n); - exponent = gmp_mpz_to_chunk(e); - hasher->allocate_hash(hasher, modulus, NULL); - hasher->allocate_hash(hasher, exponent, &hash); + mod = modulus = gmp_mpz_to_chunk(n); + exp = exponent = gmp_mpz_to_chunk(e); + + /* remove leading zero bytes before hashing modulus and exponent */ + while (mod.len > 0 && *mod.ptr == 0x00) + { + mod.ptr++; + mod.len--; + } + while (exp.len > 0 && *exp.ptr == 0x00) + { + exp.ptr++; + exp.len--; + } + hasher->allocate_hash(hasher, mod, NULL); + hasher->allocate_hash(hasher, exp, &hash); hasher->destroy(hasher); - keyid = identification_create_from_encoding(ID_PUBKEY_SHA1, hash); + keyid = identification_create_from_encoding(ID_KEY_ID, hash); free(hash.ptr); free(modulus.ptr); free(exponent.ptr);