diff options
author | NIIBE Yutaka <[email protected]> | 2024-04-26 05:18:03 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2024-04-26 05:18:03 +0000 |
commit | 9128d81bb7b92660c896965d0b6b1b1a1622d3e6 (patch) | |
tree | c55cdc61d759e73470342f1e08bde0850325f4e7 /common/sexputil.c | |
parent | speedo: Use gpg-authcode-sign.sh and change archive label to v2.5. (diff) | |
download | gnupg-9128d81bb7b92660c896965d0b6b1b1a1622d3e6.tar.gz gnupg-9128d81bb7b92660c896965d0b6b1b1a1622d3e6.zip |
agent:kem:ecc: Support a key on smartcard.
* agent/agent.h (agent_card_ecc_kem): New.
* agent/divert-scd.c (agent_card_ecc_kem): New.
* agent/pkdecrypt.c (ecc_extract_pk_from_key): New.
(ecc_extract_sk_from_key): New.
(ecc_raw_kem, get_cardkey, ecc_get_curve): New.
(ecc_pgp_kem_decrypt): Support a key on smartcard for ECC.
(composite_pgp_kem_decrypt): Handle a case of a key on smartcard.
* common/sexputil.c (get_ecc_curve_from_key): New.
* common/util.h (get_ecc_curve_from_key): New.
--
GnuPG-bug-id: 7097
Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'common/sexputil.c')
-rw-r--r-- | common/sexputil.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/common/sexputil.c b/common/sexputil.c index e6fc84da0..15fd7cf1d 100644 --- a/common/sexputil.c +++ b/common/sexputil.c @@ -1194,3 +1194,47 @@ cipher_mode_to_string (int mode) default: return "[?]"; } } + +/* Return the cannonical name of the ECC curve in KEY. */ +const char * +get_ecc_curve_from_key (gcry_sexp_t key) +{ + gcry_sexp_t list = NULL; + gcry_sexp_t l2 = NULL; + const char *curve_name = NULL; + char *name = NULL; + + /* Check that the first element is valid. */ + list = gcry_sexp_find_token (key, "public-key", 0); + if (!list) + list = gcry_sexp_find_token (key, "private-key", 0); + if (!list) + list = gcry_sexp_find_token (key, "protected-private-key", 0); + if (!list) + list = gcry_sexp_find_token (key, "shadowed-private-key", 0); + if (!list) + goto leave; + + l2 = gcry_sexp_cadr (list); + gcry_sexp_release (list); + list = l2; + l2 = NULL; + + name = gcry_sexp_nth_string (list, 0); + if (!name) + goto leave; + + if (gcry_pk_map_name (name) != GCRY_PK_ECC) + goto leave; + + l2 = gcry_sexp_find_token (list, "curve", 0); + xfree (name); + name = gcry_sexp_nth_string (l2, 1); + curve_name = openpgp_oid_or_name_to_curve (name, 1); + gcry_sexp_release (l2); + + leave: + xfree (name); + gcry_sexp_release (list); + return curve_name; +} |