scd: Fix computing fingerprint for ECC with SOS.

* scd/app-openpgp.c (count_sos_bits): New.  Count as sos_write does.
(store_fpr): For ECC, use count_sos_bits.

--

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2021-03-12 16:20:28 +09:00
parent cfc1497efa
commit 95156ef9bf
1 changed files with 22 additions and 1 deletions

View File

@ -717,6 +717,21 @@ count_bits (const unsigned char *a, size_t len)
return n;
}
static unsigned int
count_sos_bits (const unsigned char *a, size_t len)
{
unsigned int n = len * 8;
int i;
if (*a == 0)
return n;
for (i=7; i && !(*a & (1<<i)); i--)
n--;
return n;
}
/* GnuPG makes special use of the login-data DO, this function parses
the login data to store the flags for later use. It may be called
at any time and should be called after changing the login-data DO.
@ -890,12 +905,18 @@ store_fpr (app_t app, int keynumber, u32 timestamp, unsigned char *fpr,
for (i = 0; i < argc; i++)
{
if (algo == PUBKEY_ALGO_RSA || i == 1)
if (algo == PUBKEY_ALGO_RSA)
{
nbits = count_bits (m[i], mlen[i]);
*p++ = nbits >> 8;
*p++ = nbits;
}
else if (i == 1)
{
nbits = count_sos_bits (m[i], mlen[i]);
*p++ = nbits >> 8;
*p++ = nbits;
}
memcpy (p, m[i], mlen[i]);
p += mlen[i];
}