diff options
Diffstat (limited to 'cipher/pubkey.c')
-rw-r--r-- | cipher/pubkey.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/cipher/pubkey.c b/cipher/pubkey.c index 60aabdd1..2d975e81 100644 --- a/cipher/pubkey.c +++ b/cipher/pubkey.c @@ -467,7 +467,8 @@ pubkey_get_nenc (int algorithm) static gcry_err_code_t -pubkey_generate (int algorithm, unsigned int nbits, unsigned long use_e, +pubkey_generate (int algorithm, unsigned int nbits, unsigned int qbits, + unsigned long use_e, gcry_mpi_t *skey, gcry_mpi_t **retfactors) { gcry_err_code_t err = GPG_ERR_PUBKEY_ALGO; @@ -479,8 +480,13 @@ pubkey_generate (int algorithm, unsigned int nbits, unsigned long use_e, pubkey = _gcry_module_lookup_id (pubkeys_registered, algorithm); if (pubkey) { - err = ((gcry_pk_spec_t *) pubkey->spec)->generate - (algorithm, nbits, use_e, skey, retfactors); + /* Hack to pass QBITS to the DSA generation. */ + if (qbits && pubkey->spec == &_gcry_pubkey_spec_dsa) + err = _gcry_dsa_generate2 + (algorithm, nbits, qbits, 0, skey, retfactors); + else + err = ((gcry_pk_spec_t *) pubkey->spec)->generate + (algorithm, nbits, use_e, skey, retfactors); _gcry_module_release (pubkey); } ath_mutex_unlock (&pubkeys_registered_lock); @@ -1862,6 +1868,7 @@ gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms) gcry_mpi_t skey[10], *factors = NULL; unsigned int nbits = 0; unsigned long use_e = 0; + unsigned int qbits; char *name_terminated; REGISTER_DEFAULT_PUBKEYS; @@ -1941,6 +1948,28 @@ gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms) else use_e = 65537; /* Not given, use the value generated by old versions. */ + /* Handle the optional qbits element. */ + l2 = gcry_sexp_find_token (list, "qbits", 0); + if (l2) + { + char buf[50]; + + name = gcry_sexp_nth_data (l2, 1, &n); + if ((! name) || (n >= DIM (buf) - 1)) + { + rc = GPG_ERR_INV_OBJ; /* No value or value too large. */ + goto leave; + } + memcpy (buf, name, n); + buf[n] = 0; + qbits = (unsigned int)strtoul (buf, NULL, 0); + gcry_sexp_release (l2); + l2 = NULL; + } + else + qbits = 0; + + /* Now parse the required nbits element. */ l2 = gcry_sexp_find_token (list, "nbits", 0); gcry_sexp_release (list); list = l2; @@ -1970,7 +1999,7 @@ gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms) nbits = (unsigned int) strtoul (name_terminated, NULL, 0); gcry_free (name_terminated); - rc = pubkey_generate (module->mod_id, nbits, use_e, skey, &factors); + rc = pubkey_generate (module->mod_id, nbits, qbits, use_e, skey, &factors); if (rc) goto leave; |