summaryrefslogtreecommitdiff
path: root/cipher/ecc-curves.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2013-10-08 20:51:39 +0200
committerWerner Koch <wk@gnupg.org>2013-10-08 20:51:39 +0200
commit4645f3728bb0900591b0aef85831fdee52c59e3c (patch)
treed0d2a6fc2e05a181f0676bc868d8b2b98dcb3f35 /cipher/ecc-curves.c
parent3816e46ce211e63adf46dbc775510aa137572248 (diff)
downloadlibgcrypt-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-curves.c')
-rw-r--r--cipher/ecc-curves.c27
1 files changed, 16 insertions, 11 deletions
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;
}