fixed OpenPGPv3 fingerprint computation
This commit is contained in:
committed by
Martin Willi
parent
d17a120598
commit
1bb4d7dd79
@@ -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)
|
static identification_t* gmp_rsa_build_pgp_v3_keyid(mpz_t n, mpz_t e)
|
||||||
{
|
{
|
||||||
identification_t *keyid;
|
identification_t *keyid;
|
||||||
chunk_t modulus, exponent, hash;
|
chunk_t modulus, mod, exponent, exp, hash;
|
||||||
hasher_t *hasher;
|
hasher_t *hasher;
|
||||||
|
|
||||||
hasher= lib->crypto->create_hasher(lib->crypto, HASH_MD5);
|
hasher= lib->crypto->create_hasher(lib->crypto, HASH_MD5);
|
||||||
if (hasher == NULL)
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
modulus = gmp_mpz_to_chunk(n);
|
mod = modulus = gmp_mpz_to_chunk(n);
|
||||||
exponent = gmp_mpz_to_chunk(e);
|
exp = exponent = gmp_mpz_to_chunk(e);
|
||||||
hasher->allocate_hash(hasher, modulus, NULL);
|
|
||||||
hasher->allocate_hash(hasher, exponent, &hash);
|
/* 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);
|
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(hash.ptr);
|
||||||
free(modulus.ptr);
|
free(modulus.ptr);
|
||||||
free(exponent.ptr);
|
free(exponent.ptr);
|
||||||
|
|||||||
Reference in New Issue
Block a user