summaryrefslogtreecommitdiff
path: root/cipher/dsa.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/dsa.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/dsa.c')
-rw-r--r--cipher/dsa.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/cipher/dsa.c b/cipher/dsa.c
index 136d64f4..d319f732 100644
--- a/cipher/dsa.c
+++ b/cipher/dsa.c
@@ -1029,12 +1029,34 @@ dsa_verify (int algo, gcry_mpi_t hash, gcry_mpi_t *data, gcry_mpi_t *pkey,
}
+/* 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:
+ *
+ * (dsa
+ * (p <mpi>)
+ * (q <mpi>)
+ * (g <mpi>)
+ * (y <mpi>))
+ *
+ * More parameters may be given but we only need P here.
+ */
static unsigned int
-dsa_get_nbits (int algo, gcry_mpi_t *pkey)
+dsa_get_nbits (gcry_sexp_t parms)
{
- (void)algo;
+ gcry_sexp_t l1;
+ gcry_mpi_t p;
+ unsigned int nbits;
+
+ l1 = gcry_sexp_find_token (parms, "p", 1);
+ if (!l1)
+ return 0; /* Parameter P not found. */
- return mpi_get_nbits (pkey[0]);
+ p = gcry_sexp_nth_mpi (l1, 1, GCRYMPI_FMT_USG);
+ gcry_sexp_release (l1);
+ nbits = p? mpi_get_nbits (p) : 0;
+ gcry_mpi_release (p);
+ return nbits;
}