libgcrypt.git
22 months agoAdd crypto hash SM3.
Jia Zhang [Tue, 24 Oct 2017 06:55:12 +0000 (15:55 +0900)]
Add crypto hash SM3.

* configure.ac (available_digests): Add sm3.
* src/cipher.h: Add declarations for SM3.
* cipher/Makefile.am (EXTRA_libcipher_la_SOURCES): Add sm3.c.
* cipher/md.c [USE_SM3] (digest_list): Add _gcry_digest_spec_sm3.
* cipher/pubkey-util.c (hashnames): Add "sm3".
* cipher/sm3.c: New.
* tests/basic.c (check_digests): Add test vectors for SM3.
* tests/hashtest-256g.in (algos): Add SM3.
* tests/hashtest.c (testvectors): Add for SM3.

--

GnuPG-bug-id: 3454
Signed-off-by: Jia Zhang <qianyue.zj@alibaba-inc.com>
22 months agoAdd new constant GCRY_MD_SM3 for crypto hash SM3.
NIIBE Yutaka [Tue, 24 Oct 2017 06:43:41 +0000 (15:43 +0900)]
Add new constant GCRY_MD_SM3 for crypto hash SM3.

* src/gcrypt.h.in (GCRY_MD_SM3): New.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
22 months agoRegister DCO for Jia Zhang.
NIIBE Yutaka [Thu, 19 Oct 2017 02:35:00 +0000 (11:35 +0900)]
Register DCO for Jia Zhang.

--

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
23 months agoapi: New function gcry_mpi_get_ui.
Werner Koch [Tue, 17 Oct 2017 13:00:08 +0000 (15:00 +0200)]
api: New function gcry_mpi_get_ui.

* src/gcrypt.h.in (gcry_mpi_get_ui): New.
(mpi_get_ui): New macro.
* src/libgcrypt.def, src/libgcrypt.vers: Add new function.
* src/visibility.c (gcry_mpi_get_ui): New.
* src/visibility.h: Mark that function.
(gcry_mpi_get_ui): New.
* mpi/mpiutil.c (MY_UINT_MAX): New macro.
(_gcry_mpi_get_ui): Re-implemented.  This function existed but was
never imported or used.
* tests/mpitests.c (test_maxsize): Add some test for this function.
--

Note that in libgcrypt.def the cardinal 91 is used which was never
used in the past.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agoTweak GCC version check.
NIIBE Yutaka [Tue, 29 Aug 2017 07:11:42 +0000 (16:11 +0900)]
Tweak GCC version check.

* src/global.c (_gcry_vcontrol): It's GCC 4.2 which started to support
diagnostic pragma.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agorandom: Fix warnings on Windows.
NIIBE Yutaka [Tue, 29 Aug 2017 07:10:54 +0000 (16:10 +0900)]
random: Fix warnings on Windows.

* random/random-csprng.c (lock_seed_file): Vars with no use.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agotests: Fix warnings on Windows.
NIIBE Yutaka [Tue, 29 Aug 2017 07:09:39 +0000 (16:09 +0900)]
tests: Fix warnings on Windows.

* tests/fipsdrv.c (print_dsa_domain_parameters, print_ecdsa_dq): Fix.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agoecc: Fix scratch MPI.
NIIBE Yutaka [Tue, 29 Aug 2017 01:33:08 +0000 (10:33 +0900)]
ecc: Fix scratch MPI.

* mpi/ec.c (ec_p_init): Check if scratch MPI is allocated.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agoecc: Fix ec_mulm_25519.
NIIBE Yutaka [Wed, 23 Aug 2017 04:03:07 +0000 (13:03 +0900)]
ecc: Fix ec_mulm_25519.

* mpi/ec.c (ec_mulm_25519): Improve reduction to 25519.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agoecc: Use 25519 method also for ed25519.
NIIBE Yutaka [Wed, 23 Aug 2017 03:46:20 +0000 (12:46 +0900)]
ecc: Use 25519 method also for ed25519.

* cipher/ecc-curves.c (_gcry_ecc_fill_in_curve): Don't use mpi_add
since it resizes to have more limbs.
* mpi/ec.c (point_resize): Fix for Edwards curve.
(ec_p_init): Support Edwards curve.
(_gcry_mpi_ec_get_affine): Use the methods.
(dup_point_edwards, add_points_edwards, sub_points_edwards): Ditto.
(_gcry_mpi_ec_mul_point): Resize MPIs of point to fixed size.
(_gcry_mpi_ec_curve_point): Use the methods.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agoecc: Clean up curve specific method support.
NIIBE Yutaka [Wed, 23 Aug 2017 03:43:38 +0000 (12:43 +0900)]
ecc: Clean up curve specific method support.

* src/ec-context.h (struct mpi_ec_ctx_s): Remove MOD method.
* mpi/ec.c (ec_mod_25519): Remove.
(ec_p_init): Follow the removal of the MOD method.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agoecc: Relax condition for 25519 computations.
NIIBE Yutaka [Wed, 23 Aug 2017 02:11:17 +0000 (11:11 +0900)]
ecc: Relax condition for 25519 computations.

* mpi/ec.c (ec_addm_25519, ec_subm_25519, ec_mulm_25519): Check number
of limbs, allocated more is OK.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agoecc: Fix ec_mulm_25519.
NIIBE Yutaka [Wed, 23 Aug 2017 01:22:21 +0000 (10:22 +0900)]
ecc: Fix ec_mulm_25519.

* mpi/ec.c (ec_mulm_25519): Fix the cases of 0 to 18.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agoecc: field specific routines for 25519.
NIIBE Yutaka [Tue, 22 Aug 2017 23:48:53 +0000 (08:48 +0900)]
ecc: field specific routines for 25519.

* mpi/ec.c (point_resize): Improve for X25519.
(mpih_set_cond): New.
(ec_mod_25519, ec_addm_25519, ec_subm_25519, ec_mulm_25519)
(ec_mul2_25519, ec_pow2_25519): New.
(ec_p_init): Fill by FIELD_TABLE.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agoecc: Add field specific computation methods.
NIIBE Yutaka [Mon, 21 Aug 2017 05:32:08 +0000 (14:32 +0900)]
ecc: Add field specific computation methods.

