Move all helper scripts to build-aux/

* scripts/: Rename to build-aux/.
* compile, config.guess, config.rpath, config.sub
* depcomp, doc/mdate-sh, doc/texinfo.tex
* install-sh, ltmain.sh, missing: Move to build-aux/.
* Makefile.am (EXTRA_DIST): Adjust.
* configure.ac (AC_CONFIG_AUX_DIR): New.
(AM_SILENT_RULES): New.

Signed-off-by: Werner Koch <wk@gnupg.org>
(cherry picked from commit df9b4eabf52faee6f289a4bc62219684442ae383)
Use the generic autogen.sh script.

* autogen.rc: New.
* Makefile.am (EXTRA_DIST): Add it.
* autogen.sh: Update from current GnuPG.

Signed-off-by: Werner Koch <wk@gnupg.org>
(cherry picked from commit b0ac1f9b143aa15855914ba93fef900288d45c9c)
Fix buggy/incomplete detection of AVX/AVX2 support

* configure.ac: Also check for 'xgetbv' instruction in AVX and AVX2
inline assembly checks.
* src/hwf-x86.c [__i386__] (get_xgetbv): New function.
[__x86_64__] (get_xgetbv): New function.
[HAS_X86_CPUID] (detect_x86_gnuc): Check for OSXSAVE and OS support for
XMM&YMM registers and enable AVX/AVX2 only if XMM&YMM registers are
supported by OS.
--

This patch is based on original patch and bug report by Panagiotis Christopoulos:

  Adding better detection of AVX/AVX2 support

  After upgrading libgcrypt from 1.5.3 to 1.6.0 on a remote XEN system (linode) my
  gpg2 stopped working properly, throwing SIGILL signals when doing sha512
  operations etc. I managed to debug this with the help of Doublas Freed
  (dwfreed at mtu.edu) and it seems that the current AVX detection just checks for
  bit 28 on cpuid but the check still works  on systems that have disabled the avx/avx2
  instructions for some reason (eg. performance/unstability) resulting in SIGILLs
  (eg. when trying _gcry_sha512_transform_amd64_avx() ).
  From Intel resources[1][2], I found additional checks for better AVX
  detection and applied them in the following patch. Please review/change
  accordingly and commit some better AVX detection mechanism. The AVX part is
  tested but could not test the AVX2 one, because I lack proper hardware. I can
  provide additional information upon request. Use the patch only as a guideline,
  as it's not thoroughly tested.

  [1] http://software.intel.com/en-us/blogs/2011/04/14/is-avx-enabled
  [2] http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-manual-325462.pdf (sections 14.3 and 14.7.1)

Reported-by: Panagiotis Christopoulos (pchrist) <pchrist@gentoo.org>
Cc: Doublas Freed <dwfreed@mtu.edu>
Cc: Tim Harder <radhermit@gentoo.org>
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
(cherry picked from commit bbcb12187afb1756cb27296166b57fa19ee45d4d)
* cipher/Makefile.am: Add 'blowfish-arm.S' and 'serpent-armv7-neon.S'.
--

Fix for bug https://bugs.g10code.com/gnupg/issue1584

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
(cherry picked from commit 7fef7f481c0a1542be34d1dc831f58d41846ac29)
Correct formatting of gcry_mac_get_algo_keylen documentation

* doc/gcrypt.texi: add braces near gcry_mac_get_algo_keylen
  documentation.

Use braces around unsigned int in gcry_mac_get_algo_keylen
documentation, otherwise texinfo breaks that and uses 'int' as a
function definition.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Fix typo in search_oid

* cipher/md.c (search_oid): Invert condition on oid comparison.

--
Function stricmp() returns 0 in case strings match, so proper condition
that checks for matching OID strings should be if (!stricmp(...))

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Fix macro conflict in NetBSD

* cipher/bithelp.h (bswap32): Rename to _gcry_bswap32.
(bswap64): Rename to _gcry_bswap64.
--

NetBSD provides system macros bswap32 and bswap64 which conflicts with
our macros.  Prefixing them with _gcry_ is easier than to come up with
a proper test.

GnuPG-bug-id: 1600
Signed-off-by: Werner Koch <wk@gnupg.org>
Update NEWS.

--
PBKDF2: Use gcry_md_reset to speed up calculation.

* cipher/kdf.c (_gcry_kdf_pkdf2): Use gcry_md_reset
to speed up calculation.
--

Current PBKDF2 implementation uses gcry_md_set_key in every iteration
which is extremely slow (even in comparison with other implementations).

Use gcry_md_reset instead and set key only once.

With this test program:

  char input[32000], salt[8], key[16];
  gcry_kdf_derive(input, sizeof(input), GCRY_KDF_PBKDF2,
                  gcry_md_map_name("sha1"),
                  salt, sizeof(salt), 100000, sizeof(key), key);

running time without patch:
  real    0m11.165s
  user    0m11.136s
  sys     0m0.000s

and with patch applied
  real    0m0.230s
  user    0m0.184s
  sys     0m0.024s

(The problem was found when cryptsetup started to use gcrypt internal PBKDF2
and for very long keyfiles unlocking time increased drastically.
See https://bugzilla.redhat.com/show_bug.cgi?id=1051733)

Signed-off-by: Milan Broz <gmazyland@gmail.com>
(cherry picked from commit 04cda6b7cc16f3f52c12d9d3e46c56701003496e)
md: Add Whirlpool bug emulation feature.

* src/gcrypt.h.in (GCRY_MD_FLAG_BUGEMU1): New.
* src/cipher-proto.h (gcry_md_init_t): Add arg FLAGS.  Change all code
to implement that flag.
* cipher/md.c (gcry_md_context):  Replace SECURE and FINALIZED by bit
field FLAGS.  Add flag BUGEMU1.  Change all users.
(md_open): Replace args SECURE and HMAC by FLAGS.  Init flags.bugemu1.
(_gcry_md_open): Add for GCRY_MD_FLAG_BUGEMU1.
(md_enable): Pass bugemu1 flag to the hash init function.
(_gcry_md_reset): Ditto.
--

This problem is for example exhibited in the Linux cryptsetup tool.
See https://bbs.archlinux.org/viewtopic.php?id=175737 .  It has
been tracked down by Milan Broz.

The suggested way of using the flag is:

  if (whirlpool_bug_assumed)
    {
#if GCRYPT_VERSION_NUMBER >= 0x010601
      err = gcry_md_open (&hd, GCRY_MD_WHIRLPOOL, GCRY_MD_FLAG_BUGEMU1)
      if (gpg_err_code (err) == GPG_ERR_INV_ARG)
         error ("Need at least Libggcrypt 1.6.1 for the fix");
      else
         {
            do_hash (hd);
            gcry_md_close (hd);
          }
#endif
    }

Signed-off-by: Werner Koch <wk@gnupg.org>
(cherry picked from commit 94030e44aaff805d754e368507f16dd51a531b72)

Reolved conflicts:
	NEWS
	cipher/whirlpool.c: Remove NBLOCKS arg from whirlpool_transform.
cipher: Fix commit 77f28793

* cipher/tiger.c (tiger_init): Add arg FLAGS.
(tiger1_init, tiger2_init): Ditto.

(cherry picked from commit dad06e4d1b835bac778b87090b1d3894b7535b14)