From cfc1497efa8c98cf490f5efc9b280a6ec44514bd Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 12 Mar 2021 16:15:04 +0900 Subject: gpg: Fix compute_fingerprint for ECC with SOS. * g10/keyid.c (hash_public_key): Tweak NBITS just as sos_write does. -- Signed-off-by: NIIBE Yutaka --- g10/keyid.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'g10') diff --git a/g10/keyid.c b/g10/keyid.c index caf2e4f6f..522cc9cda 100644 --- a/g10/keyid.c +++ b/g10/keyid.c @@ -180,7 +180,7 @@ hash_public_key (gcry_md_hd_t md, PKT_public_key *pk) } else if (gcry_mpi_get_flag (pk->pkey[i], GCRYMPI_FLAG_OPAQUE)) { - const void *p; + const char *p; int is_sos = 0; if (gcry_mpi_get_flag (pk->pkey[i], GCRYMPI_FLAG_USER2)) @@ -194,6 +194,21 @@ hash_public_key (gcry_md_hd_t md, PKT_public_key *pk) pp[i] = NULL; if (is_sos) { + if (*p) + { + nbits = ((nbits + 7) / 8) * 8; + + if (nbits >= 8 && !(*p & 0x80)) + if (--nbits >= 7 && !(*p & 0x40)) + if (--nbits >= 6 && !(*p & 0x20)) + if (--nbits >= 5 && !(*p & 0x10)) + if (--nbits >= 4 && !(*p & 0x08)) + if (--nbits >= 3 && !(*p & 0x04)) + if (--nbits >= 2 && !(*p & 0x02)) + if (--nbits >= 1 && !(*p & 0x01)) + --nbits; + } + pp[i][0] = (nbits >> 8); pp[i][1] = nbits; } -- cgit v1.2.3