* src/ec-context.h (struct mpi_ec_ctx_s): Add methods.
* mpi/ec.c (ec_p_init): Initialize the default methods.
(montgomery_ladder): Use the methods.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agoAlso bump the LT Current value.
Werner Koch [Sun, 27 Aug 2017 08:13:53 +0000 (10:13 +0200)]
Also bump the LT Current value.

--

2 years agoPrepare for the 1.9 branch
Werner Koch [Sun, 27 Aug 2017 08:08:58 +0000 (10:08 +0200)]
Prepare for the 1.9 branch

--

We need to bump the LT Age even if there won't be compatible interface
change.  This is so that we can keep on updating the Revision in the
1.8 branch.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agoPost release updates
Werner Koch [Sun, 27 Aug 2017 07:36:37 +0000 (09:36 +0200)]
Post release updates

--

2 years agoRelease 1.8.1 libgcrypt-1.8.1
Werner Koch [Sun, 27 Aug 2017 07:22:09 +0000 (09:22 +0200)]
Release 1.8.1

* configure.ac: Set LT version to C22/A2/R1.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agoecc: Add input validation for X25519.
NIIBE Yutaka [Fri, 25 Aug 2017 09:13:28 +0000 (18:13 +0900)]
ecc: Add input validation for X25519.

* cipher/ecc.c (ecc_decrypt_raw): Add input validation.
* mpi/ec.c (ec_p_init): Use scratch buffer for bad points.
(_gcry_mpi_ec_bad_point): New.

--

Following is the paper describing the attack:

    May the Fourth Be With You: A Microarchitectural Side Channel Attack
    on Real-World Applications of Curve25519
    by Daniel Genkin, Luke Valenta, and Yuval Yarom

In the current implementation, we do output checking and it results an
error for those bad points.  However, when attacked, the computation
will done with leak of private key, even it will results errors.  To
mitigate leak, we added input validation.

Note that we only list bad points with MSB=0.  By X25519, MSB is
always cleared.

In future, we should implement constant-time field computation.  Then,
this input validation could be removed, if performance is important
and we are sure for no leak.

CVE-id: CVE-2017-0379
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agoindent: Typo fix.
Werner Koch [Thu, 24 Aug 2017 09:43:05 +0000 (11:43 +0200)]
indent: Typo fix.

--

2 years agocipher: Add OID for SHA384WithECDSA.
Marcus Brinkmann [Mon, 7 Aug 2017 17:26:26 +0000 (19:26 +0200)]
cipher: Add OID for SHA384WithECDSA.

* cipher/sha512.c (oid_spec_sha384): Add SHA384WithECDSA.

Signed-off-by: Marcus Brinkmann <mb@g10code.com>
Suggested-by: Sven Fischer <sven@leiderfischer.de>
GnuPG-bug-id: 3336

2 years agotests: Fix a printf glitch for a Windows test.
Werner Koch [Wed, 2 Aug 2017 16:45:51 +0000 (18:45 +0200)]
tests: Fix a printf glitch for a Windows test.

* tests/t-convert.c (check_formats): Fix print format glitch on
Windows.
* tests/t-ed25519.c: Typo fix.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agotests: Add benchmarking option to tests/random.
Werner Koch [Wed, 2 Aug 2017 16:44:14 +0000 (18:44 +0200)]
tests: Add benchmarking option to tests/random.

* tests/random.c: Always include unistd.h.
(prepend_srcdir): New.
(run_benchmark): New.
(main): Add options --benchmark and --with-seed-file.  Print whetehr
JENT has been used.
* tests/t-common.h (split_fields_colon): New. Taken from GnuPG.
License of that code changed to LGPLv2.1.

--

Running these tests on a KVM hosted Windows Vista using a statically
compiled tests/random and modifying the extra random added in
read_seed_file gave these results:

  | Seed | Jent | Bytes | Bits | Time (ms)  |
  |------+------+-------+------+------------|
  | yes  | yes  |    32 |  256 |  46 ..  62 |
  | yes  | yes  |    64 |  512 |  62 ..  78 |
  | yes  | yes  |   128 | 1024 |  78 ..  93 |
  | yes  | yes  |   256 | 2048 | 124 .. 156 |
  | yes  | yes  |   384 | 3072 | 171 .. 202 |
  | yes  | yes  |   512 | 4096 | 234 .. 249 |
  | yes  | no   |    32 |  256 |  15 ..  31 |
  | yes  | no   |    64 |  512 |  15 ..  31 |
  | yes  | no   |   128 | 1024 |  15        |
  | no   | yes  |     - |    - |  78 .. 93  |
  | no   | no   |     - |    - |  15        |

 Seed: Whether a seed file is used.
 Jent: Whether JENT was working.
Bytes: The number bytes mixed into the pool after reading
       the seed file.
 Bits: 8 * Bytes
 Time: Measured time including the time to read the seed file.
       Mimimun and maximum values are given.  Granularity of
       the used timer is quite large.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agorandom: Add more bytes to the pool in addition to the seed file.
Werner Koch [Fri, 28 Jul 2017 13:31:03 +0000 (15:31 +0200)]
random: Add more bytes to the pool in addition to the seed file.

* random/random-csprng.c (read_seed_file): Read 128 or 32 butes
depending on whether we have the Jitter RNG.
--

These are actually 3 changes:

- We use GCRY_STRONG_RANDOM instead GCRY_WEAK_RANDOM, which we used
  for historical reasons.  However the entropy gather modules handle
  both identical; that is reading from /dev/urandom.  Only
  GCRY_VERY_STRONG_RANDOM would use a blocking read from /dev/random.

- We increase the number of extra buts from 128 or 256.

- If the Jitter RNG is available we assume that a fast entropy source
  is available and thus we read 4 times more entropy (1024 bits).

Note that on Windows GnuPG tests in DE-VS mode that the Jitter RNG is
available and properly working.  Thus we will add 1024 bits in
addition to the state read from the seed file.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agoAdd script to run basic tests with all supported HWF combinations
Jussi Kivilinna [Tue, 1 Aug 2017 18:05:31 +0000 (21:05 +0300)]
Add script to run basic tests with all supported HWF combinations

