mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
gpg: Use only OpenPGP public key algo ids and add the EdDSA algo id.
* common/sexputil.c (get_pk_algo_from_canon_sexp): Change to return a string. * g10/keygen.c (check_keygrip): Adjust for change. * sm/certreqgen-ui.c (check_keygrip): Likewise. * agent/pksign.c (do_encode_dsa): Remove bogus map_pk_openpgp_to_gcry. * g10/misc.c (map_pk_openpgp_to_gcry): Remove. (openpgp_pk_test_algo): Change to a wrapper for openpgp_pk_test_algo2. (openpgp_pk_test_algo2): Rewrite. (openpgp_pk_algo_usage, pubkey_nbits): Add support for EdDSA. (openpgp_pk_algo_name): Rewrite to remove need for gcry calls. (pubkey_get_npkey, pubkey_get_nskey): Ditto. (pubkey_get_nsig, pubkey_get_nenc): Ditto. * g10/keygen.c(do_create_from_keygrip): Support EdDSA. (common_gen, gen_ecc, ask_keysize, generate_keypair): Ditto. * g10/build-packet.c (do_key): Ditto. * g10/export.c (transfer_format_to_openpgp): Ditto. * g10/getkey.c (cache_public_key): Ditto. * g10/import.c (transfer_secret_keys): Ditto. * g10/keylist.c (list_keyblock_print, list_keyblock_colon): Ditto. * g10/mainproc.c (proc_pubkey_enc): Ditto. * g10/parse-packet.c (parse_key): Ditto, * g10/sign.c (hash_for, sign_file, make_keysig_packet): Ditto. * g10/keyserver.c (print_keyrec): Use openpgp_pk_algo_name. * g10/pkglue.c (pk_verify, pk_encrypt, pk_check_secret_key): Use only OpenPGP algo ids and support EdDSA. * g10/pubkey-enc.c (get_it): Use only OpenPGP algo ids. * g10/seskey.c (encode_md_value): Ditto. -- This patch separates Libgcrypt and OpenPGP public key algorithms ids and in most cases completely removes the Libgcrypt ones. This is useful because for Libgcrypt we specify the algorithm in the S-expressions and the public key ids are not anymore needed. This patch also adds some support for PUBKEY_ALGO_EDDSA which will eventually be used instead of merging EdDSA with ECDSA. As of now an experimental algorithm id is used but the plan is to write an I-D so that we can get a new id from the IETF. Note that EdDSA (Ed25519) does not yet work and that more changes are required. The ECC support is still broken right now. Needs to be fixed. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
ea8a1685f7
commit
b7f8dec632
21 changed files with 323 additions and 253 deletions
86
g10/keygen.c
86
g10/keygen.c
|
@ -1235,6 +1235,7 @@ do_create_from_keygrip (ctrl_t ctrl, int algo, const char *hexkeygrip,
|
|||
case PUBKEY_ALGO_ELGAMAL_E: algoelem = "pgy"; break;
|
||||
case PUBKEY_ALGO_ECDH:
|
||||
case PUBKEY_ALGO_ECDSA: algoelem = ""; break;
|
||||
case PUBKEY_ALGO_EDDSA: algoelem = ""; break;
|
||||
default: return gpg_error (GPG_ERR_INTERNAL);
|
||||
}
|
||||
|
||||
|
@ -1268,7 +1269,9 @@ do_create_from_keygrip (ctrl_t ctrl, int algo, const char *hexkeygrip,
|
|||
pk->expiredate = pk->timestamp + expireval;
|
||||
pk->pubkey_algo = algo;
|
||||
|
||||
if (algo == PUBKEY_ALGO_ECDSA || algo == PUBKEY_ALGO_ECDH)
|
||||
if (algo == PUBKEY_ALGO_ECDSA
|
||||
|| algo == PUBKEY_ALGO_EDDSA
|
||||
|| algo == PUBKEY_ALGO_ECDH )
|
||||
err = ecckey_from_sexp (pk->pkey, s_key, algo);
|
||||
else
|
||||
err = key_from_sexp (pk->pkey, s_key, "public-key", algoelem);
|
||||
|
@ -1330,7 +1333,9 @@ common_gen (const char *keyparms, int algo, const char *algoelem,
|
|||
pk->expiredate = pk->timestamp + expireval;
|
||||
pk->pubkey_algo = algo;
|
||||
|
||||
if (algo == PUBKEY_ALGO_ECDSA || algo == PUBKEY_ALGO_ECDH)
|
||||
if (algo == PUBKEY_ALGO_ECDSA
|
||||
|| algo == PUBKEY_ALGO_EDDSA
|
||||
|| algo == PUBKEY_ALGO_ECDH )
|
||||
err = ecckey_from_sexp (pk->pkey, s_key, algo);
|
||||
else
|
||||
err = key_from_sexp (pk->pkey, s_key, "public-key", algoelem);
|
||||
|
@ -1508,7 +1513,9 @@ gen_ecc (int algo, const char *curve, kbnode_t pub_root,
|
|||
gpg_error_t err;
|
||||
char *keyparms;
|
||||
|
||||
assert (algo == PUBKEY_ALGO_ECDSA || algo == PUBKEY_ALGO_ECDH);
|
||||
assert (algo == PUBKEY_ALGO_ECDSA
|
||||
|| algo == PUBKEY_ALGO_EDDSA
|
||||
|| algo == PUBKEY_ALGO_ECDH);
|
||||
|
||||
if (!curve || !*curve)
|
||||
return gpg_error (GPG_ERR_UNKNOWN_CURVE);
|
||||
|
@ -1735,7 +1742,7 @@ check_keygrip (ctrl_t ctrl, const char *hexgrip)
|
|||
gpg_error_t err;
|
||||
unsigned char *public;
|
||||
size_t publiclen;
|
||||
int algo;
|
||||
const char *algostr;
|
||||
|
||||
if (hexgrip[0] == '&')
|
||||
hexgrip++;
|
||||
|
@ -1745,18 +1752,26 @@ check_keygrip (ctrl_t ctrl, const char *hexgrip)
|
|||
return 0;
|
||||
publiclen = gcry_sexp_canon_len (public, 0, NULL, NULL);
|
||||
|
||||
get_pk_algo_from_canon_sexp (public, publiclen, &algo);
|
||||
get_pk_algo_from_canon_sexp (public, publiclen, &algostr);
|
||||
xfree (public);
|
||||
|
||||
switch (algo)
|
||||
{
|
||||
case GCRY_PK_RSA: return PUBKEY_ALGO_RSA;
|
||||
case GCRY_PK_DSA: return PUBKEY_ALGO_DSA;
|
||||
case GCRY_PK_ELG_E: return PUBKEY_ALGO_ELGAMAL_E;
|
||||
case GCRY_PK_ECDH: return PUBKEY_ALGO_ECDH;
|
||||
case GCRY_PK_ECDSA: return PUBKEY_ALGO_ECDSA;
|
||||
default: return 0;
|
||||
}
|
||||
/* FIXME: Mapping of ECC algorithms is probably not correct. */
|
||||
if (!algostr)
|
||||
return 0;
|
||||
else if (!strcmp (algostr, "rsa"))
|
||||
return PUBKEY_ALGO_RSA;
|
||||
else if (!strcmp (algostr, "dsa"))
|
||||
return PUBKEY_ALGO_DSA;
|
||||
else if (!strcmp (algostr, "elg"))
|
||||
return PUBKEY_ALGO_ELGAMAL_E;
|
||||
else if (!strcmp (algostr, "ecc"))
|
||||
return PUBKEY_ALGO_ECDH;
|
||||
else if (!strcmp (algostr, "ecdsa"))
|
||||
return PUBKEY_ALGO_ECDSA;
|
||||
else if (!strcmp (algostr, "eddsa"))
|
||||
return PUBKEY_ALGO_EDDSA;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1803,13 +1818,13 @@ ask_algo (ctrl_t ctrl, int addmode, int *r_subkey_algo, unsigned int *r_usage,
|
|||
}
|
||||
|
||||
if (opt.expert && !addmode)
|
||||
tty_printf (_(" (%d) ECDSA and ECDH\n"), 9 );
|
||||
tty_printf (_(" (%d) ECC\n"), 9 );
|
||||
if (opt.expert)
|
||||
tty_printf (_(" (%d) ECDSA (sign only)\n"), 10 );
|
||||
tty_printf (_(" (%d) ECC (sign only)\n"), 10 );
|
||||
if (opt.expert)
|
||||
tty_printf (_(" (%d) ECDSA (set your own capabilities)\n"), 11 );
|
||||
tty_printf (_(" (%d) ECC (set your own capabilities)\n"), 11 );
|
||||
if (opt.expert && addmode)
|
||||
tty_printf (_(" (%d) ECDH (encrypt only)\n"), 12 );
|
||||
tty_printf (_(" (%d) ECC (encrypt only)\n"), 12 );
|
||||
|
||||
if (opt.expert && r_keygrip)
|
||||
tty_printf (_(" (%d) Existing key\n"), 13 );
|
||||
|
@ -1978,6 +1993,12 @@ ask_keysize (int algo, unsigned int primary_keysize)
|
|||
max=521;
|
||||
break;
|
||||
|
||||
case PUBKEY_ALGO_EDDSA:
|
||||
min=255;
|
||||
def=255;
|
||||
max=441;
|
||||
break;
|
||||
|
||||
case PUBKEY_ALGO_RSA:
|
||||
min=1024;
|
||||
break;
|
||||
|
@ -2017,6 +2038,18 @@ ask_keysize (int algo, unsigned int primary_keysize)
|
|||
if (!autocomp)
|
||||
tty_printf (_("rounded up to %u bits\n"), nbits);
|
||||
}
|
||||
else if (algo == PUBKEY_ALGO_EDDSA)
|
||||
{
|
||||
if (nbits != 255 && nbits != 441)
|
||||
{
|
||||
if (nbits < 256)
|
||||
nbits = 255;
|
||||
else
|
||||
nbits = 441;
|
||||
if (!autocomp)
|
||||
tty_printf (_("rounded to %u bits\n"), nbits);
|
||||
}
|
||||
}
|
||||
else if (algo == PUBKEY_ALGO_ECDH || algo == PUBKEY_ALGO_ECDSA)
|
||||
{
|
||||
if (nbits != 256 && nbits != 384 && nbits != 521)
|
||||
|
@ -2613,7 +2646,9 @@ do_create (int algo, unsigned int nbits, const char *curve, KBNODE pub_root,
|
|||
else if (algo == PUBKEY_ALGO_DSA)
|
||||
err = gen_dsa (nbits, pub_root, timestamp, expiredate, is_subkey,
|
||||
keygen_flags, cache_nonce_addr);
|
||||
else if (algo == PUBKEY_ALGO_ECDSA || algo == PUBKEY_ALGO_ECDH)
|
||||
else if (algo == PUBKEY_ALGO_ECDSA
|
||||
|| algo == PUBKEY_ALGO_EDDSA
|
||||
|| algo == PUBKEY_ALGO_ECDH)
|
||||
err = gen_ecc (algo, curve, pub_root, timestamp, expiredate, is_subkey,
|
||||
keygen_flags, cache_nonce_addr);
|
||||
else if (algo == PUBKEY_ALGO_RSA)
|
||||
|
@ -3410,9 +3445,12 @@ generate_keypair (ctrl_t ctrl, const char *fname, const char *card_serialno,
|
|||
sprintf( r->u.value, "%d", algo );
|
||||
r->next = para;
|
||||
para = r;
|
||||
if (algo == PUBKEY_ALGO_ECDSA || algo == PUBKEY_ALGO_ECDH)
|
||||
if (algo == PUBKEY_ALGO_ECDSA
|
||||
|| algo == PUBKEY_ALGO_EDDSA
|
||||
|| algo == PUBKEY_ALGO_ECDH)
|
||||
{
|
||||
curve = ask_curve ();
|
||||
nbits = 0;
|
||||
r = xmalloc_clear (sizeof *r + strlen (curve));
|
||||
r->key = pKEYCURVE;
|
||||
strcpy (r->u.value, curve);
|
||||
|
@ -3467,7 +3505,9 @@ generate_keypair (ctrl_t ctrl, const char *fname, const char *card_serialno,
|
|||
nbits = 0;
|
||||
}
|
||||
|
||||
if (algo == PUBKEY_ALGO_ECDSA || algo == PUBKEY_ALGO_ECDH)
|
||||
if (algo == PUBKEY_ALGO_ECDSA
|
||||
|| algo == PUBKEY_ALGO_EDDSA
|
||||
|| algo == PUBKEY_ALGO_ECDH)
|
||||
{
|
||||
if (!both)
|
||||
curve = ask_curve ();
|
||||
|
@ -3969,7 +4009,9 @@ generate_subkeypair (ctrl_t ctrl, kbnode_t keyblock)
|
|||
|
||||
if (hexgrip)
|
||||
nbits = 0;
|
||||
else if (algo == PUBKEY_ALGO_ECDSA || algo == PUBKEY_ALGO_ECDH)
|
||||
else if (algo == PUBKEY_ALGO_ECDSA
|
||||
|| algo == PUBKEY_ALGO_EDDSA
|
||||
|| algo == PUBKEY_ALGO_ECDH)
|
||||
curve = ask_curve ();
|
||||
else
|
||||
nbits = ask_keysize (algo, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue