Provide Pth compatiblity for use with GnuPG 2.0.

* src/ath.c (ath_install): Call ath_init and declare Pth as
compatible.
--

GnuPG 2.0 requires GNU Pth which is a plain userland thread
implementation.  Given that decent versions of GNU Pth seem to work
together with pthread, we can declare Pth as compatible.  Native
pthreads in Libgcrypt are only used internal to Libgcrypt and any
internal blocking should be invisible to Pth.

Signed-off-by: Werner Koch <wk@gnupg.org>
doc: Remove note that RC2/128 is not yet supported.

--
doc: Type fix.

--
ecc: Add OID for Ed25519.

--

See:

  From: Peter Gutmann <pgut001@cs.auckland.ac.nz>
  Subject: Re: [cryptography] Curve25519 OID (was: Re: the spell is broken)
  To: xxxxxxxxxxxxx
  Cc: cryptography@randombit.net
  Message-Id: <E1VSk4L-0004JD-AI@login01.fos.auckland.ac.nz>
  Date: Sun, 06 Oct 2013 21:52:05 +1300

  xxxxxxxxxxxxxxx writes:

  >For completeness, Crypto++ has a factory-like method that serves curves. The
  >curves are sorted by OID in the function, so Crypto++ would need an OID for
  >ed25519.

    { 1 3 6 1 4 1 3029 1 5 1 } ed209^H^H5519

  You have been OIDed.  Go forth and encrypt.

  Peter.
cipher: Deprecate GCRY_PK_ELG_E.

* cipher/elgamal.c (_gcry_pubkey_spec_elg_e): Remove.
* cipher/pubkey.c (pubkey_list): Remove double included
_gcry_pubkey_spec_elg.
(map_algo): MAke ELG_E to ELG.
--

It does not make sense to have different algorithm identifiers for
Elgamal encryption and the obsolete Elgamal signing.  Thus mark one of
them as deprecated and remove the useless extra spec info in
elgamal.c.  Frankly it is questionable why at all we need the
algorithm identifiers; they are a remain from the time when Libgcrypt
was part of GnuPG.  With the s-expression based API the IDs they don't
make much sense.

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

* cipher/pubkey-util.c: New.
(_gcry_pk_util_get_nbits): New.  Based on code from gcry_pk_genkey.
(_gcry_pk_util_get_rsa_use_e): Ditto.
* cipher/pubkey.c (gcry_pk_genkey): Strip most code and pass.
* cipher/rsa.c (rsa_generate): Remove args ALGO, NBITS and EVALUE.
Call new fucntions to get these values.
* cipher/dsa.c (dsa_generate): Remove args ALGO, NBITS and EVALUE.
Call _gcry_pk_util_get_nbits to get nbits.  Always parse genparms.
* cipher/elgamal.c (elg_generate): Ditto.
* cipher/ecc.c (ecc_generate): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
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>
pubkey: Move sexp parsing for gcry_pk_verify to the modules.

* cipher/rsa.c (rsa_verify): Revamp.
* cipher/dsa.c (dsa_verify): Revamp.
* cipher/elgamal.c (elg_verify): Revamp.
* cipher/ecc.c (ecc_verify): Revamp.
* cipher/pubkey.c (sexp_to_sig): Remove.
(pss_verify_cmp): Move to pubkey-util.c
(sexp_data_to_mpi): Ditto.
(init_encoding_ctx): Ditto.
(gcry_pk_verify): Simplify.
* cipher/pubkey-util.c (_gcry_pk_util_init_encoding_ctx): Add. Take
from pubkey.c
(get_hash_algo): Ditto.
(_gcry_pk_util_data_to_mpi): Ditto.
(pss_verify_cmp): Ditto.
(_gcry_pk_util_extract_mpis): New.
(_gcry_pk_util_preparse_sigval): New.
(_gcry_pk_util_free_encoding_ctx): New.
* cipher/ecc-curves.c (_gcry_ecc_fill_in_curve): Make curve init
optional.

* src/g10lib.h (GCC_ATTR_SENTINEL): New.

* tests/basic.c (check_pubkey_sign): Print the algo name.
(main): Add option --pubkey.

Signed-off-by: Werner Koch <wk@gnupg.org>
Prevent tail call optimization with _gcry_burn_stack

* configure.ac: New check, HAVE_GCC_ASM_VOLATILE_MEMORY.
* src/g10lib.h (_gcry_burn_stack): Rename to __gcry_burn_stack.
(__gcry_burn_stack_dummy): New.
(_gcry_burn_stack): New macro.
* src/misc.c (_gcry_burn_stack): Rename to __gcry_burn_stack.
(__gcry_burn_stack_dummy): New.
--

Tail call optimization can turn _gcry_burn_stack call in to tail jump. When
this happens, stack pointer is restored to initial state of current function.
This causes problem for _gcry_burn_stack because its callers do not count in
current function stack depth.

One solution is to prevent gcry_burn_stack being tail optimized by inserting
dummy function call behind it. Another would be to add memory barrier 'asm
volatile("":::"memory")' behind every _gcry_burn_stack call. This however
requires GCC asm support from compiler.

Patch adds detection for memory barrier support and when available uses
memory barrier to prevent when tail call optimization. If not available
dummy function call is used instead.

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
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>
mpicalc: Accept lowercase hex digits.

* src/mpicalc.c (main): Test for lowercase hex digits.
--

This change is useful so to make use of Libgcrypt debug code easier.
pubkey: Remove duplicated flag parsing code.

* cipher/pubkey-util.c (_gcry_pk_util_preparse_encval)
(_gcry_pk_util_data_to_mpi): Factor flag parsing code out to ..
(parse_flag_list): New.
* src/cipher.h (PUBKEY_FLAG_RAW_FLAG): New.
--

A minor disadvantage of that code is that invalid flags are not
anymore detected depending on the use.  According to the documentation
this is anyway the expected behavior.

Signed-off-by: Werner Koch <wk@gnupg.org>
pubkey: Support flags list in gcry_pk_genkey.

* src/cipher.h (PUBKEY_FLAG_TRANSIENT_KEY): New.
(PUBKEY_FLAG_USE_X931): New.
(PUBKEY_FLAG_USE_FIPS186): New.
(PUBKEY_FLAG_USE_FIPS186_2): New.
* cipher/pubkey-util.c (_gcry_pk_util_parse_flaglist): Rename from
parse_flags_list.  Parse new flags.
* cipher/dsa.c (dsa_generate): Support flag list.
* cipher/ecc.c (ecc_generate): Ditto.
* cipher/rsa.c (rsa_generate): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
ecc:  Support use of Ed25519 with ECDSA.

* src/cipher.h (PUBKEY_FLAG_ECDSA): New.
* cipher/pubkey-util.c (_gcry_pk_util_parse_flaglist): Add flag "ecdsa".
* cipher/ecc.c (verify_ecdsa, verify_eddsa): Remove some debug output.
(ecc_generate, ecc_sign, ecc_verify): Support Ed25519 with ECDSA.
* tests/keygen.c (check_ecc_keys): Create such a test key.
* tests/pubkey.c (fail, info, data_from_hex, extract_cmp_data): New.
Take from dsa-6979.c
(check_ed25519ecdsa_sample_key): new.
(main): Call new test.

Signed-off-by: Werner Koch <wk@gnupg.org>
Drop automake-installed files

Drop files that are provided by automake. They are better to be in sync
with automake used.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Update .gitingore to ignore more files

* .gitignore: add more tests, temporary files, etc to the list of
ignored files.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Drop _gcry_cipher_ofb_decrypt as it duplicates _gcry_cipher_ofb_encrypt

* cipher/cipher.c (cipher_decrypt): Use _gcry_cipher_ofb_encrypt for OFB
  decryption.
* cipher/cipher-internal.h: Remove _gcry_cipher_ofb_decrypt declaration.
* cipher/cipher.c: Delete _gcry_cipher_ofb_decrypt().

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>