diff options
author | Werner Koch <[email protected]> | 2017-03-01 12:36:01 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2017-03-01 12:36:01 +0000 |
commit | 2bbdeb8ee87a6c7ec211be16391a11b7c6030bed (patch) | |
tree | b00d826be8111cd5ec1786bd88debf29b8867db6 /common/sexputil.c | |
parent | speedo,w32: Install sks-keyservers.netCA.pem. (diff) | |
download | gnupg-2bbdeb8ee87a6c7ec211be16391a11b7c6030bed.tar.gz gnupg-2bbdeb8ee87a6c7ec211be16391a11b7c6030bed.zip |
gpg: Allow creating keys using an existing ECC key.
* common/sexputil.c (get_pk_algo_from_canon_sexp): Remove arg R_ALGO.
Change to return the algo id. Reimplement using get_pk_algo_from_key.
* g10/keygen.c (check_keygrip): Adjust for change.
* sm/certreqgen-ui.c (check_keygrip): Ditto.
--
GnuPG-bug-id: 2976
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/sexputil.c')
-rw-r--r-- | common/sexputil.c | 65 |
1 files changed, 18 insertions, 47 deletions
diff --git a/common/sexputil.c b/common/sexputil.c index 0c5c730ac..a8dc1a58c 100644 --- a/common/sexputil.c +++ b/common/sexputil.c @@ -512,53 +512,6 @@ get_rsa_pk_from_canon_sexp (const unsigned char *keydata, size_t keydatalen, } -/* Return the algo of a public RSA expressed as an canonical encoded - S-expression. The return value is a statically allocated - string. On error that string is set to NULL. */ -gpg_error_t -get_pk_algo_from_canon_sexp (const unsigned char *keydata, size_t keydatalen, - const char **r_algo) -{ - gpg_error_t err; - const unsigned char *buf, *tok; - size_t buflen, toklen; - int depth; - - *r_algo = NULL; - - buf = keydata; - buflen = keydatalen; - depth = 0; - if ((err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen))) - return err; - if ((err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen))) - return err; - if (!tok || toklen != 10 || memcmp ("public-key", tok, toklen)) - return gpg_error (GPG_ERR_BAD_PUBKEY); - if ((err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen))) - return err; - if ((err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen))) - return err; - if (!tok) - return gpg_error (GPG_ERR_BAD_PUBKEY); - - if (toklen == 3 && !memcmp ("rsa", tok, toklen)) - *r_algo = "rsa"; - else if (toklen == 3 && !memcmp ("dsa", tok, toklen)) - *r_algo = "dsa"; - else if (toklen == 3 && !memcmp ("elg", tok, toklen)) - *r_algo = "elg"; - else if (toklen == 5 && !memcmp ("ecdsa", tok, toklen)) - *r_algo = "ecdsa"; - else if (toklen == 5 && !memcmp ("eddsa", tok, toklen)) - *r_algo = "eddsa"; - else - return gpg_error (GPG_ERR_PUBKEY_ALGO); - - return 0; -} - - /* Return the algo of a public KEY of SEXP. */ int get_pk_algo_from_key (gcry_sexp_t key) @@ -606,3 +559,21 @@ get_pk_algo_from_key (gcry_sexp_t key) return algo; } + + +/* This is a variant of get_pk_algo_from_key but takes an canonical + * encoded S-expression as input. Returns a GCRYPT public key + * identiier or 0 on error. */ +int +get_pk_algo_from_canon_sexp (const unsigned char *keydata, size_t keydatalen) +{ + gcry_sexp_t sexp; + int algo; + + if (gcry_sexp_sscan (&sexp, NULL, keydata, keydatalen)) + return 0; + + algo = get_pk_algo_from_key (sexp); + gcry_sexp_release (sexp); + return algo; +} |