diff options
author | Werner Koch <wk@gnupg.org> | 2013-10-08 17:59:50 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2013-10-08 17:59:50 +0200 |
commit | 3816e46ce211e63adf46dbc775510aa137572248 (patch) | |
tree | 7a4e51d84d2e0f83803f5865b58c8135f4a1ca5e /cipher/pubkey.c | |
parent | f79d3e13d3229115c47cbe5007647cb44105fe3f (diff) | |
download | libgcrypt-3816e46ce211e63adf46dbc775510aa137572248.tar.gz |
pubkey: Move sexp parsing for gcry_pk_getkey to the modules.
* cipher/pubkey-util.c: New.
(_gcry_pk_util_get_nbits): New. Based on code from gcry_pk_genkey.
(_gcry_pk_util_get_rsa_use_e): Ditto.
* cipher/pubkey.c (gcry_pk_genkey): Strip most code and pass.
* cipher/rsa.c (rsa_generate): Remove args ALGO, NBITS and EVALUE.
Call new fucntions to get these values.
* cipher/dsa.c (dsa_generate): Remove args ALGO, NBITS and EVALUE.
Call _gcry_pk_util_get_nbits to get nbits. Always parse genparms.
* cipher/elgamal.c (elg_generate): Ditto.
* cipher/ecc.c (ecc_generate): Ditto.
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'cipher/pubkey.c')
-rw-r--r-- | cipher/pubkey.c | 58 |
1 files changed, 3 insertions, 55 deletions
diff --git a/cipher/pubkey.c b/cipher/pubkey.c index 50ce6382..305f53a4 100644 --- a/cipher/pubkey.c +++ b/cipher/pubkey.c @@ -1862,12 +1862,8 @@ gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms) gcry_pk_spec_t *spec = NULL; gcry_sexp_t list = NULL; gcry_sexp_t l2 = NULL; - gcry_sexp_t l3 = NULL; char *name = NULL; - size_t n; - gcry_err_code_t rc = GPG_ERR_NO_ERROR; - unsigned int nbits = 0; - unsigned long use_e = 0; + gcry_err_code_t rc; *r_key = NULL; @@ -1904,63 +1900,15 @@ gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms) goto leave; } - /* Handle the optional rsa-use-e element. Actually this belong into - the algorithm module but we have this parameter in the public - module API, so we need to parse it right here. */ - l2 = gcry_sexp_find_token (list, "rsa-use-e", 0); - if (l2) - { - char buf[50]; - const char *s; - - s = gcry_sexp_nth_data (l2, 1, &n); - if ( !s || n >= DIM (buf) - 1 ) - { - rc = GPG_ERR_INV_OBJ; /* No value or value too large. */ - goto leave; - } - memcpy (buf, s, n); - buf[n] = 0; - use_e = strtoul (buf, NULL, 0); - gcry_sexp_release (l2); - l2 = NULL; - } - else - use_e = 65537; /* Not given, use the value generated by old versions. */ - - - /* Get the "nbits" parameter. */ - l2 = gcry_sexp_find_token (list, "nbits", 0); - if (l2) - { - char buf[50]; - const char *s; - - s = gcry_sexp_nth_data (l2, 1, &n); - if (!s || n >= DIM (buf) - 1 ) - { - rc = GPG_ERR_INV_OBJ; /* NBITS given without a cdr. */ - goto leave; - } - memcpy (buf, s, n); - buf[n] = 0; - nbits = (unsigned int)strtoul (buf, NULL, 0); - gcry_sexp_release (l2); l2 = NULL; - } - else - nbits = 0; - if (spec->generate) - rc = spec->generate (spec->algo, nbits, use_e, list, r_key); + rc = spec->generate (list, r_key); else rc = GPG_ERR_NOT_IMPLEMENTED; leave: - gcry_sexp_release (list); list = NULL; + gcry_sexp_release (list); gcry_free (name); - gcry_sexp_release (l3); gcry_sexp_release (l2); - gcry_sexp_release (list); return gcry_error (rc); } |