diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2020-06-09 03:32:47 +0200 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2020-06-09 03:32:47 +0200 |
commit | f5bc94555458123f93d8b07816a68fb7485421e1 (patch) | |
tree | d2e27f1eb0c027721847acc498affb536981e1e1 /g10/export.c | |
parent | gpg: If possible TRUST values now depend on signer's UID or --sender. (diff) | |
download | gnupg2-f5bc94555458123f93d8b07816a68fb7485421e1.tar.xz gnupg2-f5bc94555458123f93d8b07816a68fb7485421e1.zip |
gpg,ecc: Handle external representation as SOS with opaque MPI.
* g10/pkglue.h (sexp_extract_param_sos): New.
* g10/build-packet.c (sos_write): New.
(do_key, do_pubkey_enc, do_signature): Use sos_write for ECC.
* g10/export.c (cleartext_secret_key_to_openpgp): Use
sexp_extract_param_sos.
(transfer_format_to_openpgp): Use opaque MPI for ECC.
* g10/keygen.c (ecckey_from_sexp): Use sexp_extract_param_sos.
* g10/keyid.c (hash_public_key): Handle opaque MPI for SOS.
* g10/parse-packet.c (sos_read): New.
(parse_pubkeyenc,parse_signature,parse_key): Use sos_read for ECC.
* g10/pkglue.c (sexp_extract_param_sos): New.
(pk_verify): Handle opaque MPI for SOS.
(pk_encrypt): Use sexp_extract_param_sos.
* g10/seskey.c (encode_session_key): Use opaque MPI.
* g10/sign.c (do_sign): Use sexp_extract_param_sos.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'g10/export.c')
-rw-r--r-- | g10/export.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/g10/export.c b/g10/export.c index a76a7da84..d06896026 100644 --- a/g10/export.c +++ b/g10/export.c @@ -42,6 +42,7 @@ #include "trustdb.h" #include "call-agent.h" #include "key-clean.h" +#include "pkglue.h" /* An object to keep track of subkeys. */ @@ -750,10 +751,8 @@ cleartext_secret_key_to_openpgp (gcry_sexp_t s_key, PKT_public_key *pk) err = match_curve_skey_pk (key, pk); if (err) goto leave; - if (!err) - err = gcry_sexp_extract_param (key, NULL, "q", - &pub_params[0], - NULL); + else + err = sexp_extract_param_sos (key, "q", &pub_params[0]); if (!err && (gcry_mpi_cmp(pk->pkey[1], pub_params[0]))) err = gpg_error (GPG_ERR_BAD_PUBKEY); @@ -764,9 +763,7 @@ cleartext_secret_key_to_openpgp (gcry_sexp_t s_key, PKT_public_key *pk) { gcry_mpi_release (pk->pkey[sec_start]); pk->pkey[sec_start] = NULL; - err = gcry_sexp_extract_param (key, NULL, "d", - &pk->pkey[sec_start], - NULL); + err = sexp_extract_param_sos (key, "d", &pk->pkey[sec_start]); } if (!err) @@ -978,15 +975,16 @@ transfer_format_to_openpgp (gcry_sexp_t s_pgp, PKT_public_key *pk) value = gcry_sexp_nth_data (list, ++idx, &valuelen); if (!value || !valuelen) goto bad_seckey; - if (is_enc) + if (is_enc + || pk->pubkey_algo == PUBKEY_ALGO_ECDSA + || pk->pubkey_algo == PUBKEY_ALGO_EDDSA + || pk->pubkey_algo == PUBKEY_ALGO_ECDH) { - void *p = xtrymalloc (valuelen); - if (!p) - goto outofmem; - memcpy (p, value, valuelen); - skey[skeyidx] = gcry_mpi_set_opaque (NULL, p, valuelen*8); + skey[skeyidx] = gcry_mpi_set_opaque_copy (NULL, value, valuelen*8); if (!skey[skeyidx]) goto outofmem; + if (is_enc) + gcry_mpi_set_flag (skey[skeyidx], GCRYMPI_FLAG_USER1); } else { @@ -1144,7 +1142,7 @@ transfer_format_to_openpgp (gcry_sexp_t s_pgp, PKT_public_key *pk) /* Check that the first secret key parameter in SKEY is encrypted and that there are no more secret key parameters. The latter is guaranteed by the v4 packet format. */ - if (!gcry_mpi_get_flag (skey[npkey], GCRYMPI_FLAG_OPAQUE)) + if (!gcry_mpi_get_flag (skey[npkey], GCRYMPI_FLAG_USER1)) goto bad_seckey; if (npkey+1 < DIM (skey) && skey[npkey+1]) goto bad_seckey; |