mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
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 <wk@gnupg.org>
This commit is contained in:
parent
19f8d53191
commit
2bbdeb8ee8
4 changed files with 34 additions and 83 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue