Commit Graph

165 Commits

Author SHA1 Message Date
NIIBE Yutaka 554ded4854 mpi: Minor fix for mpi_pow.
* mpi/mpi-pow.c (mpi_powm): Fix allocation size.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2017-07-07 15:12:00 +09:00
NIIBE Yutaka 12029f83fd mpi: Same computation for square and multiply for mpi_pow.
* 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>

(backport commit of libgcrypt master:
78130828e9a140a9de4dafadbc844dbb64cb709a)
2017-07-07 14:38:19 +09:00
NIIBE Yutaka b38f4489f7 mpi: Simplify mpi_powm.
* mpi/mpi-pow.c (_gcry_mpi_powm): Simplify the loop.

--

(backport of libgcrypt master commit:
 719468e53133d3bdf12156c5bfdea2bf15f9f6f1)

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2017-07-07 14:26:39 +09:00
Marcus Brinkmann 782f804765 mpi: Fix ARM assembler in longlong.h.
* mpi/longlong.h [__arm__] (add_ssaaaa, sub_ddmmss): Add __CLOBBER_CC.
[__arm__][__ARM_ARCH <= 3] (umul_ppmm): Add __AND_CLOBBER_CC.

--
This is a backport of libgcrypt 8aa4f2161 and 3b1cc9e6c.

Signed-off-by: Marcus Brinkmann <mb@g10code.com>
GnuPG-bug-id: 3182
2017-07-04 23:19:51 +02:00
NIIBE Yutaka 04667cabef g10: fix cmp_public_key and cmp_secret_keys.
* g10/free-packet.c (cmp_public_keys, cmp_secret_keys): Compare opaque
data at the first entry of the array when it's unknown algo.
* mpi/mpi-cmp.c (mpi_cmp): Backport libgcrypt 1.5.0's semantics.

--

(backported from 2.0 commit 43429c7869)

GnuPG-bug-id: 1962
2015-04-30 17:20:08 +09:00
NIIBE Yutaka 6cbc75e712 mpi: Avoid data-dependent timing variations in mpi_powm.
* include/mpi.h, mpi/mpiutils.c (mpi_set_cond): New.
* mpi/mpi-pow.c (SIZE_PRECOMP): Rename from SIZE_B_2I3.
(mpi_powm): Access all data in the table and use mpi_set_cond.

--

Access to the precomputed table was indexed by a portion of EXPO,
which could be mounted by a side channel attack.  This change fixes
this particular data-dependent access pattern.
2015-02-26 21:00:05 +09:00
Werner Koch 592e1aa407 Modernize to automake 1.14.
* Makefile.am (AUTOMAKE_OPTIONS): Move to ...
* configure.ac (AM_INIT_AUTOMAKE): here and add serial-tests.

* keyserver/Makefile.am: Replace INCLUDES by AM_CPPFLAGS.
* mpi/Makefile.am: Ditto.
* util/Makefile.am: Ditto.
* keyserver/Makefile.am: Ditto.  Adjusted other things.

* m4/intl.m4, m4/po.m4: Use autoconf's AC_PROG_MKDIR_P.
2015-01-19 18:59:13 +01:00
Werner Koch f68123551f mpi: Fix compiler warning.
* mpi/mpi-inv.c (mpi_invm): Do not return a value.
2014-10-03 18:28:58 +02:00
Werner Koch cd53cdbc37 mpi: Improve mpi_invm to detect bad input.
* mpi/mpi-inv.c (mpi_invm): Return 0 for bad input.
--

Without this patch the function may enter an endless loop.  This is a
backport from libgcrypt.

GnuPG-bug-id: 1713
2014-09-11 17:06:22 +02:00
Werner Koch b89f57fe5d mpi: Suppress set-but-unused-variables warnings.
* include/types.h (GNUPG_GCC_ATTR_UNUSED): Define for gcc >= 3.5.
* mpi/mpih-div.c (mpihelp_divmod_1, mpihelp_mod_1): Mark dummy as
 unused.
