diff options
author | Werner Koch <wk@gnupg.org> | 2013-10-08 20:51:39 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2013-10-08 20:51:39 +0200 |
commit | 4645f3728bb0900591b0aef85831fdee52c59e3c (patch) | |
tree | d0d2a6fc2e05a181f0676bc868d8b2b98dcb3f35 /cipher/ecc.c | |
parent | 3816e46ce211e63adf46dbc775510aa137572248 (diff) | |
download | libgcrypt-4645f3728bb0900591b0aef85831fdee52c59e3c.tar.gz |
pubkey: Move sexp parsing for gcry_pk_get_nbits to the modules.
* cipher/pubkey.c (spec_from_sexp): New.
(gcry_pk_get_nbits): Simplify.
* cipher/rsa.c (rsa_get_nbits): Take only PARMS as args and do sexp
parsing here.
* cipher/dsa.c (dsa_get_nbits): Ditto.
* cipher/elgamal.c (elg_get_nbits): Ditto.
* cipher/ecc.c (ecc_get_nbits): Ditto.
* cipher/ecc-curves.c (_gcry_ecc_fill_in_curve): Allow NULL for arg
CURVE.
--
gcry_pk_get_nbits should now also be faster for ECC because there is
no more need to copy all the parms if a curve name has been given.
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'cipher/ecc.c')
-rw-r--r-- | cipher/ecc.c | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/cipher/ecc.c b/cipher/ecc.c index eed96eb8..e3d397a6 100644 --- a/cipher/ecc.c +++ b/cipher/ecc.c @@ -1836,12 +1836,56 @@ ecc_decrypt_raw (int algo, gcry_sexp_t *r_plain, gcry_mpi_t *data, } +/* Return the number of bits for the key described by PARMS. On error + * 0 is returned. The format of PARMS starts with the algorithm name; + * for example: + * + * (ecc + * (p <mpi>) + * (a <mpi>) + * (b <mpi>) + * (g <mpi>) + * (n <mpi>) + * (q <mpi>)) + * + * More parameters may be given currently P is needed. FIXME: We + * need allow for a "curve" parameter. + */ static unsigned int -ecc_get_nbits (int algo, gcry_mpi_t *pkey) +ecc_get_nbits (gcry_sexp_t parms) { - (void)algo; + gcry_sexp_t l1; + gcry_mpi_t p; + unsigned int nbits = 0; + char *curve; + + l1 = gcry_sexp_find_token (parms, "p", 1); + if (!l1) + { /* Parameter P not found - check whether we have "curve". */ + l1 = gcry_sexp_find_token (parms, "curve", 5); + if (!l1) + return 0; /* Neither P nor CURVE found. */ + + curve = _gcry_sexp_nth_string (l1, 1); + gcry_sexp_release (l1); + if (!curve) + return 0; /* No curve name given (or out of core). */ - return mpi_get_nbits (pkey[0]); + if (_gcry_ecc_fill_in_curve (0, curve, NULL, &nbits)) + nbits = 0; + gcry_free (curve); + } + else + { + p = gcry_sexp_nth_mpi (l1, 1, GCRYMPI_FMT_USG); + gcry_sexp_release (l1); + if (p) + { + nbits = mpi_get_nbits (p); + gcry_mpi_release (p); + } + } + return nbits; } |