1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-03-28 22:49:59 +01:00

scd: Add handling of Ed448 key.

* scd/app-openpgp.c (struct app_local_s): Add ecc.algo field.
(send_key_attr): Use ecc.algo field.
(ecc_read_pubkey): Use ecc.algo field.
(ecc_writekey): Ed448 means EdDSA.
(parse_algorithm_attribute): Set ecc.algo field from card.
Add checking for Ed25519 for ECC_FLAG_DJB_TWEAK flag.

--

There used to be a possible support of Ed25519 with ECDSA, (instead of
EdDSA).  To distinguish key for Ed25519 for EdDSA, we use the
flag: (flags eddsa).  Ed448 has no support for ECDSA and defaults to
EdDSA even if no such flag.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
(cherry picked from commit b743942a9719be59f1da67cd338248fe7ee5aeab)
This commit is contained in:
NIIBE Yutaka 2021-03-15 17:02:32 +09:00 committed by Werner Koch
parent b262a21c61
commit 52abdac2d4
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -245,7 +245,8 @@ struct app_local_s {
} rsa; } rsa;
struct { struct {
const char *curve; const char *curve;
int flags; int algo;
unsigned int flags;
} ecc; } ecc;
}; };
} keyattr[3]; } keyattr[3];
@ -1011,9 +1012,7 @@ send_key_attr (ctrl_t ctrl, app_t app, const char *keyword, int keyno)
{ {
snprintf (buffer, sizeof buffer, "%d %d %s", snprintf (buffer, sizeof buffer, "%d %d %s",
keyno+1, keyno+1,
keyno==1? PUBKEY_ALGO_ECDH : app->app_local->keyattr[keyno].ecc.algo,
(app->app_local->keyattr[keyno].ecc.flags & ECC_FLAG_DJB_TWEAK)?
PUBKEY_ALGO_EDDSA : PUBKEY_ALGO_ECDSA,
app->app_local->keyattr[keyno].ecc.curve); app->app_local->keyattr[keyno].ecc.curve);
} }
else else
@ -1719,18 +1718,11 @@ ecc_read_pubkey (app_t app, ctrl_t ctrl, int meta_update,
send_key_data (ctrl, "curve", oidbuf, oid_len); send_key_data (ctrl, "curve", oidbuf, oid_len);
} }
algo = app->app_local->keyattr[keyno].ecc.algo;
if (keyno == 1) if (keyno == 1)
{ {
if (ctrl) if (ctrl)
send_key_data (ctrl, "kdf/kek", ecdh_params (curve), (size_t)4); send_key_data (ctrl, "kdf/kek", ecdh_params (curve), (size_t)4);
algo = PUBKEY_ALGO_ECDH;
}
else
{
if ((app->app_local->keyattr[keyno].ecc.flags & ECC_FLAG_DJB_TWEAK))
algo = PUBKEY_ALGO_EDDSA;
else
algo = PUBKEY_ALGO_ECDSA;
} }
if (ctrl) if (ctrl)
@ -4225,6 +4217,8 @@ ecc_writekey (app_t app, ctrl_t ctrl,
curve = "secp256k1" */ curve = "secp256k1" */
/* (private-key(ecc(curve%s)(flags eddsa)(q%m)(d%m))(created-at%d)): /* (private-key(ecc(curve%s)(flags eddsa)(q%m)(d%m))(created-at%d)):
curve = "Ed25519" */ curve = "Ed25519" */
/* (private-key(ecc(curve%s)(q%m)(d%m))(created-at%d)):
curve = "Ed448" */
last_depth1 = depth; last_depth1 = depth;
while (!(err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen)) while (!(err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen))
&& depth && depth >= last_depth1) && depth && depth >= last_depth1)
@ -4369,6 +4363,8 @@ ecc_writekey (app_t app, ctrl_t ctrl,
algo = PUBKEY_ALGO_EDDSA; algo = PUBKEY_ALGO_EDDSA;
else if (keyno == 1) else if (keyno == 1)
algo = PUBKEY_ALGO_ECDH; algo = PUBKEY_ALGO_ECDH;
else if (!strcmp (curve, "Ed448"))
algo = PUBKEY_ALGO_EDDSA;
else else
algo = PUBKEY_ALGO_ECDSA; algo = PUBKEY_ALGO_ECDSA;
@ -5707,6 +5703,7 @@ parse_algorithm_attribute (app_t app, int keyno)
{ {
int oidlen = buflen - 1; int oidlen = buflen - 1;
app->app_local->keyattr[keyno].ecc.algo = *buffer;
app->app_local->keyattr[keyno].ecc.flags = 0; app->app_local->keyattr[keyno].ecc.flags = 0;
if (APP_CARD(app)->cardtype == CARDTYPE_YUBIKEY) if (APP_CARD(app)->cardtype == CARDTYPE_YUBIKEY)
@ -5741,7 +5738,9 @@ parse_algorithm_attribute (app_t app, int keyno)
{ {
app->app_local->keyattr[keyno].key_type = KEY_TYPE_ECC; app->app_local->keyattr[keyno].key_type = KEY_TYPE_ECC;
app->app_local->keyattr[keyno].ecc.curve = curve; app->app_local->keyattr[keyno].ecc.curve = curve;
if (*buffer == PUBKEY_ALGO_EDDSA if ((*buffer == PUBKEY_ALGO_EDDSA
&& !strcmp (app->app_local->keyattr[keyno].ecc.curve,
"Ed25519"))
|| (*buffer == PUBKEY_ALGO_ECDH || (*buffer == PUBKEY_ALGO_ECDH
&& !strcmp (app->app_local->keyattr[keyno].ecc.curve, && !strcmp (app->app_local->keyattr[keyno].ecc.curve,
"Curve25519"))) "Curve25519")))