* mpi/mpi-internal.h (UDIV_QRNND_PREINV): Mark _ql as unused.
--

Due to the use of macros and longlong.h, we use variables which are
only used by some architectures.  At least gcc 4.7.2 prints new
warnings about set but not used variables.  This patch silences them.
2014-08-20 13:25:17 +02:00
Werner Koch cad8216f9a mpi: mpi-pow improvements
* mpi/mpi-pow.c (USE_ALGORITHM_SIMPLE_EXPONENTIATION): New.
(mul_mod) [!USE_ALGORITHM_SIMPLE_EXPONENTIATION]: New.
(mpi_powm) [!USE_ALGORITHM_SIMPLE_EXPONENTIATION]: New implementation
of left-to-right k-ary exponentiation.
--

This is a backport from Libgcrypt commit
45aa6131e93fac89d46733b3436d960f35fb99b2

    Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>

    For the Yarom/Falkner flush+reload cache side-channel attack, we
    changed the code so that it always calls the multiplication
    routine (even if we can skip it to get result).  This results some
    performance regression.

    This change is for recovering performance with efficient
    algorithm.

Signed-off-by: Werner Koch <wk@gnupg.org>
2013-10-18 10:54:55 +02:00
Werner Koch 9d89564a42 mpi: Fix syntax error for mips64 and gcc < 4.4
* mpi/longlong.h [__mips && gcc < 4.4]: Fix cpp syntax error.
--

GnuPG-bug-id: 1465
2013-10-11 14:11:43 +02:00
Werner Koch 9dc6dd0572 Fix bug in mpi_tdiv_q_2exp.
* mpi/mpi-internal.h (MPN_COPY_INCR): Make it work.
--

This bug has been with us since the version 0.0.0 of GnuPG.
Fortunately it only affects an optimized code path which is rarely
used in practice: If the shift size matches the size of a
limb (i.e.. 32 or 64); this is is_prime in primegen.c.  Over there the
Rabin-Miller test may fail with a probability of 2^-31 (that is if the
to be tested prime - 1 has the low 32 bits cleared).  In practice the
probability is even much less because we first do a Fermat test on the
randomly generated candidates which sorts out the majority of
composite numbers.

The bug in MPN_COPY_INCR was found by Sven Bjorn.

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

(back ported from Libgcrypt
 commit 7f7a5ef59962ae1a819b5060f9b781469bfe27d5)
2013-09-16 15:57:01 +02:00
Werner Koch 35646689f4 Mitigate a flush+reload cache attack on RSA secret exponents.
* mpi/mpi-pow.c (mpi_powm): Always perform the mpi_mul for exponents
hold in secure memory.
--

The attack is described in a paper to be pusblished at eprint.iacr.org:

Flush+Reload: a High Resolution, Low Noise, L3 Cache Side-Channel
Attack by Yuval Yarom and Katrina Falkner. 18 July 2013.

  Flush+Reload is a cache side-channel attack that monitors access to
  data in shared pages. In this paper we demonstrate how to use the
  attack to extract private encryption keys from GnuPG.  The high
  resolution and low noise of the Flush+Reload attack enables a spy
  program to recover over 98% of the bits of the private key in a
  single decryption or signing round. Unlike previous attacks, the
  attack targets the last level L3 cache. Consequently, the spy
  program and the victim do not need to share the execution core of
  the CPU. The attack is not limited to a traditional OS and can be
  used in a virtualised environment, where it can attack programs
  executing in a different VM.

Signed-off-by: Werner Koch <wk@gnupg.org>
2013-07-25 10:37:40 +02:00
Werner Koch 0fee571260 Support NetBSD m68K ELF targets
* mpi/config.links (m68k*-*-netbsdelf): New.

--

The original patch from NetBSD had this additional code:

	if ! test x$M68060 = xYES; then
	    path="m68k/mc68020 m68k"
	fi

