pubkey: Move sexp parsing for gcry_pk_sign to the modules.

* cipher/rsa.c (rsa_sign): Revamp.
* cipher/dsa.c (dsa_sign): Revamp.
* cipher/elgamal.c (elg_sign): Revamp.
* cipher/ecc.c (ecc_sign): Revamp.
* cipher/pubkey.c (gcry_pk_sign): Simplify.

Signed-off-by: Werner Koch <wk@gnupg.org>
pubkey: Move sexp parsing for gcry_pk_encrypt to the modules.

* cipher/rsa.c (rsa_encrypt): Revamp.
* cipher/elgamal.c (elg_encrypt): Revamp.
* cipher/ecc.c (ecc_encrypt_raw): Revamp.
* cipher/pubkey.c (gcry_pk_encrypt): Simplify.

* tests/basic.c (check_pubkey_crypt): Init plain, ciph, and data so
that they are initialized even after an encrypt failure.
--

Note that we do not have a regression test for ecc_encrypt_raw.  Thus
it is possible that a bug has been introduced.  Should be tested using
GnuPG master.

Signed-off-by: Werner Koch <wk@gnupg.org>
pubkey: Move sexp parsing for gcry_pk_decrypt to the modules.

* cipher/rsa.c (rsa_decrypt): Revamp.
* cipher/elgamal.c (elg_decrypt): Revamp.
* cipher/ecc.c (ecc_decrypt_raw): Revamp.
* cipher/pubkey.c (gcry_pk_decrypt): Simplify.
(sexp_to_enc): Remove.
* cipher/pubkey-util.c (_gcry_pk_util_preparse_encval): New.
--

Note that we do not have a regression test for ecc_decrypt_raw.  Even
GnuPG does not use it.  we also better check whether the interface is
really usable; for example GnuPG implements way to much low-level ECC
code.  Maybe we should move the OpenPGP ECC encryption code into
Libgcrypt.

Signed-off-by: Werner Koch <wk@gnupg.org>
pubkey: Move sexp parsing of remaining fucntions to the modules.

* cipher/pubkey.c (release_mpi_array): Remove.
(pubkey_check_secret_key): Remove.
(sexp_elements_extract): Remove.
(sexp_elements_extract_ecc): Remove.
(sexp_to_key): Remove.
(get_hash_algo): Remove.
(gcry_pk_testkey): Revamp.
(gcry_pk_get_curve): Revamp.
* cipher/rsa.c (rsa_check_secret_key): Revamp.
* cipher/elgamal.c (elg_check_secret_key): Revamp.
* cipher/dsa.c (dsa_check_secret_key): Revamp.
* cipher/ecc.c (ecc_check_secret_key): Revamp.
* cipher/ecc-curves.c: Include cipher.h and pubkey-internal.h
(_gcry_ecc_get_curve): Revamp.

* cipher/pubkey-util.c (_gcry_pk_util_extract_mpis): Set passed and
used parameters on error to NULL.
--

That is the final part of the changes modulo introduced regressions.
pubkey.c is now actually maintainable code.

Signed-off-by: Werner Koch <wk@gnupg.org>