From 4645f3728bb0900591b0aef85831fdee52c59e3c Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 8 Oct 2013 20:51:39 +0200 Subject: 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 --- cipher/ecc-curves.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'cipher/ecc-curves.c') diff --git a/cipher/ecc-curves.c b/cipher/ecc-curves.c index 9731debf..449a168e 100644 --- a/cipher/ecc-curves.c +++ b/cipher/ecc-curves.c @@ -306,7 +306,9 @@ scanval (const char *string) /* Generate the crypto system setup. This function takes the NAME of a curve or the desired number of bits and stores at R_CURVE the parameters of the named curve or those of a suitable curve. If - R_NBITS is not NULL, the chosen number of bits is stored there. */ + R_NBITS is not NULL, the chosen number of bits is stored there. + NULL may be given for R_CURVE, if the value is not required and for + example only a quick test for availability is desired. */ gpg_err_code_t _gcry_ecc_fill_in_curve (unsigned int nbits, const char *name, elliptic_curve_t *curve, unsigned int *r_nbits) @@ -372,16 +374,19 @@ _gcry_ecc_fill_in_curve (unsigned int nbits, const char *name, if (r_nbits) *r_nbits = domain_parms[idx].nbits; - curve->model = domain_parms[idx].model; - curve->dialect = domain_parms[idx].dialect; - curve->p = scanval (domain_parms[idx].p); - curve->a = scanval (domain_parms[idx].a); - curve->b = scanval (domain_parms[idx].b); - curve->n = scanval (domain_parms[idx].n); - curve->G.x = scanval (domain_parms[idx].g_x); - curve->G.y = scanval (domain_parms[idx].g_y); - curve->G.z = mpi_alloc_set_ui (1); - curve->name = resname; + if (curve) + { + curve->model = domain_parms[idx].model; + curve->dialect = domain_parms[idx].dialect; + curve->p = scanval (domain_parms[idx].p); + curve->a = scanval (domain_parms[idx].a); + curve->b = scanval (domain_parms[idx].b); + curve->n = scanval (domain_parms[idx].n); + curve->G.x = scanval (domain_parms[idx].g_x); + curve->G.y = scanval (domain_parms[idx].g_y); + curve->G.z = mpi_alloc_set_ui (1); + curve->name = resname; + } return 0; } -- cgit v1.2.1