However, this bypasses the config system.  It would be better to add
proper support for this CPU to config.sub.
2012-12-13 18:15:38 +01:00
Werner Koch 5093bed275 Fix extern inline use for gcc > 4.3 in c99 mode
* mpi/mpi-inline.h [!G10_MPI_INLINE_DECL]: Take care of changed extern
inline semantics in gcc.
--

I am not use how this will work out with non-gcc. However, we had no
problems in the past and thus this change is the least invasive for
non-gcc compilers.
2012-11-06 17:14:04 +01:00
Werner Koch 76b73caf91 Rename all ChangeLog files to ChangeLog-2011.
* ChangeLog: New file.
2011-12-02 19:42:56 +01:00
Werner Koch a95143e225 Removed some set but unused vars. 2011-08-09 10:54:22 +02:00
Werner Koch 6daa9dbd7c Allow building for ARM thumb. Fixes bug#1202. 2011-07-04 12:41:45 +02:00
Werner Koch 36366dab85 Revert last two changes and replace by code from libgcrypt 1.4.6. 2010-12-23 19:05:31 +00:00
Werner Koch f7ab9d61bf mips fixes 2010-10-22 07:35:30 +00:00
Werner Koch c253383ab1 Fix bug 1231.
Minor doc improvement.
2010-06-01 12:42:39 +00:00
Werner Koch 6cb6c761a6 Remove sparc64 asm modules 2009-12-09 15:56:45 +00:00
Werner Koch 2c045c4fca Powerpc64 fix. 2008-03-25 10:45:59 +00:00
Werner Koch 9a2a818887 Switched to GPLv3.
Updated gettext.
2007-10-23 10:48:09 +00:00
David Shaw e5f521db93 * config.links: powerpc64* needs to come before powerpc* or it will
never match.  Reported by Alon Bar-Lev for libgcrypt, but relevant
here as well.
2007-01-16 05:20:06 +00:00
Werner Koch 9f433cccca Removed the use of g10defs.h.
This required some code cleanups and the introduction of
a few accessor ducntions in mpi.
2006-12-11 19:54:53 +00:00
David Shaw 516ec53e02 * mpicoder.c (mpi_read): Fix minor bug in reading a zero-length MPI
(was failing unnecessarily).
2005-09-01 13:44:49 +00:00
Werner Koch a1cdf3c75f Converted all m_free to xfree etc. 2005-07-27 18:10:56 +00:00
Werner Koch 7d4043ca57 Updated FSF street address and preparations for a release candidate. 2005-05-31 08:39:18 +00:00
Werner Koch be2aa37dbf * cardglue.c (send_status_info): Make CTRL optional.
(agent_scd_writekey, inq_writekey_parms): New.
(agent_openpgp_storekey): Removed.
* cardglue.h: Add a few more error code mappings.
* keygen.c (copy_mpi): Removed.
(save_unprotected_key_to_card): Changed to use agent_scd_writekey.
* app-common.h, app-openpgp.c, tlv.c, tlv.h: Updated from newer
version in gnupg 1.9 CVS.
2005-05-21 14:04:32 +00:00
Werner Koch f0e9a1ff4f * configure.ac: New option --enable-noexecstack.
* Makefile.am (ASFLAGS): Renamed to AM_CCASFLAGS and added the
variable for non exectubale stack options.  Adapted users.
2005-03-11 11:02:12 +00:00
Werner Koch 9e3526f236 * seckey-cert.c (do_check): Handle case when checksum was okay but
passphrase still wrong.  Roman Pavlik found such a case.

* mpicoder.c (mpi_read_from_buffer): Don't abort in case of an
invalid MPI but print a message and return NULL.  Use log_info and
not log_error.
2004-12-20 10:05:20 +00:00
Werner Koch d7fd47185e * configure.ac: New option --disable-gnupg-iconv, define
USE_GNUPG_ICONV.
(AC_CANONICAL_TARGET): Replaced by AC_CANONICAL_HOST. Changed all
reference to TARGET to HOST.  Made sure that i586-mingw32msvc gets
detected as mingw32.
(UNIT64_C): Don't include inttype.h uncoditional but use a test to
ensure that it gets into conftest.h.
(AH_TOP): New. Prevent double inclusion of config.h.