* tests/basic_all_hwfeature_combinations.sh: New.
* tests/Makefile.am: Add basic_all_hwfeature_combinations.sh.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agoFix return value type for _gcry_md_extract
Jussi Kivilinna [Sat, 29 Jul 2017 11:34:23 +0000 (14:34 +0300)]
Fix return value type for _gcry_md_extract

* src/gcrypt-int.h (_gcry_md_extract): Use gpg_err_code_t instead of
gpg_error_t for internal function return type.
--

GnuPG-bug-id: 3314
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agoFix building AArch32 CE implementations when target is ARMv6 arch
Jussi Kivilinna [Sat, 29 Jul 2017 11:34:23 +0000 (14:34 +0300)]
Fix building AArch32 CE implementations when target is ARMv6 arch

* cipher/cipher-gcm-armv8-aarch32-ce.S: Select ARMv8 architecure.
* cipher/rijndael-armv8-aarch32-ce.S: Ditto.
* cipher/sha1-armv8-aarch32-ce.S: Ditto.
* cipher/sha256-armv8-aarch32-ce.S: Ditto.
* configure.ac (gcry_cv_gcc_inline_asm_aarch32_crypto): Ditto.
--

Raspbian distribution defaults to ARMv6 architecture thus 'rbit'
instruction is not available with default compiler flags. Patch
adds explicit architecture selection for ARMv8 to enable 'rbit'
usage with ARMv8/AArch32-CE assembly implementations of SHA,
GHASH and AES.

Reported-by: Chris Horry <zerbey@gmail.com>
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agosexp: Add fall through annotation.
NIIBE Yutaka [Tue, 25 Jul 2017 06:26:33 +0000 (15:26 +0900)]
sexp: Add fall through annotation.

* src/dumpsexp.c (parse_and_print): It's fall through.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agorandom: Fix the command line munging for jitterbase.
Werner Koch [Mon, 24 Jul 2017 07:32:25 +0000 (09:32 +0200)]
random: Fix the command line munging for jitterbase.

* random/Makefile.am (o_flag_munging): Make the first sed term also
global.
--

The sed script did not caught multiple -O which are not -O0.

GnuPG-bug-id: 3293
Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agodoc: Typo fix.
Werner Koch [Thu, 20 Jul 2017 08:49:24 +0000 (10:49 +0200)]
doc: Typo fix.

--

2 years agoRemove byte order mark.
NIIBE Yutaka [Wed, 19 Jul 2017 05:28:14 +0000 (14:28 +0900)]
Remove byte order mark.

* random/jitterentropy-base.c, random/jitterentropy.h: Remove
byte order mark.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agoPost release updates
Werner Koch [Tue, 18 Jul 2017 14:27:13 +0000 (16:27 +0200)]
Post release updates

--

2 years agoRelease 1.8.0 libgcrypt-1.8.0
Werner Koch [Tue, 18 Jul 2017 14:13:18 +0000 (16:13 +0200)]
Release 1.8.0

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agobuild: Remove the configure run notice on EGD.
Werner Koch [Tue, 18 Jul 2017 12:57:36 +0000 (14:57 +0200)]
build: Remove the configure run notice on EGD.

--

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agomac: Add selftests for HMAC-SHA3-xxx.
Werner Koch [Tue, 18 Jul 2017 12:11:26 +0000 (14:11 +0200)]
mac: Add selftests for HMAC-SHA3-xxx.

* cipher/hmac-tests.c (check_one): Add arg trunc and change all
callers to pass false.
(selftests_sha3): New.
(run_selftests): Call new selftests.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agoapi: New function gcry_mpi_point_copy.
Werner Koch [Tue, 18 Jul 2017 08:16:07 +0000 (10:16 +0200)]
api: New function gcry_mpi_point_copy.

* src/gcrypt.h.in (gcry_mpi_point_copy): New.
(mpi_point_copy): New macro.
* src/visibility.c (gcry_mpi_point_copy): New.
* src/libgcrypt.def, src/libgcrypt.vers: Add function.
* mpi/ec.c (_gcry_mpi_point_copy): New.
* tests/t-mpi-point.c (set_get_point): Add test.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agobuild: Bump LT version to C22/A2/R0.
Werner Koch [Mon, 17 Jul 2017 12:04:30 +0000 (14:04 +0200)]
build: Bump LT version to C22/A2/R0.

--

This is required to allow installation of 1.7 and 1.8.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agorandom: Minor fix for getting the rndjent version.
Werner Koch [Mon, 17 Jul 2017 10:34:13 +0000 (12:34 +0200)]
random: Minor fix for getting the rndjent version.

* random/rndjent.c (_gcry_rndjent_get_version): Always set R_ACTIVE.
* tests/version.c (test_get_config): Check number of fields for
rng-type.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agompi: Minor fix of mpi_pow.
NIIBE Yutaka [Fri, 7 Jul 2017 05:48:17 +0000 (14:48 +0900)]
mpi: Minor fix of mpi_pow.

* mpi/mpi-pow.c (_gcry_mpi_powm): Allocate size fix.

--

Same thing of 619ebae9847831f43314a95cc3180f4b329b4d3b applied.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agompi: Fix mpi_pow alternative implementation.
NIIBE Yutaka [Fri, 7 Jul 2017 03:00:03 +0000 (12:00 +0900)]
mpi: Fix mpi_pow alternative implementation.

* mpi/mpi-pow.c
  [USE_ALGORITHM_SIMPLE_EXPONENTIATION] (_gcry_mpi_powm): Use
  mpi_set_cond.

--

Limbs of RES may be allocated more before the call of mpi_pow,
but it only uses the space of SIZE.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agoFix mpi_pow alternative implementation.
NIIBE Yutaka [Fri, 7 Jul 2017 02:39:09 +0000 (11:39 +0900)]
Fix mpi_pow alternative implementation.

* mpi/mpi-pow.c [USE_ALGORITHM_SIMPLE_EXPONENTIATION] (_gcry_mpi_powm):
Allocate size fix.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agoUpdate NEWS
Werner Koch [Thu, 6 Jul 2017 08:26:24 +0000 (10:26 +0200)]
Update NEWS

--

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agorsa: Use modern MPI allocation function.
Werner Koch [Thu, 29 Jun 2017 06:31:27 +0000 (08:31 +0200)]
rsa: Use modern MPI allocation function.

* cipher/rsa.c (secret_core_crt): Use modern function _gcry_mpi_snew.
--

