scd: Fix varargs call for 64-bit arch on ECC keys
NIIBE Yutaka
gniibe at fsij.org
Tue Jan 27 13:05:34 CET 2015
On 01/27/2015 07:21 PM, Werner Koch wrote:
> 'L' indicates a long but we need a size_t. On 64 bit Windows we have
>
> sizeof(int) == 4
> sizeof(long) == 4
> sizeof(size_t) == 8
>
> thus using
>
> curve == CURVE_ED25519 ? (size_t)10
> : curve == CURVE_NIST_P256? (size_t)9 : (size_t)6,
> ecc_q, ecc_q_len, "\x03\x01\x08\x07", (size_t)4);
>
> would be correct. Or we change store_fpr to take an int.
My badness. I only considered LP64 model and didn't consider LLP64
model.
If we change store_fpr to take an int, we need to change the calls for
RSA by casting int. I'd like to choose less typing.
Not only casting, but OID hard coding and hash/cipher algo hard coding
also look bad. I will update this code, when I will add Curve25519
support.
Meanwhile, here is updated patch. OK to commit?
scd: Fix varargs call for 64-bit arch on ECC keys.
* scd/app-openpgp.c (store_fpr): Remove CARD_VERSION from the
arguments.
(rsa_writekey): Follow the change.
(do_genkey): Likewise.
(ecc_writekey): Likewise. Cast to size_t.
--
KEYTOCARD caused SEGV of scdaemon on 64-bit arch. That's because
int is 32-bit, but size_t is 64-bit.
diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c
index 7f1ec43..f68813b 100644
--- a/scd/app-openpgp.c
+++ b/scd/app-openpgp.c
@@ -755,10 +755,8 @@ get_algo_byte (int keynumber, key_type_t key_type)
/* Note, that FPR must be at least 20 bytes. */
static gpg_error_t
-store_fpr (app_t app, int keynumber, u32 timestamp,
- unsigned char *fpr, unsigned int card_version,
- key_type_t key_type,
- ...)
+store_fpr (app_t app, int keynumber, u32 timestamp, unsigned char *fpr,
+ key_type_t key_type, ...)
{
unsigned int n, nbits;
unsigned char *buffer, *p;
@@ -821,7 +819,7 @@ store_fpr (app_t app, int keynumber, u32 timestamp,
xfree (buffer);
- tag = (card_version > 0x0007? 0xC7 : 0xC6) + keynumber;
+ tag = (app->card_version > 0x0007? 0xC7 : 0xC6) + keynumber;
flush_cache_item (app, 0xC5);
tag2 = 0xCE + keynumber;
flush_cache_item (app, 0xCD);
@@ -830,7 +828,7 @@ store_fpr (app_t app, int keynumber, u32 timestamp,
if (rc)
log_error (_("failed to store the fingerprint: %s\n"),gpg_strerror (rc));
- if (!rc && card_version > 0x0100)
+ if (!rc && app->card_version > 0x0100)
{
unsigned char buf[4];
@@ -3196,8 +3194,8 @@ rsa_writekey (app_t app, gpg_error_t (*pincb)(void*, const char *, char **),
goto leave;
}
- err = store_fpr (app, keyno, created_at, fprbuf, app->card_version,
- KEY_TYPE_RSA, rsa_n, rsa_n_len, rsa_e, rsa_e_len);
+ err = store_fpr (app, keyno, created_at, fprbuf, KEY_TYPE_RSA,
+ rsa_n, rsa_n_len, rsa_e, rsa_e_len);
if (err)
goto leave;
@@ -3383,16 +3381,16 @@ ecc_writekey (app_t app, gpg_error_t (*pincb)(void*, const char *, char **),
goto leave;
}
- err = store_fpr (app, keyno, created_at, fprbuf, app->card_version,
+ err = store_fpr (app, keyno, created_at, fprbuf,
curve == CURVE_ED25519 ? KEY_TYPE_EDDSA : KEY_TYPE_ECC,
curve == CURVE_ED25519 ?
"\x09\x2b\x06\x01\x04\x01\xda\x47\x0f\x01"
: curve == CURVE_NIST_P256 ?
"\x08\x2a\x86\x48\xce\x3d\x03\x01\x07"
: "\x05\x2b\x81\x04\x00\x0a",
- curve == CURVE_ED25519 ? 10
- : curve == CURVE_NIST_P256? 9 : 6,
- ecc_q, ecc_q_len, "\x03\x01\x08\x07", 4);
+ (size_t)(curve == CURVE_ED25519 ? 10
+ : curve == CURVE_NIST_P256? 9 : 6),
+ ecc_q, ecc_q_len, "\x03\x01\x08\x07", (size_t)4);
if (err)
goto leave;
@@ -3604,8 +3602,8 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
send_status_info (ctrl, "KEY-CREATED-AT",
numbuf, (size_t)strlen(numbuf), NULL, 0);
- rc = store_fpr (app, keyno, (u32)created_at, fprbuf, app->card_version,
- KEY_TYPE_RSA, m, mlen, e, elen);
+ rc = store_fpr (app, keyno, (u32)created_at, fprbuf, KEY_TYPE_RSA,
+ m, mlen, e, elen);
if (rc)
goto leave;
send_fpr_if_not_null (ctrl, "KEY-FPR", -1, fprbuf);
--
More information about the Gnupg-devel
mailing list