* config.links: Use HOST instead of TARGET.
2004-10-26 19:33:41 +00:00
Werner Koch c44e66f352 * Makefile.am (.S.o): Include MPI_SFLAGS. This is our bug 145. 2004-10-13 07:11:10 +00:00
David Shaw ec0cc1f135 * mpicoder.c (mpi_read): If we must fail due to a oversize (generally
corrupt) MPI, make sure the number of bytes we read is valid so we can
skip the rest of the bad packet (in hopes the whole stream isn't invalid).
2004-09-30 04:07:23 +00:00
David Shaw c19c728afa * longlong.h: Typo.
* mpi-pow.c (mpi_powm): s/exp/exponent/ to shutup a compiler warning.
From Werner on stable branch.
2004-05-20 17:34:00 +00:00
David Shaw a18110a053 hppa1.1/udiv-qrnnd.S: Alignment fix from Lamont Jones for Debian. 2004-01-21 04:26:35 +00:00
David Shaw 666c582e36 * config.links: OpenBSD 3.4 is now ELF, so use the proper assembler code
for that.  Use the portable C MPI code for OpenBSD before 3.4, and remove
the special i386-openbsd assembly directory.

* Makefile.am: Add the portable C links to DISTCLEANFILES.  Noted by
Nelson H. F. Beebe.

* mpi-mpow.c (build_index): s/index/idx/ to avoid gcc warning. From Werner
on stable branch.

* longlong.h: Added PowerPC 64 bit code from GPM-4.1.2 but didn't enable
it yet.  From Werner on stable branch.
2004-01-12 00:51:39 +00:00
David Shaw 5a57e36003 Use the portable C MPI code for OpenBSD before 3.4, and remove the special
i386-openbsd assembly directory.
2004-01-12 00:48:28 +00:00
David Shaw 1228a48ab9 * g10m.c: Dead code. Remove.
* Makefile.am: Don't compile g10m.c.
2003-12-30 04:29:07 +00:00
David Shaw e49672d5a3 * mpiutil.c (mpi_set_opaque, mpi_get_opaque): Make the length of an opaque
MPI unsigned.
2003-12-17 22:30:57 +00:00
David Shaw 10e596d6c3 * config.links: Show target in asm-syntax.h file and include targets for
K*BSD (GNU userland with BSD kernel).
2003-12-05 04:15:31 +00:00
David Shaw 3330dbd714 * config.links: sparc64 assembler doesn't work on FreeBSD or OpenBSD
either.
2003-11-21 01:13:55 +00:00
David Shaw 951f7d9eca * Makefile.am: Make use of AM_CFLAGS. (From wk on stable branch) 2003-05-26 13:15:24 +00:00
David Shaw e152598106 * mpicoder.c, mpi-inline.h, mpi-inv.c, mpiutil.c, mpih-div.c,
mpi-internal.h, mpi-scan.c: Edit all preprocessor instructions to remove
whitespace before the '#'.  This is not required by C89, but there are
some compilers out there that don't like it.
2003-05-24 17:54:56 +00:00
David Shaw e0373e85a9 * config.links: Re-disable assembler on Darwin. Darwin 6.5 broke it
again.
2003-04-25 04:12:57 +00:00
Werner Koch 6878858fdc * longlong.h (umul_ppmm): Support SH3 and SH4. Thanks to
kazuya.s@jp.yokogawa.com.
2003-04-15 12:44:27 +00:00
David Shaw 6b48375467 * config.links: Use OpenBSD/NetBSD powerpc assembler code for Darwin.
Successfully tested by Gordon Worley.
2002-11-16 16:53:58 +00:00
Werner Koch 74d460ad63 * config.links (powerpc-apple-darwin6.1): Disable assembler
due to non-working modules/as.  Suggested by Gordon Worley.
2002-10-18 09:24:56 +00:00