Eventually we want to get rid of the notion of limb sizes in mpi using
code.  Thus it is better to use the modern function/macro.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agobuild: Minor API fixes to fix build problems on AIX.
Werner Koch [Wed, 5 Jul 2017 18:10:56 +0000 (20:10 +0200)]
build: Minor API fixes to fix build problems on AIX.

* src/gcrypt.h.in (gcry_error_from_errno): Fix return type.
* src/visibility.c (gcry_md_extract): Change return type to match the
prototype.
--

IBM compiler optimize enums and thus enums may be shorter than an
unsigned int.  Thus an

  assert (sizeof (gpg_error_t) == sizeof (gpg_err_code_t)

would fail.  The deatils seem to depend on the passed compiler options
which explains that it has been only reported now.

GnuPG-bug-id: 3256
Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agotools: Add left shift to mpicalc.
Werner Koch [Wed, 5 Jul 2017 18:05:41 +0000 (20:05 +0200)]
tools: Add left shift to mpicalc.

* src/mpicalc.c (do_lshift): New.
(main): Handle '<'.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agompi: Fix mpi_set_secure.
NIIBE Yutaka [Tue, 4 Jul 2017 00:33:46 +0000 (09:33 +0900)]
mpi: Fix mpi_set_secure.

* mpi/mpiutil.c (mpi_set_secure): Allocate by ->alloced.

--

The code was simply wrong.  The question is if (1) it allocates
(possibly) more or (2) modifi ->alloced.  The choice is (1).

Because we have routines of mpi_set_cond and mpi_swap_cond which
assume no change for the allocated length of limbs, no surprise is
better.  See _gcry_mpi_ec_mul_point for concrete example for those
routines.  That's for constant-time computation.

Debian-bug-id: 866964
Suggested-by: Mark Wooding <mdw@distorted.org.uk>
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agorsa: Add exponent blinding.
NIIBE Yutaka [Thu, 29 Jun 2017 02:11:37 +0000 (11:11 +0900)]
rsa: Add exponent blinding.

* cipher/rsa.c (secret_core_crt): Blind secret D with randomized
nonce R for mpi_powm computation.

--

Co-authored-by: Werner Koch <wk@gnupg.org>
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
The paper describing attack: https://eprint.iacr.org/2017/627

Sliding right into disaster: Left-to-right sliding windows leak
by Daniel J. Bernstein and Joachim Breitner and Daniel Genkin and
Leon Groot Bruinderink and Nadia Heninger and Tanja Lange and
Christine van Vredendaal and Yuval Yarom

  It is well known that constant-time implementations of modular
  exponentiation cannot use sliding windows. However, software
  libraries such as Libgcrypt, used by GnuPG, continue to use sliding
  windows. It is widely believed that, even if the complete pattern of
  squarings and multiplications is observed through a side-channel
  attack, the number of exponent bits leaked is not sufficient to
  carry out a full key-recovery attack against RSA. Specifically,
  4-bit sliding windows leak only 40% of the bits, and 5-bit sliding
  windows leak only 33% of the bits.

  In this paper we demonstrate a complete break of RSA-1024 as
  implemented in Libgcrypt. Our attack makes essential use of the fact
  that Libgcrypt uses the left-to-right method for computing the
  sliding-window expansion. We show for the first time that the
  direction of the encoding matters: the pattern of squarings and
  multiplications in left-to-right sliding windows leaks significantly
  more information about exponent bits than for right-to-left. We show
  how to incorporate this additional information into the
  Heninger-Shacham algorithm for partial key reconstruction, and use
  it to obtain very efficient full key recovery for RSA-1024. We also
  provide strong evidence that the same attack works for RSA-2048 with
  only moderately more computation.

Exponent blinding is a kind of workaround to add noise.  Signal (leak)
is still there for non-constant-time implementation.

2 years agoSame computation for square and multiply.
NIIBE Yutaka [Sat, 24 Jun 2017 11:46:20 +0000 (20:46 +0900)]
Same computation for square and multiply.

* mpi/mpi-pow.c (_gcry_mpi_powm): Compare msize for max_u_size.  Move
the assignment to base_u into the loop.  Copy content refered by RP to
BASE_U except the last of the loop.

--

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agorsa: Minor refactoring.
Werner Koch [Sat, 24 Jun 2017 10:03:14 +0000 (12:03 +0200)]
rsa: Minor refactoring.

* cipher/rsa.c (secret): Factor code out to ...
(secret_core_std, secret_core_crt): new functions.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agorandom: Add missing dependency.
Werner Koch [Fri, 23 Jun 2017 07:34:35 +0000 (09:34 +0200)]
random: Add missing dependency.

* random/Makefile.am (EXTRA_librandom_la_SOURCES): Fix file name.
(rndjent.o, rndjent.lo): Depend on jitterentropy-base-user.h.
--

Fixes-commit: 8dfae89ecd3e9ae0967586cb38d12ef9111fc7cd
Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agorandom: Update jitterentropy to 2.1.0.
Werner Koch [Fri, 23 Jun 2017 07:11:47 +0000 (09:11 +0200)]
random: Update jitterentropy to 2.1.0.

* random/rndjent.c (jent_get_nstime, jent_zfree)
(jent_fips_enabled, jent_zalloc): Move functions and macros to ...
* random/jitterentropy-base-user.h: this file.   That files was not
used before.
* random/Makefile.am (EXTRA_librandom_la_SOURCES): Add
jitterentropy-base-user.
* random/jitterentropy-base.c: Update to version 2.1.0.
* random/jitterentropy.h: Ditto.
--

The files jitterentropy-base.c and jitterentropy.h are are now
verbatim copies of the upstream source using a private copy received
prior to a push to the upstream repo.  Though, 3 white spaces issues
were fixed.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agoapi: New function gcry_get_config.
Werner Koch [Wed, 21 Jun 2017 07:29:09 +0000 (09:29 +0200)]
api: New function gcry_get_config.

* src/misc.c (_gcry_log_info_with_dummy_fp): Remove.
* src/global.c (print_config): New arg WHAT.  Remove arg FNC and use
gpgrt_fprintf directly.
(_gcry_get_config): New.
(_gcry_vcontrol) <GCRYCTL_PRINT_CONFIG>: Use _gcry_get_config instead
of print_config.
* src/gcrypt.h.in (gcry_get_config): New.
* src/libgcrypt.def, src/libgcrypt.vers: Add new function.
* src/visibility.c (gcry_get_config): New.
* src/visibility.h: Mark new function.

* tests/version.c (test_get_config): New.
(main): Call new test.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agorandom: Allow building rndjent on non-x86.
Werner Koch [Wed, 21 Jun 2017 07:24:42 +0000 (09:24 +0200)]
random: Allow building rndjent on non-x86.

* random/jitterentropy-base.c (jent_version): Uncomment function.
* random/rndjent.c: Include time.h
(JENT_USES_RDTSC): New.
(JENT_USES_GETTIME): New.
(JENT_USES_READ_REAL_TIME): New.
(jent_get_nstime): Support clock_gettime and AIX specific
function.  Taken from Stephan Müller's code.
(is_rng_available): New.
(_gcry_rndjent_dump_stats): Use that function.
(_gcry_rndjent_poll): Use that fucntion.  Allow an ADD of NULL for an
intialize only mode.
(_gcry_rndjent_get_version): New.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agorijndael-padlock: change asm operands from read-only to read/write
Jussi Kivilinna [Sun, 18 Jun 2017 07:35:50 +0000 (10:35 +0300)]
rijndael-padlock: change asm operands from read-only to read/write

* cipher/rijndael-padlock.c (do_padlock): Change ESI/EDI/ECX to use
read/write operands as XCRYPT instruction modifies these registers.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agorandom: Make rndjent.c NTG.1 compliant.
Werner Koch [Fri, 16 Jun 2017 15:09:20 +0000 (17:09 +0200)]
random: Make rndjent.c NTG.1 compliant.

* random/rndjent.c (_gcry_rndjent_poll): Hash the retrieved jitter.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agomd: Optimize gcry_md_hash_buffers for SHA-256 and SHA-512.
Werner Koch [Fri, 16 Jun 2017 14:53:33 +0000 (16:53 +0200)]
md: Optimize gcry_md_hash_buffers for SHA-256 and SHA-512.

* cipher/sha256.c (_gcry_sha256_hash_buffer): New.
(_gcry_sha256_hash_buffers): New.
* cipher/sha512.c (_gcry_sha512_hash_buffer): New.
(_gcry_sha512_hash_buffers): New.
* cipher/md.c (_gcry_md_hash_buffer): Optimize for SHA246 and SHA512.
(_gcry_md_hash_buffers): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agorandom: Allow building rndjent.c with stats collecting enabled.
Werner Koch [Fri, 16 Jun 2017 10:31:11 +0000 (12:31 +0200)]
random: Allow building rndjent.c with stats collecting enabled.

* random/rndjent.c: Change license to the one used by jitterentropy.h.
(jent_init_statistic): New.
(jent_bit_count): New.
(jent_statistic_copy_stat): new.
(jent_calc_statistic): New.
--

New code taken from Stephan's jitterentropy-stat.c.  This does now
build with CONFIG_CRYPTO_CPU_JITTERENTROPY_STAT defined; not sure
whether this is already useful.  Changed the license due to the new
code.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agoNew global config option "only-urandom".
Werner Koch [Fri, 16 Jun 2017 09:55:50 +0000 (11:55 +0200)]
New global config option "only-urandom".

* random/rand-internal.h (RANDOM_CONF_ONLY_URANDOM): New.
* random/random.c (_gcry_random_read_conf): Add option "only-urandom".
* random/rndlinux.c (_gcry_rndlinux_gather_random): Implement that
option.
* tests/keygen.c (main): Add option --no-quick for better manual
tests.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agoImplement global config file /etc/gcrypt/random.conf
Werner Koch [Fri, 16 Jun 2017 08:42:44 +0000 (10:42 +0200)]
Implement global config file /etc/gcrypt/random.conf

* src/hwfeatures.c (my_isascii): Move macro to ...
* src/g10lib.h: here.
* tests/random.c (main): Dump random stats.
* random/random.c (RANDOM_CONF_FILE): New.
(_gcry_random_read_conf): New.
(_gcry_random_dump_stats): Call rndjent stats.
* random/rndjent.c (jent_rng_totalcalls, jent_rng_totalbytes): New.
(_gcry_rndjent_poll): Take care of config option disable-jent.  Wipe
buffer.  Bump counters.
(_gcry_rndjent_dump_stats): New.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agorandom: Add jitter RND based entropy collector.
Werner Koch [Wed, 14 Jun 2017 12:03:05 +0000 (14:03 +0200)]
random: Add jitter RND based entropy collector.

* random/rndjent.c: New.
* random/rndlinux.c (_gcry_rndlinux_gather_random): Use rndjent.
* random/rndw32.c (_gcry_rndw32_gather_random): Use rndjent.
(slow_gatherer): Fix compiler warning.
* random/Makefile.am (librandom_la_SOURCES): Add rndjent.c
(EXTRA_librandom_la_SOURCES): Add jitterentropy-base.c and
jitterentropy.h.
(rndjent.o, rndjent.lo): New rules.
* configure.ac: New option --disbale-jent-support
(ENABLE_JENT_SUPPORT): New ac-define.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agocipher: New helper function rol64.
Werner Koch [Wed, 14 Jun 2017 11:58:18 +0000 (13:58 +0200)]
cipher: New helper function rol64.

* cipher/bithelp.h (rol64): New inline functions.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agoNew hardware feature flag HWF_INTEL_RDTSC.
Werner Koch [Wed, 14 Jun 2017 11:57:45 +0000 (13:57 +0200)]
New hardware feature flag HWF_INTEL_RDTSC.

* src/g10lib.h (HWF_INTEL_RDTSC): New.
* src/hwfeatures.c (hwflist): Add "intel-rdtsc".
* src/hwf-x86.c (detect_x86_gnuc): Get EDX features and test for TSC.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agorandom: Changes to original Jitter RNG implementation
Werner Koch [Wed, 14 Jun 2017 11:51:51 +0000 (13:51 +0200)]
random: Changes to original Jitter RNG implementation

* random/jitterentropy-base.c: Change double underscore symbols and
make all functions static.
* random/jitterentropy.h: Likewise.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agorandom: Add original Jitter RNG implementation
Stephan Mueller [Tue, 23 May 2017 16:53:21 +0000 (18:53 +0200)]
random: Add original Jitter RNG implementation

* random/jitterentropy-base-user.h: New.
* random/jitterentropy-base.c: New.
* random/jitterentropy.h: New.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
- Tabs and trailing white spaces removed from original source.
- Source received by mail dated Fri, 27 Jan 2017 17:52:38 +0100 from
  Stephan

2 years agobuild: Fix ChangeLog building for builds from other worktrees.
Werner Koch [Thu, 8 Jun 2017 08:10:47 +0000 (10:10 +0200)]
build: Fix ChangeLog building for builds from other worktrees.

* Makefile.am (gen-ChangeLog): Test for existance of ".git" regardless
on whether it is a file or directory.
--

git worktree create a plain file ".git" and not a ".git" directory.
Thus we can't check for the existance of a directory.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agoAdd release info from 1.7.7 to NEWS
Werner Koch [Fri, 2 Jun 2017 07:19:05 +0000 (09:19 +0200)]
Add release info from 1.7.7 to NEWS

--

2 years agosecmem: Fix SEGV and stat calculation.
NIIBE Yutaka [Fri, 2 Jun 2017 01:34:42 +0000 (10:34 +0900)]
secmem: Fix SEGV and stat calculation.

* src/secmem (init_pool): Care about the header size.
(_gcry_secmem_malloc_internal): Likewise.
(_gcry_secmem_malloc_internal): Use mb->size for stats.

--

GnuPG-bug-id: 3027
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agoecc: Store EdDSA session key in secure memory.
Jo Van Bulck [Thu, 19 Jan 2017 16:00:15 +0000 (17:00 +0100)]
ecc: Store EdDSA session key in secure memory.

* cipher/ecc-eddsa.c (_gcry_ecc_eddsa_sign): use mpi_snew to allocate
session key.
--

An attacker who learns the EdDSA session key from side-channel
observation during the signing process, can easily revover the long-
term secret key. Storing the session key in secure memory ensures that
constant time point operations are used in the MPI library.

Signed-off-by: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
2 years agoapi: Deprecate gcry_md_info
Werner Koch [Wed, 31 May 2017 11:00:05 +0000 (13:00 +0200)]
api: Deprecate gcry_md_info

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agompi: Distribute asm files for aarch64 and asm
Werner Koch [Tue, 30 May 2017 13:27:47 +0000 (15:27 +0200)]
mpi: Distribute asm files for aarch64 and asm

* mpi/aarch64/distfiles: New.
* mpi/arm/distfiles: New.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agompi: Distribute asm definitions for amd64
Werner Koch [Tue, 30 May 2017 13:23:45 +0000 (15:23 +0200)]
mpi: Distribute asm definitions for amd64

* mpi/amd64/distfiles: Add mpi-asm-defs.h.
--

The problem exhibits itself only on Windows64 where
sizeof(long) == sizeof(int).
For other platforms the definition from
generic/mpi-asm-defs.h works also for amd64.

GnuPG-bug-id: 3184
Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agocipher: Fix compiler warnings.
Werner Koch [Tue, 23 May 2017 15:48:15 +0000 (17:48 +0200)]
cipher: Fix compiler warnings.

* cipher/poly1305.c (poly1305_default_ops): Move to the top.  Add
prototypes and compile only if USE_SSE2 is not defined.
(poly1305_init_ext_ref32): Compile only if USE_SSE2 is not defined.
(poly1305_blocks_ref32): Ditto.
(poly1305_finish_ext_ref32): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 years agodoc: Comment fixes
Werner Koch [Tue, 23 May 2017 15:28:46 +0000 (17:28 +0200)]
doc: Comment fixes

2 years agorijndael-ssse3: fix functions calls from assembly blocks
Jussi Kivilinna [Tue, 16 May 2017 18:22:11 +0000 (21:22 +0300)]
rijndael-ssse3: fix functions calls from assembly blocks

* cipher/rijndael-ssse3-amd64.c (PUSH_STACK_PTR, POP_STACK_PTR): New.
(vpaes_ssse3_prepare_enc, vpaes_ssse3_prepare_dec)
(_gcry_aes_ssse3_do_setkey, _gcry_aes_ssse3_prepare_decryption)
(do_vpaes_ssse3_enc, do_vpaes_ssse3_dec): Use PUSH_STACK_PTR and
POP_STACK_PTR.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agochacha20-armv7-neon: fix to use fast code path when memory is aligned
Jussi Kivilinna [Sat, 13 May 2017 15:36:00 +0000 (18:36 +0300)]
chacha20-armv7-neon: fix to use fast code path when memory is aligned

* cipher/chacha20-armv7-neon.S (UNALIGNED_LDMIA4): Uncomment
instruction for jump to aligned code path.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agoMove data in AMD64 assembly to text section
Jussi Kivilinna [Sat, 13 May 2017 15:53:08 +0000 (18:53 +0300)]
Move data in AMD64 assembly to text section

* cipher/camellia-aesni-avx-amd64.S: Move data to .text section to
ensure that RIP relative addressing of data will work.
* cipher/camellia-aesni-avx2-amd64.S: Ditto.
* cipher/chacha20-avx2-amd64.S: Ditto.
* cipher/chacha20-ssse3-amd64.S: Ditto.
* cipher/des-amd64.S: Ditto.
* cipher/serpent-avx2-amd64.S: Ditto.
* cipher/sha1-avx-amd64.S: Ditto.
* cipher/sha1-avx-bmi2-amd64.S: Ditto.
* cipher/sha1-ssse3-amd64.S: Ditto.
* cipher/sha256-avx-amd64.S: Ditto.
* cipher/sha256-avx2-bmi2-amd64.S: Ditto.
* cipher/sha256-ssse3-amd64.S: Ditto.
* cipher/sha512-avx-amd64.S: Ditto.
* cipher/sha512-avx2-bmi2-amd64.S: Ditto.
* cipher/sha512-ssse3-amd64.S: Ditto.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agocast5-amd64: use 64-bit relocation with large PIC memory model
Jussi Kivilinna [Sat, 13 May 2017 15:35:30 +0000 (18:35 +0300)]
cast5-amd64: use 64-bit relocation with large PIC memory model

* cipher/cast5-amd64.S [__code_model_large__]
(GET_EXTERN_POINTER): New.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agoFix building with x86-64 medium and large memory models
Jussi Kivilinna [Sat, 13 May 2017 14:53:27 +0000 (17:53 +0300)]
Fix building with x86-64 medium and large memory models

* cipher/cast5-amd64.S [HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS]
(GET_EXTERN_POINTER): Load 64-bit address instead of 32-bit.
* cipher/rijndael.c (do_encrypt, do_decrypt)
[USE_AMD64_ASM && !HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS]: Load
table pointer through register instead of generic reference.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agoSpelling fixes in docs and comments.
NIIBE Yutaka [Fri, 28 Apr 2017 00:27:00 +0000 (09:27 +0900)]
Spelling fixes in docs and comments.

--

GnuPG-bug-id: 3120
Reported-by: ka7 (klemens)
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agompi: Simplify mpi_powm.
NIIBE Yutaka [Tue, 4 Apr 2017 08:38:05 +0000 (17:38 +0900)]
mpi: Simplify mpi_powm.

* mpi/mpi-pow.c (_gcry_mpi_powm): Simplify the loop.

--

This fix is not a solution for the problem reported (yet).  The
problem is that the current algorithm of _gcry_mpi_powm depends on
exponent and some information leaks is possible.

Reported-by: Andreas Zankl <andreas.zankl@aisec.fraunhofer.de>
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2 years agobuild: Use macOS' compatibility macros to enable all features.
Justus Winter [Wed, 8 Mar 2017 12:09:11 +0000 (13:09 +0100)]
build: Use macOS' compatibility macros to enable all features.

* configure.ac: On macOS, use the compatibility macros to expose every
feature of the libc.  This is the equivalent of _GNU_SOURCE on GNU
libc.
--
Not defining this leads to compilation errors or superfluous warnings
on macOS.

GnuPG-bug-id: 2910
Signed-off-by: Justus Winter <justus@g10code.com>
2 years agoAdd BLAKE2b and BLAKE2s hash algorithms (RFC 7693)
Jussi Kivilinna [Sun, 26 Feb 2017 17:55:34 +0000 (19:55 +0200)]
Add BLAKE2b and BLAKE2s hash algorithms (RFC 7693)

* cipher/blake2.c: New.
* cipher/Makefile.am: Add 'blake2.c'.
* cipher/md.c (digest_list, prepare_macpads): Add BLAKE2.
(md_setkey): New.
(_gcry_md_setkey): Call 'md_setkey' for non-HMAC md.
* configure.ac: Add BLAKE2 digest.
* doc/gcrypt.texi: Add BLAKE2.
* src/cipher.h (_gcry_blake2_init_with_key)
(_gcry_digest_spec_blake2b_512, _gcry_digest_spec_blake2b_384)
(_gcry_digest_spec_blake2b_256, _gcry_digest_spec_blake2b_160)
(_gcry_digest_spec_blake2s_256, _gcry_digest_spec_blake2s_224)
(_gcry_digest_spec_blake2s_160, _gcry_digest_spec_blake2s_128): New.
* src/gcrypt.h.in (GCRY_MD_BLAKE2B_512, GCRY_MD_BLAKE2B_384)
(GCRY_MD_BLAKE2B_256, GCRY_MD_BLAKE2B_160, GCRY_MD_BLAKE2S_256)
(GCRY_MD_BLAKE2S_224, GCRY_MD_BLAKE2S_160, GCRY_MD_BLAKE2S_128): New.
* tests/basic.c (check_one_md): Add testing for keyed hashes.
(check_digests): Add BLAKE2 test vectors; Add testing for keyed hashes.
* tests/blake2b.h: New.
* tests/blake2s.h: New.
* tests/Makefile.am: Add 'blake2b.h' and 'blake2s.h'.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agoFix building with clang on ARM64/FreeBSD
Jussi Kivilinna [Sun, 26 Feb 2017 17:55:34 +0000 (19:55 +0200)]
Fix building with clang on ARM64/FreeBSD

* cipher/cipher-gcm-armv8-aarch64-ce.S: Use '.cpu generic+simd+crypto'
instead of '.arch armv8-a+crypto'.
* cipher/rijndael-armv8-aarch64-ce.S: Ditto.
* cipher/sha1-armv8-aarch64-ce.S: Ditto.
* cipher/sha256-armv8-aarch64-ce.S: Ditto.
* configure.ac (gcry_cv_gcc_inline_asm_aarch64_neon): Ditto.
(gcry_cv_gcc_inline_asm_aarch64_crypto): Ditto; and include NEON
instructions to crypto instructions check.
--

GnuPG-bug-id: 2975
Reported-by: Kirill Ponomarev <kp@krion.cc>
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agoFix building with a pre C99 compiler.
Justus Winter [Tue, 7 Feb 2017 09:20:58 +0000 (10:20 +0100)]
Fix building with a pre C99 compiler.

* cipher/cipher-cfb.c (_gcry_cipher_cfb8_encrypt): Move the
declaration of 'i' out of the loop.
(_gcry_cipher_cfb8_decrypt): Likewise.
--
Fixes build on OpenBSD.

Fixes-commit: d1ee9a660571ce4a998c9ab2299d4f2419f99127
Signed-off-by: Justus Winter <justus@g10code.com>
2 years agoImplement CFB with 8-bit mode
Mathias L. Baumann [Sat, 4 Feb 2017 11:30:41 +0000 (13:30 +0200)]
Implement CFB with 8-bit mode

* cipher/cipher-cfb.c (_gcry_cipher_cfb8_encrypt)
(_gcry_cipher_cfg8_decrypt): Add 8-bit variants of decrypt/encrypt
functions.
* cipher/cipher-internal.h (_gcry_cipher_cfb8_encrypt)
(_gcry_cipher_cfg8_decrypt): Ditto.
* cipher/cipher.c: Adjust code flow to work with GCRY_CIPHER_MODE_CFB8.
* tests/basic.c: Add tests for cfb8 with AES and 3DES.
--

Signed-off-by: Mathias L. Baumann <mathias.baumann at sociomantic.com>
[JK: edit changelog, fix email malformed patch]
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agoRegister DCO for Mathias L. Baumann
Jussi Kivilinna [Sat, 4 Feb 2017 11:29:50 +0000 (13:29 +0200)]
Register DCO for Mathias L. Baumann

--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agorndhw: add missing "memory" clobbers
Jussi Kivilinna [Sat, 4 Feb 2017 10:48:57 +0000 (12:48 +0200)]
rndhw: add missing "memory" clobbers

* random/rndhw.c: (poll_padlock, rdrand_long): Add "memory" to asm
clobbers.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agoAdd UNLIKELY and LIKELY macros
Jussi Kivilinna [Sat, 28 Jan 2017 09:00:35 +0000 (11:00 +0200)]
Add UNLIKELY and LIKELY macros

* src/g10lib.h (LIKELY, UNLIKELY): New.
(gcry_assert): Use LIKELY for assert check.
(fast_wipememory2_unaligned_head): Use UNLIKELY for unaligned
branching.
* cipher/bufhelp.h (buf_cpy, buf_xor, buf_xor_1, buf_xor_2dst)
(buf_xor_n_copy_2): Ditto.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agorndhw: avoid type-punching
Jussi Kivilinna [Sat, 28 Jan 2017 13:00:28 +0000 (15:00 +0200)]
rndhw: avoid type-punching

* random/rndhw.c (rdrand_long, rdrand_nlong): Add 'volatile' for
pointer.
(poll_drng): Convert buffer to 'unsigned long[]' and make use of DIM
macro.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agohwf-x86: avoid type-punching
Jussi Kivilinna [Sat, 28 Jan 2017 12:59:56 +0000 (14:59 +0200)]
hwf-x86: avoid type-punching

* src/hwf-x86.c (detect_x86_gnuc): Use union for vendor_id.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agocipher: add explicit blocksize checks to allow better optimization
Jussi Kivilinna [Sat, 28 Jan 2017 08:26:09 +0000 (10:26 +0200)]
cipher: add explicit blocksize checks to allow better optimization

* cipher/cipher-cbc.c (_gcry_cipher_cbc_encrypt)
(_gcry_cipher_cbc_decrypt): Add explicit check for cipher blocksize of
64-bit or 128-bit.
* cipher/cipher-cfb.c (_gcry_cipher_cfb_encrypt)
(_gcry_cipher_cfb_decrypt): Ditto.
* cipher/cipher-cmac.c (cmac_write, cmac_generate_subkeys)
(cmac_final): Ditto.
* cipher/cipher-ctr.c (_gcry_cipher_ctr_encrypt): Ditto.
* cipher/cipher-ofb.c (_gcry_cipher_ofb_encrypt): Ditto.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agobufhelp: use unaligned dword and qword types for endianess helpers
Jussi Kivilinna [Sat, 28 Jan 2017 09:26:02 +0000 (11:26 +0200)]
bufhelp: use unaligned dword and qword types for endianess helpers

* cipher/bufhelp.h (BUFHELP_UNALIGNED_ACCESS): New, defined
if attributes 'packed', 'aligned' and 'may_alias' are supported.
(BUFHELP_FAST_UNALIGNED_ACCESS): Define if have
BUFHELP_UNALIGNED_ACCESS.
--

Now that compiler is properly told that reads from these types
may do not follow strict-aliasing and may be unaligned, we
enable use of these for all architectures and compiler will
emit more optimized, yet correct, code (for example, use
special unaligned read/write instructions instead of accessing
byte-by-byte).

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agorijndael-aesni: fix u128_t strict-aliasing rule breaking
Jussi Kivilinna [Sat, 28 Jan 2017 09:26:02 +0000 (11:26 +0200)]
rijndael-aesni: fix u128_t strict-aliasing rule breaking

* cipher/rijndael-aesni.c (u128_t): Add attributes to tell GCC and clang
that casting from 'char *' to 'u128_t *' is ok.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agocipher-xts: fix pointer casting to wrong alignment and aliasing
Jussi Kivilinna [Sat, 28 Jan 2017 09:26:02 +0000 (11:26 +0200)]
cipher-xts: fix pointer casting to wrong alignment and aliasing

* cipher/cipher-xts.c (xts_gfmul_byA, xts_inc128): Use buf_get_le64
and buf_put_le64 for accessing data; Change parameter pointers to
'unsigned char *' type.
(_gcry_cipher_xts_crypt): Do not cast buffer pointers to 'u64 *'
for helper functions.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agocrc-intel-pclmul: fix undefined behavior with unaligned access
Jussi Kivilinna [Sat, 28 Jan 2017 09:26:02 +0000 (11:26 +0200)]
crc-intel-pclmul: fix undefined behavior with unaligned access

* cipher/crc-intel-pclmul.c (u16_unaligned_s): New.
(crc32_reflected_less_than_16, crc32_less_than_16): Use
'u16_unaligned_s' for unaligned memory access.
--

GnuPG-bug-id: 2292
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agoconfigure.ac: fix attribute checks
Jussi Kivilinna [Sat, 28 Jan 2017 09:26:02 +0000 (11:26 +0200)]
configure.ac: fix attribute checks

* configure.ac: Add -Werror flag for attribute checks.
--

Compilter ignores unknown attributes and just shows warning. Therefore
attribute checks need to be run with -Werror.

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agoconfigure.ac: fix may_alias attribute check
Jussi Kivilinna [Sat, 28 Jan 2017 09:26:02 +0000 (11:26 +0200)]
configure.ac: fix may_alias attribute check

* configure.ac: Test may_alias attribute on type, not on variable.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agobufhelp: add 'may_alias' attribute for properly aligned 'bufhelp_int_t'
Jussi Kivilinna [Sat, 28 Jan 2017 09:26:02 +0000 (11:26 +0200)]
bufhelp: add 'may_alias' attribute for properly aligned 'bufhelp_int_t'

* cipher/bufhelp.h [!BUFHELP_FAST_UNALIGNED_ACCESS]
(bufhelp_int_t): Add 'may_alias' attribute.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
2 years agow32: New envvar GCRYPT_RNDW32_DBG.
Werner Koch [Fri, 27 Jan 2017 08:16:31 +0000 (09:16 +0100)]
w32: New envvar GCRYPT_RNDW32_DBG.

* random/rndw32.c (_gcry_rndw32_gather_random): Use getenv to set
DEBUG_ME.

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