catacomb
3 years agobase/asm-common.h (x86), and knock-on: Add macros for full-size regs.
Mark Wooding [Tue, 29 Oct 2019 18:55:16 +0000 (18:55 +0000)]
base/asm-common.h (x86), and knock-on: Add macros for full-size regs.

These registers get used a lot as pointers, so it's useful to be able to
refer to them as full-width registers more conveniently than `R_sp(r)'.
Introduce (C preprocessor) macros `AX', ..., for this purpose, and use
them extensively.

(Delete the existing `SI' and `DI' macros from `rijndael-x86ish-aesni.S'
which had the same purpose.)

3 years agobase/regdump.h: Pass cooked register index to `REGDEF_GPX86_COMMON'.
Mark Wooding [Tue, 29 Oct 2019 18:38:27 +0000 (18:38 +0000)]
base/regdump.h: Pass cooked register index to `REGDEF_GPX86_COMMON'.

I want to define `BP' and `SP' as macros, but they'll expand in the
calls to `REGDEF_GPX86_COMMON', which will break things.  They don't
expand directly in the body of `REGDEF_GPX86_XP' because `##' inhibits
this.  Alas, this means we have to do this token-gluing in the interface
macros rather than the common core.

3 years agosymm/poly1305.c, etc.: Convert the Monte-Carlo tests to incremental form.
Mark Wooding [Tue, 29 Oct 2019 23:41:37 +0000 (23:41 +0000)]
symm/poly1305.c, etc.: Convert the Monte-Carlo tests to incremental form.

Similarly to the way 1e4c26653e52aa4c4b06e345617135a6ff271ab5 modified
the X25519 and X448 tests, arrange that each Monte-Carlo test vector
continues from where the previous one left off.  This is considerably
trickier to pull off because there's so much more state to maintain in
these tests, and changes to the processing code was necessary to make it
work.

Again, as in 1e4c2665..., move the very slow high-iteration-count tests
into a separate file, and arrange for it to be distributed.

Note that the outputs are unchanged by all of this.

3 years agosymm/poly1305.c: Keep the working buffers in `dstr' buffers.
Mark Wooding [Tue, 29 Oct 2019 10:26:11 +0000 (10:26 +0000)]
symm/poly1305.c: Keep the working buffers in `dstr' buffers.

This way, they can be printed easily using the testrig type machinery.

3 years agosymm/poly1305.c: Use explicit sizes in the Monte-Carlo test.
Mark Wooding [Tue, 29 Oct 2019 10:19:49 +0000 (10:19 +0000)]
symm/poly1305.c: Use explicit sizes in the Monte-Carlo test.

The indirect `sizeof' expressions weren't always of the right variable,
and I'm going to replace the vectors with pointers soon.

3 years agoprogs/key.c: Don't print secret parts of keys at verbosity 3.
Mark Wooding [Sat, 26 Oct 2019 14:46:20 +0000 (15:46 +0100)]
progs/key.c: Don't print secret parts of keys at verbosity 3.

Print them at level 4.  Push printing of locked portions to level 5.

3 years agoprogs/key.c: Use `HASH' rather than `HASHALG' to denote a hash-function name.
Mark Wooding [Sat, 26 Oct 2019 14:43:23 +0000 (15:43 +0100)]
progs/key.c: Use `HASH' rather than `HASHALG' to denote a hash-function name.

I noticed that the synopses were inconsistent between `fingerprint' and
`verify'.  Resolve this in favour of the shorter `HASH', despite the
1--3 minority.  (Note that the manual already uses `hash' consistently.)

3 years agokey/key-misc.c (key_bytag): Accept `tag:', `id:' and `type:' prefixes.
Mark Wooding [Sat, 26 Oct 2019 14:40:19 +0000 (15:40 +0100)]
key/key-misc.c (key_bytag): Accept `tag:', `id:' and `type:' prefixes.

Further to the fix 079836cc4d21b355c8b58a4624ef85df0ac6c21a, allow the
user to attach a disambiguating prefix to the label.  Using the colon is
safe here, since it's obviously not acceptable in a hex id, and
`key_chkident' rejects colons in tag and type strings.

3 years agoDeploy the new <ctype.h> and `foocmp' macros from mLib.
Mark Wooding [Tue, 1 Oct 2019 19:01:20 +0000 (20:01 +0100)]
Deploy the new <ctype.h> and `foocmp' macros from mLib.

3 years agosymm/t/poly1305: Spell Dan Bernstein's name correctly.
Mark Wooding [Wed, 23 Oct 2019 22:42:12 +0000 (23:42 +0100)]
symm/t/poly1305: Spell Dan Bernstein's name correctly.

Sorry, Dan.

3 years agopub/dh-kcdsa.c: Retry or fail if we don't get the target sizes.
Mark Wooding [Wed, 23 Oct 2019 03:12:44 +0000 (04:12 +0100)]
pub/dh-kcdsa.c: Retry or fail if we don't get the target sizes.

Following the usual convention, we retry unless the caller gave us a
bounded number of steps, and otherwise fail.

I think failure is fairly unlikely now.  To find an N-bit prime, we
expect to take about 4 N steps (see analysis in `math/strongprime.c').
But we're trying to find two primes simultaneously, one of N bits, and
one of M bits, so this will take about 16 M N steps in total.  We start
with v < 2^{N-M-1}, and choose 2^{M-1} <= q_0 < 2^M such that 2^{N-1} <
p_0 = 2 q_0 v + 1 < 2^N (nearly true).  We'll fail if 2^M - q_0 < 16 M N,
which seems unlikely, or if 2^N - p_0 < 32 M N v, i.e., 2^M - p_0/(2 v) <
16 M N, which is basically the same condition.

3 years agopub/dh-kcdsa.c: Choose the starting point for the right result size.
Mark Wooding [Wed, 23 Oct 2019 03:11:55 +0000 (04:11 +0100)]
pub/dh-kcdsa.c: Choose the starting point for the right result size.

And try again until it's actually likely to work.

3 years agopub/dh-kcdsa.c: Choose the cofactor size correctly.
Mark Wooding [Wed, 23 Oct 2019 03:11:05 +0000 (04:11 +0100)]
pub/dh-kcdsa.c: Choose the cofactor size correctly.

Considering that we're going to have to multiply in a factor of 2 at
some point.

3 years agopub/dh-kcdsa.c: Make the cleanup flow less crazy.
Mark Wooding [Wed, 23 Oct 2019 03:09:05 +0000 (04:09 +0100)]
pub/dh-kcdsa.c: Make the cleanup flow less crazy.

I'm pretty sure I've fixed bugs in here.

3 years agopub/dh-kcdsa.c: Fix commentary blunder.
Mark Wooding [Wed, 23 Oct 2019 03:05:21 +0000 (04:05 +0100)]
pub/dh-kcdsa.c: Fix commentary blunder.

3 years agoutils/advmodes, utils/gcm-ref: Make conversions from `int' to `GF' explicit.
Mark Wooding [Fri, 18 Oct 2019 21:59:02 +0000 (22:59 +0100)]
utils/advmodes, utils/gcm-ref: Make conversions from `int' to `GF' explicit.

This anticipates a Catacomb/Python change which breaks implicit
conversions to `GF'.

3 years agosymm/hmac-def.h: Base key sizes on the hash size, not state size.
Mark Wooding [Sat, 12 Oct 2019 20:49:48 +0000 (21:49 +0100)]
symm/hmac-def.h: Base key sizes on the hash size, not state size.

Back in c850c0da81ad9f72315f8e6e26bdfbd98daf9d89 (`Support HMAC mode for
hash functions which need to store more state than the hash output
size'), there was only a single key-size specification shared between
HMAC and NMAC.  This nearly makes sense, because an NMAC key is a /pair/
of hash states, for the outer and inner hash applications, but the key
size at this time was only the size of /single/ state.  At this time,
only HMAC had a `gcmac' definition, so the key size had to be right for
HMAC, which may explain this, but it seems rather unconvincing.

Later, 2a62e96dc602cf6ec0e5a489b18262ae6abb29be (`Provide correct key
sizes for NMAC, HMAC and SSLMAC') splits this single key-size
specification into three, and adds a `gcmac' definition for the NMAC
variant.  The new key-size specification for NMAC correctly reports
double the state size, and uses `KSZ_SET' rather than `KSZ_ANY'.  I
think the other two should have been based on the hash size at this
point, but weren't: I suspect that I just propagated the previous
mistake without thinking about it very hard.

Even later, c148759dc94794db3faa3ed556583b65d40ae799 (`symm/hmac-def.h:
Report key sizes as 16-bit quantities') changes the key-size
specifications to use the new 16-bit format, but shies away from fixing
the HMAC and SSLMAC key sizes.

I'm now going to bite this bullet and declare that the HMAC and SSLMAC
key sizes should be based on the hash size.  This changes the default
key sizes for: MD2, SHA224, SHA384, SHA512/224, SHA512/256, SHA3 (all
variants), and Whirlpool256.  I think it's probably a mistake to have
used any of these hash functions with HMAC: MD2 is slow and weak; the
SHA2 variants are all worse than truncating SHA256 or SHA512; similarly,
using Whirlpool256 rather than truncating plain Whirlpool is
bizarre (and Whirlpool is slow and rarely used anyway); and SHA3 is just
a terrible fit for HMAC, and you should be using KMAC instead.

This will break interoperability in `catcrypt' if HMAC based on any of
the above hash functions is used as the `mac'.  TrIPE (sensibly) doesn't
use the default key size, so isn't affected by this change.

3 years agomath/mpgen, symm/multigen: Fix the various build scripts for Python 3.
Mark Wooding [Fri, 4 Oct 2019 14:43:27 +0000 (15:43 +0100)]
math/mpgen, symm/multigen: Fix the various build scripts for Python 3.

  * Put parentheses around `print' arguments.

  * Write `raise EXC(VALUE)' rather than `raise EXC, VALUE' to raise
    exceptions.

  * Cope with `xrange' being renamed to `range' in Python 3.

  * Cope with `long' not being a type name in Python 3.

  * Cope with `execfile' not being available in Python 3.

  * Cope with function-object attribute names being renamed in Python 3.

  * Cope with `StringIO' being in `io' rather than `cStringIO' in Python
    3, and with `StringIO.reset' not being available any more.

  * Cope with `itertools.izip' not being available in Python 3.

  * Cope with `OBJ.next' not being available in Python 3.

  * Use an unpleasant hack to inject metaclasses, because the official
    syntax is so different between the two versions.

3 years agosymm/multigen (SequenceTemplate): Don't try to pass `seq' initarg.
Mark Wooding [Tue, 8 Oct 2019 11:09:48 +0000 (12:09 +0100)]
symm/multigen (SequenceTemplate): Don't try to pass `seq' initarg.

I have no idea how this ever worked.  Certainly Python 3 complains, but
Python 2 should have done too.

3 years agokey/key-io.c: Add low-level `key_mergeline' and `key_extractline' functions.
Mark Wooding [Thu, 3 Oct 2019 13:33:36 +0000 (14:33 +0100)]
key/key-io.c: Add low-level `key_mergeline' and `key_extractline' functions.

Python 3 doesn't use C `stdio' streams.  In order to integrate properly,
we need to provide some other way to do I/O of key material.  Introduce
new functions which work in terms of lines in the keyring, which a
Python wrapper can transfer between us and a Python file.

3 years agosymm/strobe.c: Implement Hamburg's STROBE framework.
Mark Wooding [Sun, 25 Nov 2018 11:40:32 +0000 (11:40 +0000)]
symm/strobe.c: Implement Hamburg's STROBE framework.

3 years agosymm/keccak1600.c: Add new function to overwrite the state.
Mark Wooding [Sat, 17 Nov 2018 22:32:32 +0000 (22:32 +0000)]
symm/keccak1600.c: Add new function to overwrite the state.

This is somewhat more useful for implementing duplex-style
constructions.

3 years agorand/rand.c: More dynamic assertions converted to use `STATIC_ASSERT'.
Mark Wooding [Thu, 12 Dec 2019 19:11:47 +0000 (19:11 +0000)]
rand/rand.c: More dynamic assertions converted to use `STATIC_ASSERT'.

3 years agoMerge branch '2.5.x'
Mark Wooding [Sat, 9 May 2020 19:55:40 +0000 (20:55 +0100)]
Merge branch '2.5.x'

* 2.5.x:
  Release 2.5.2.
  base/regdump.c: Be helpful about VFP/NEON registers before `regdump_init'.
  base/regdump.h (ARM32, ARM64): Properly parenthesize `_regfmt' arguments.
  base/regdump.c: Dump ARM VFP/NEON registers with the correct source tag.
  debian/catacomb2.symbols: Bump versions for fixed functions.
  Release 2.4.5.
  math/group-parse.c (group-parse): Parse binary-group descriptions.
  math/group-parse.c: Fix copyright notice.
  *.c: Check for ARM64 SIMD before using the accelerated code.
  base/dispatch.c: Recognize `CPUFEAT_ARM_NEON' as requesting ARM64 SIMD.
  symm/t/chacha: Missing test from RFC8439.
  math/t/{mpx,mpmont}: Add some extra tests for flushing out `mul4' bugs.
  math/mpx-mul4-*: Test the `...zc' variants too.
  math/Makefile.am, symm/Makefile.am: Use `--no-install' on oddball tests.
  progs/pixie.c: Don't crash when trying to set an empty passphrase.
  configure.ac, vars.am: Use host-specific link options for test programs.

3 years agoRelease 2.5.2. 2.5.2
Mark Wooding [Sat, 9 May 2020 19:51:15 +0000 (20:51 +0100)]
Release 2.5.2.

3 years agobase/regdump.c: Be helpful about VFP/NEON registers before `regdump_init'.
Mark Wooding [Thu, 7 Nov 2019 01:31:29 +0000 (01:31 +0000)]
base/regdump.c: Be helpful about VFP/NEON registers before `regdump_init'.

On ARM32 (only), you really /must/ call `regdump_init' before dumping
VFP/NEON registers because otherwise there's no way to tell that they
need saving -- so they aren't and an important pointer is left null.

Rather than crashing, detect this and print a message explaining why the
register can't be dumped.

3 years agobase/regdump.h (ARM32, ARM64): Properly parenthesize `_regfmt' arguments.
Mark Wooding [Thu, 7 Nov 2019 01:34:52 +0000 (01:34 +0000)]
base/regdump.h (ARM32, ARM64): Properly parenthesize `_regfmt' arguments.

3 years agobase/regdump.c: Dump ARM VFP/NEON registers with the correct source tag.
Mark Wooding [Thu, 7 Nov 2019 01:30:41 +0000 (01:30 +0000)]
base/regdump.c: Dump ARM VFP/NEON registers with the correct source tag.

Otherwise you get an assertion failure from `regwd'.

3 years agodebian/catacomb2.symbols: Bump versions for fixed functions.
Mark Wooding [Sat, 9 May 2020 17:24:48 +0000 (18:24 +0100)]
debian/catacomb2.symbols: Bump versions for fixed functions.

3 years agoMerge branch '2.4.x' into 2.5.x
Mark Wooding [Sat, 9 May 2020 19:39:18 +0000 (20:39 +0100)]
Merge branch '2.4.x' into 2.5.x

* 2.4.x:
  Release 2.4.5.
  math/group-parse.c (group-parse): Parse binary-group descriptions.
  math/group-parse.c: Fix copyright notice.
  *.c: Check for ARM64 SIMD before using the accelerated code.
  base/dispatch.c: Recognize `CPUFEAT_ARM_NEON' as requesting ARM64 SIMD.
  symm/t/chacha: Missing test from RFC8439.
  math/t/{mpx,mpmont}: Add some extra tests for flushing out `mul4' bugs.
  math/mpx-mul4-*: Test the `...zc' variants too.
  math/Makefile.am, symm/Makefile.am: Use `--no-install' on oddball tests.
  progs/pixie.c: Don't crash when trying to set an empty passphrase.
  configure.ac, vars.am: Use host-specific link options for test programs.

3 years agoRelease 2.4.5. 2.4.5
Mark Wooding [Sat, 9 May 2020 16:58:16 +0000 (17:58 +0100)]
Release 2.4.5.

3 years agomath/group-parse.c (group-parse): Parse binary-group descriptions.
Mark Wooding [Wed, 20 Nov 2019 18:37:01 +0000 (18:37 +0000)]
math/group-parse.c (group-parse): Parse binary-group descriptions.

I don't recommend them, but their omission is a bug.

3 years agomath/group-parse.c: Fix copyright notice.
Mark Wooding [Wed, 20 Nov 2019 18:36:16 +0000 (18:36 +0000)]
math/group-parse.c: Fix copyright notice.

Huh.  I guess I cloned this from TrIPE then.

For the record: this file has actually been subject to LGPL2+ since its
incorporation into Catacomb.

3 years ago*.c: Check for ARM64 SIMD before using the accelerated code.
Mark Wooding [Fri, 15 Nov 2019 17:09:01 +0000 (17:09 +0000)]
*.c: Check for ARM64 SIMD before using the accelerated code.

I don't expect ARM64 processors to omit the SIMD instructions, but it's
convenient to have a way to inhibit the accelerated code (e.g., for
performance measurement).

3 years agobase/dispatch.c: Recognize `CPUFEAT_ARM_NEON' as requesting ARM64 SIMD.
Mark Wooding [Fri, 15 Nov 2019 17:06:46 +0000 (17:06 +0000)]
base/dispatch.c: Recognize `CPUFEAT_ARM_NEON' as requesting ARM64 SIMD.

The original ARMv8 spec describes the advanced SIMD instructions as
mandatory, but there's a feature flag for them, so I guess that there
might be processors which don't support them.

3 years agosymm/t/chacha: Missing test from RFC8439.
Mark Wooding [Mon, 4 Nov 2019 13:33:03 +0000 (13:33 +0000)]
symm/t/chacha: Missing test from RFC8439.

3 years agomath/t/{mpx,mpmont}: Add some extra tests for flushing out `mul4' bugs.
Mark Wooding [Sat, 9 Nov 2019 00:41:46 +0000 (00:41 +0000)]
math/t/{mpx,mpmont}: Add some extra tests for flushing out `mul4' bugs.

3 years agomath/mpx-mul4-*: Test the `...zc' variants too.
Mark Wooding [Mon, 4 Nov 2019 11:59:28 +0000 (11:59 +0000)]
math/mpx-mul4-*: Test the `...zc' variants too.

3 years agomath/Makefile.am, symm/Makefile.am: Use `--no-install' on oddball tests.
Mark Wooding [Sat, 9 May 2020 13:24:15 +0000 (14:24 +0100)]
math/Makefile.am, symm/Makefile.am: Use `--no-install' on oddball tests.

There are a small number of test programs -- mostly for unsaturated
bignum code built specially to test unusual piece sizes -- and these
should be built with `-no-install' or whataver just like the normal test
programs.

3 years agoprogs/pixie.c: Don't crash when trying to set an empty passphrase.
Mark Wooding [Sat, 26 Oct 2019 14:51:22 +0000 (15:51 +0100)]
progs/pixie.c: Don't crash when trying to set an empty passphrase.

3 years agoconfigure.ac, vars.am: Use host-specific link options for test programs.
Mark Wooding [Sat, 9 May 2020 12:26:13 +0000 (13:26 +0100)]
configure.ac, vars.am: Use host-specific link options for test programs.

It turns out that `libtool' spams an annoying warning message to the
terminal every time you call it with `-no-install' on a Windowsish or
Mac OSish system.  Since this is just intended to be an optimization and
developer-convenience feature, wind it down to `-no-fast-install' on the
affected platforms so as not to provoke these really annoying messages.

3 years agoMerge branch '2.5.x'
Mark Wooding [Wed, 6 May 2020 09:18:58 +0000 (10:18 +0100)]
Merge branch '2.5.x'

* 2.5.x:
  vars.am: Don't build the test programs for installation.

3 years agoMerge branch '2.4.x' into 2.5.x
Mark Wooding [Wed, 6 May 2020 09:18:44 +0000 (10:18 +0100)]
Merge branch '2.4.x' into 2.5.x

* 2.4.x:
  vars.am: Don't build the test programs for installation.

3 years agovars.am: Don't build the test programs for installation.
Mark Wooding [Wed, 6 May 2020 09:16:01 +0000 (10:16 +0100)]
vars.am: Don't build the test programs for installation.

Most importantly, this makes them much easier to attach a debugger to,
because the actual executables are now where you expect, and you don't
have to write ridiculous runes involving `../libtool --mode=execute
...'.

Also, this makes the actual linking step somewhat faster.

4 years agobase/dispatch-x86ish.S: Fix build failure from incompetent cherry-pick.
Mark Wooding [Fri, 27 Mar 2020 17:19:00 +0000 (17:19 +0000)]
base/dispatch-x86ish.S: Fix build failure from incompetent cherry-pick.

The `SP' register-name macro used in 25f3ce6... comes from the future.
Fortunately, we don't actually need it here.

4 years agomath/f25519.c: Fix spelling of `weird'.
Mark Wooding [Fri, 27 Mar 2020 17:09:12 +0000 (17:09 +0000)]
math/f25519.c: Fix spelling of `weird'.

4 years agobase/dispatch.c, etc.: Replace inline assembler for the `rdrand' fix.
Mark Wooding [Tue, 29 Oct 2019 18:59:32 +0000 (18:59 +0000)]
base/dispatch.c, etc.: Replace inline assembler for the `rdrand' fix.

4 years agoMerge branch '2.5.x'
Mark Wooding [Mon, 16 Dec 2019 17:21:25 +0000 (17:21 +0000)]
Merge branch '2.5.x'

* 2.5.x:
  debian/catacomb2.symbols: Bump versions for fixed functions.
  rand/rand.c: Mix the pool key in `rand_gate' and `rand_stretch'.
  rand/lcrand.c: Swap flags and max so generator not advertised as strong.
  pub/dh-kcdsa.c: Free the correct factor.
  math/limlee.c: Don't leak the factor vector on overall failure.
  math/limlee.c: Handle an abort from `pgen' correctly.
  math/pgen.c: Don't free the tester if it's not set up.
  math/ec-exp.h: Fix segfault when base point is at infinity.
  key/key-data.c (key_copydata): Fix catastrophic bug.
  key/key-data.c (key_split): Fix long-standing reference leak.
  key/key-misc.c (key_bytag): Don't give up because a by-id search fails.
  base/dispatch.c, etc.: Check that `rdrand' works.

4 years agodebian/catacomb2.symbols: Bump versions for fixed functions.
Mark Wooding [Mon, 16 Dec 2019 16:48:01 +0000 (16:48 +0000)]
debian/catacomb2.symbols: Bump versions for fixed functions.

I didn't do this for the 2.4.x branch because there's no way to say
`2.4.x with x > 4 or 2.5.x with x > 1'.  But I can be sure that all
releases beyond 2.5.1 will have the fixes.

There's no version-bump for the `rdrand' fix.  I'm not leaning on it
very hard.

4 years agoMerge branch '2.4.x' into 2.5.x
Mark Wooding [Mon, 16 Dec 2019 17:20:15 +0000 (17:20 +0000)]
Merge branch '2.4.x' into 2.5.x

* 2.4.x:
  rand/rand.c: Mix the pool key in `rand_gate' and `rand_stretch'.
  rand/lcrand.c: Swap flags and max so generator not advertised as strong.
  pub/dh-kcdsa.c: Free the correct factor.
  math/limlee.c: Don't leak the factor vector on overall failure.
  math/limlee.c: Handle an abort from `pgen' correctly.
  math/pgen.c: Don't free the tester if it's not set up.
  math/ec-exp.h: Fix segfault when base point is at infinity.
  key/key-data.c (key_copydata): Fix catastrophic bug.
  key/key-data.c (key_split): Fix long-standing reference leak.
  key/key-misc.c (key_bytag): Don't give up because a by-id search fails.
  base/dispatch.c, etc.: Check that `rdrand' works.

4 years agorand/rand.c: Mix the pool key in `rand_gate' and `rand_stretch'.
Mark Wooding [Thu, 12 Dec 2019 19:12:26 +0000 (19:12 +0000)]
rand/rand.c: Mix the pool key in `rand_gate' and `rand_stretch'.

Back in commit d6fab4f6ae209afd6799a2974ce2849123965170, I rearranged
the cryptography to use plain SHA256 rather than RIPEMD160-HMAC for
determining the cipher key for churning the generator state.

I also managed to remove all the points at which the key actually
influences the behaviour of the generator!

This was four years ago, and I can't remember exactly why, but my guess
is that the key was previously inserted as part of `rmd160_macinit',
which was replaced by the unheyed `HASH_INIT' function.

4 years agorand/lcrand.c: Swap flags and max so generator not advertised as strong.
Mark Wooding [Fri, 15 Nov 2019 19:37:29 +0000 (19:37 +0000)]
rand/lcrand.c: Swap flags and max so generator not advertised as strong.

Oh, dear.  This isn't good.

Even worse, this means that `max' was advertised as zero, so the outputs
have been biased.

4 years agopub/dh-kcdsa.c: Free the correct factor.
Mark Wooding [Wed, 23 Oct 2019 03:10:27 +0000 (04:10 +0100)]
pub/dh-kcdsa.c: Free the correct factor.

4 years agomath/limlee.c: Don't leak the factor vector on overall failure.
Mark Wooding [Thu, 14 Nov 2019 20:17:58 +0000 (20:17 +0000)]
math/limlee.c: Don't leak the factor vector on overall failure.

The `done' function doesn't know whether we succeeded or failed, so it
prepares the factor vector for output regardless.  In `limlee', if we
don't have a result, then release the factors.

4 years agomath/limlee.c: Handle an abort from `pgen' correctly.
Mark Wooding [Thu, 14 Nov 2019 19:53:27 +0000 (19:53 +0000)]
math/limlee.c: Handle an abort from `pgen' correctly.

The `llgen' function just tries again if `pgen' reports an abort.  This
is entirely contrary to the intend of the `PGEN_ABORT' protocol, so I've
no idea why I thought this was a good idea.

Instead, leave the prime slot null (because adding a return code to the
`pgen' callback breaks the API), and arrange for the caller to notice
and clean up.  This is annoyingly because there may be an `mpmul' in
progress.

4 years agomath/pgen.c: Don't free the tester if it's not set up.
Mark Wooding [Thu, 14 Nov 2019 19:46:53 +0000 (19:46 +0000)]
math/pgen.c: Don't free the tester if it's not set up.

The problem flow is this:

  * The stepper reports a candidate (`p' is `P_STEP', and `proc' returns
    `PGEN_TRY').

  * We decide to (a) report an event (set `A_EVENT' in `act'), and (b)
    initialize the tester (set `p = P_TEST', `proc = test', and `rq =
    PGEN_BEGIN'.

  * We call the event handler, but it returns `PGEN_ABORT'.  We notice
    that `p == P_TEST', and set `A_ENDTEST'.

  * This causes us to call `test' with `PGEN_DONE'.  Alas, the tester
    hasn't been initialized, because we haven't actually called it with
    `PGEN_BEGIN' yet.  Result: segfault.

We can notice this because `rq == PGEN_BEGIN': don't set `A_ENDTEST'
if this is the case.

4 years agomath/ec-exp.h: Fix segfault when base point is at infinity.
Mark Wooding [Fri, 18 Oct 2019 21:45:01 +0000 (22:45 +0100)]
math/ec-exp.h: Fix segfault when base point is at infinity.

4 years agokey/key-data.c (key_copydata): Fix catastrophic bug.
Mark Wooding [Thu, 21 Nov 2019 17:43:51 +0000 (17:43 +0000)]
key/key-data.c (key_copydata): Fix catastrophic bug.

The fundamental problem is that the key-encoding test has the wrong
sense.  The result is that we end up (only) trying to iterate over non-
structured keys, which results in an assertion failure.

Also, switch things around so that we check the encoding type before
checking the flags.

4 years agokey/key-data.c (key_split): Fix long-standing reference leak.
Mark Wooding [Tue, 8 Oct 2019 19:23:01 +0000 (20:23 +0100)]
key/key-data.c (key_split): Fix long-standing reference leak.

4 years agokey/key-misc.c (key_bytag): Don't give up because a by-id search fails.
Mark Wooding [Sat, 26 Oct 2019 14:38:25 +0000 (15:38 +0100)]
key/key-misc.c (key_bytag): Don't give up because a by-id search fails.

This came to my attention when searching for a key of type `ec' didn't
work because it looks like a hex number.  This obviously sucks.

4 years agobase/dispatch.c, etc.: Check that `rdrand' works.
Mark Wooding [Wed, 30 Oct 2019 00:45:11 +0000 (00:45 +0000)]
base/dispatch.c, etc.: Check that `rdrand' works.

When probing for `rdrand', check to make sure that it doesn't just
return the same thing every time, and that it can reasonably well make
progress.  We check that up to five 32-bit samples are not all the same,
which will mistakenly mark a working CPU as defective with probability
2^-128.

It seems that some processors will return a constant value from `rdrand'
but set the carry flag to indicate that it's properly random anyway.
See

https://arstechnica.com/gadgets/2019/10/how-a-months-old-amd-microcode-bug-destroyed-my-weekend/

as an example.

4 years agoMerge branch '2.5.x'
Mark Wooding [Tue, 8 Oct 2019 10:48:32 +0000 (11:48 +0100)]
Merge branch '2.5.x'

* 2.5.x:
  key/key-io.c: Mark `exptime' function `static'.
  key/key-io.c (key_new): Don't leak attribute `sym_table' on error.

4 years agodebian/.gitignore: Ignore `catacomb-data' directory.
Mark Wooding [Tue, 8 Oct 2019 10:47:53 +0000 (11:47 +0100)]
debian/.gitignore: Ignore `catacomb-data' directory.

4 years agoMerge branch '2.4.x' into 2.5.x
Mark Wooding [Tue, 8 Oct 2019 10:45:56 +0000 (11:45 +0100)]
Merge branch '2.4.x' into 2.5.x

* 2.4.x:
  key/key-io.c: Mark `exptime' function `static'.
  key/key-io.c (key_new): Don't leak attribute `sym_table' on error.

4 years agokey/key-io.c: Mark `exptime' function `static'.
Mark Wooding [Tue, 8 Oct 2019 10:44:19 +0000 (11:44 +0100)]
key/key-io.c: Mark `exptime' function `static'.

I think it was always meant to be so.  It doesn't have a prefix, and
isn't used anywhere else.  Leaking it into the client namespace was just
a mistake.

4 years agokey/key-io.c (key_new): Don't leak attribute `sym_table' on error.
Mark Wooding [Tue, 8 Oct 2019 10:36:34 +0000 (11:36 +0100)]
key/key-io.c (key_new): Don't leak attribute `sym_table' on error.

This is safe: `insert' doesn't do anything with `k->a'.

4 years agoMerge branch '2.5.x'
Mark Wooding [Tue, 1 Oct 2019 20:43:41 +0000 (21:43 +0100)]
Merge branch '2.5.x'

* 2.5.x:
  catacomb.pc.in: Update dependency on mLib.

4 years agoMerge branch '2.4.x' into 2.5.x
Mark Wooding [Tue, 1 Oct 2019 20:43:29 +0000 (21:43 +0100)]
Merge branch '2.4.x' into 2.5.x

* 2.4.x:
  catacomb.pc.in: Update dependency on mLib.

4 years agocatacomb.pc.in: Update dependency on mLib.
Mark Wooding [Tue, 1 Oct 2019 11:54:27 +0000 (12:54 +0100)]
catacomb.pc.in: Update dependency on mLib.

The most recent relevant change appears to be

    commit 4d845619c3f21fe19dd7f7b16815281b34de9e33
    Author: Mark Wooding <mdw@distorted.org.uk>
    Date:   Sat, 26 May 2018 23:31:00 +0100

codec/url.c: Always encode whitespace characters.

Vertical whitespace is obviously bad, so this is a longstanding bug; but
all whitespace should really be escaped.

which was first released as part of 2.3.0.

4 years agodebian/changelog: Lower placeholder version for benefit of `pkg-config'.
Mark Wooding [Tue, 1 Oct 2019 20:41:20 +0000 (21:41 +0100)]
debian/changelog: Lower placeholder version for benefit of `pkg-config'.

Because it doesn't implement the convention that `~' sorts before
anything else, even though that's a defined part of the RPM
version-number system which it claims to implement.

4 years agodebian/changelog: Prepare for next release.
Mark Wooding [Mon, 30 Sep 2019 01:19:12 +0000 (02:19 +0100)]
debian/changelog: Prepare for next release.

4 years agosymm/keccak1600.c (keccak1600_extract): Eliminate intermediate state buffer.
Mark Wooding [Sat, 17 Nov 2018 21:08:11 +0000 (21:08 +0000)]
symm/keccak1600.c (keccak1600_extract): Eliminate intermediate state buffer.

Instead, introduce a handy bitmap which identifies which lanes need
complementing and do the whole thing in the loop.

4 years agorand/lcrand.c, rand/rand.c: Replace dynamic assertions with static ones.
Mark Wooding [Sun, 29 Sep 2019 14:44:26 +0000 (15:44 +0100)]
rand/lcrand.c, rand/rand.c: Replace dynamic assertions with static ones.

This adds a dependency on mLib 2.4.1.

4 years agobase/keysz.c: Delete trailing `,' in enum.
Mark Wooding [Sat, 28 Sep 2019 01:05:48 +0000 (02:05 +0100)]
base/keysz.c: Delete trailing `,' in enum.

4 years agomath/mpx.c: Fix function name in header comment.
Mark Wooding [Sat, 28 Sep 2019 01:05:27 +0000 (02:05 +0100)]
math/mpx.c: Fix function name in header comment.

4 years agoMerge branch '2.5.x'
Mark Wooding [Sun, 29 Sep 2019 17:42:35 +0000 (18:42 +0100)]
Merge branch '2.5.x'

* 2.5.x:
  Release 2.5.1.
  Release 2.4.4.
  debian/: Ship correct symbols files.
  debian/: Bump to Debhelper 10.
  debian/rules: Prefix `dh' options with `-O' to prevent sadness.

4 years agoRelease 2.5.1. 2.5.1
Mark Wooding [Sun, 29 Sep 2019 16:57:10 +0000 (17:57 +0100)]
Release 2.5.1.

4 years agoMerge branch '2.4.x' into 2.5.x
Mark Wooding [Sun, 29 Sep 2019 16:52:39 +0000 (17:52 +0100)]
Merge branch '2.4.x' into 2.5.x

* 2.4.x:
  Release 2.4.4.
  debian/: Ship correct symbols files.
  debian/: Bump to Debhelper 10.
  debian/rules: Prefix `dh' options with `-O' to prevent sadness.

Conflicts:
debian/changelog (take both)
debian/control

Also fix debian/catacomb2.symbols to add new symbols; bump `pgen_primep'
to 2.5.0 to ensure that the Baillie--PSW test is used.

4 years agoRelease 2.4.4. 2.4.4
Mark Wooding [Sun, 29 Sep 2019 14:58:57 +0000 (15:58 +0100)]
Release 2.4.4.

4 years agodebian/: Ship correct symbols files.
Mark Wooding [Sat, 28 Sep 2019 00:21:53 +0000 (01:21 +0100)]
debian/: Ship correct symbols files.

4 years agodebian/: Bump to Debhelper 10.
Mark Wooding [Sun, 29 Sep 2019 14:56:38 +0000 (15:56 +0100)]
debian/: Bump to Debhelper 10.

4 years agodebian/rules: Prefix `dh' options with `-O' to prevent sadness.
Mark Wooding [Sun, 29 Sep 2019 15:39:13 +0000 (16:39 +0100)]
debian/rules: Prefix `dh' options with `-O' to prevent sadness.

4 years agoMostly abolish inline assembler code in favour of dedicated files.
Mark Wooding [Thu, 26 Sep 2019 11:11:50 +0000 (12:11 +0100)]
Mostly abolish inline assembler code in favour of dedicated files.

Move the fancy feature probing from `dispatch.c'.  This makes it easier to
understand because it's not covered in `%' sigils and backwards, and
also simplifies things because we have better machinery for papering
over the differences between 32- and 64-bit instruction sets.

Also move the `rdrand' code from `rand.c'.  This makes things
significantly more complicated because it calls back into C, but it does
improve availability of a security feature, so that's good.

That leaves only a use of `rdtsc' in `perftest.c', which is hardly
critical, and the `rbit' in the ARM64 `gcm.c' code, which has a slightly
slower portable alternative.

4 years agobase/regdump.h: Add missing `regfmt.' definitions for `eflags', `rflags'.
Mark Wooding [Thu, 26 Sep 2019 12:50:21 +0000 (13:50 +0100)]
base/regdump.h: Add missing `regfmt.' definitions for `eflags', `rflags'.

Not having these causes GNU `as' to segfault, which is a little
alarming.

4 years agobase/regdump.h: Add missing `F(...)' around `callext' targets.
Mark Wooding [Thu, 26 Sep 2019 12:49:45 +0000 (13:49 +0100)]
base/regdump.h: Add missing `F(...)' around `callext' targets.

Probably broke Windows.

4 years agoMerge branch '2.4.x' into 2.5.x
Mark Wooding [Fri, 27 Sep 2019 00:25:58 +0000 (01:25 +0100)]
Merge branch '2.4.x' into 2.5.x

* 2.4.x:
  base/dispatch.c: Check for XMM registers after CPUID probe.
  rand/noise.c: Fix foolish bug in the `getentropy' code.

4 years agobase/dispatch.c: Check for XMM registers after CPUID probe.
Mark Wooding [Thu, 26 Sep 2019 11:09:10 +0000 (12:09 +0100)]
base/dispatch.c: Check for XMM registers after CPUID probe.

`fxsave' isn't universally available, but if CPUID is reporting that XMM
instructions are available, we can definitely use it.

4 years agorand/noise.c: Fix foolish bug in the `getentropy' code.
Mark Wooding [Thu, 26 Sep 2019 16:03:46 +0000 (17:03 +0100)]
rand/noise.c: Fix foolish bug in the `getentropy' code.

I've probably never built this before. :-/

4 years agoRelease 2.5.0. 2.5.0
Mark Wooding [Sat, 21 Sep 2019 20:29:19 +0000 (21:29 +0100)]
Release 2.5.0.

4 years agoMerge branch '2.4.x'
Mark Wooding [Sat, 21 Sep 2019 20:18:12 +0000 (21:18 +0100)]
Merge branch '2.4.x'

* 2.4.x:
  Release 2.4.3.
  debian/control: Don't require `valgrind' on `armel'.
  progs/perftest.c: Document the `-n' option for `enc' and `hash'.
  key/key-misc.c: Fix bogus parentheses in macro.
  symm/rijndael-arm64-crypto.S: Fix bogus element-to-GP move.
  symm/chacha.c: Set the correct nonce size for `xchachaNN'.
  symm/idea.c: Fix key-size descriptor.

4 years agoRelease 2.4.3. 2.4.3
Mark Wooding [Sat, 21 Sep 2019 16:44:24 +0000 (17:44 +0100)]
Release 2.4.3.

4 years agodebian/control: Don't require `valgrind' on `armel'.
Mark Wooding [Sat, 21 Sep 2019 17:18:20 +0000 (18:18 +0100)]
debian/control: Don't require `valgrind' on `armel'.

It isn't there.  We must manage without.

4 years agoprogs/perftest.c: Document the `-n' option for `enc' and `hash'.
Mark Wooding [Sat, 10 Nov 2018 13:55:14 +0000 (13:55 +0000)]
progs/perftest.c: Document the `-n' option for `enc' and `hash'.

(cherry picked from commit 6fbaed9534c9c100ed4c2c45c4a5b3e95142c888)

4 years agokey/key-misc.c: Fix bogus parentheses in macro.
Mark Wooding [Wed, 18 Sep 2019 17:35:34 +0000 (18:35 +0100)]
key/key-misc.c: Fix bogus parentheses in macro.

The old, bogus behaviour was that it would report `KERR_READONLY' if the
keyring was neither open for writing, /nor/ modified.  I think this is
relatively benign, but still well deserving of fixing.

Spotted by Clang.

(cherry picked from commit 924c7057076a23e322d40693912633dc546867e9)

4 years agosymm/rijndael-arm64-crypto.S: Fix bogus element-to-GP move.
Mark Wooding [Wed, 18 Sep 2019 17:24:49 +0000 (18:24 +0100)]
symm/rijndael-arm64-crypto.S: Fix bogus element-to-GP move.

Spotted by Clang's assembler.  GAS is obviously too lenient.

(cherry picked from commit cead42fc5cf5ff8c1c13f123e4c002077b42f6cd)

4 years agosymm/chacha.c: Set the correct nonce size for `xchachaNN'.
Mark Wooding [Thu, 15 Aug 2019 17:16:02 +0000 (18:16 +0100)]
symm/chacha.c: Set the correct nonce size for `xchachaNN'.

Oops.

(cherry picked from commit 9acc7e10f1da03be55e3bc2cdcbbd5775253e3d0)

4 years agosymm/idea.c: Fix key-size descriptor.
Mark Wooding [Fri, 9 Nov 2018 22:44:40 +0000 (22:44 +0000)]
symm/idea.c: Fix key-size descriptor.

Missing terminator.  Oops.

(cherry picked from commit 9c22e9e0d174ee0c1e649464755568fe61c0e949)

4 years agoprogs/Makefile.am: Don't link `pixie' against the main `libcatacomb.la'.
Mark Wooding [Wed, 18 Sep 2019 18:47:47 +0000 (19:47 +0100)]
progs/Makefile.am: Don't link `pixie' against the main `libcatacomb.la'.

It doesn't actually do any cryptography.  Instead, Just pick out the
`base' and `key' libraries which contain its (very light) requirements.

This is the conclusion I reached following an Android ARM64 build
failure caused by lack of maths functions.

4 years agokey/key-misc.c: Fix bogus parentheses in macro.
Mark Wooding [Wed, 18 Sep 2019 17:35:34 +0000 (18:35 +0100)]
key/key-misc.c: Fix bogus parentheses in macro.

The old, bogus behaviour was that it would report `KERR_READONLY' if the
keyring was neither open for writing, /nor/ modified.  I think this is
relatively benign, but still well deserving of fixing.

Spotted by Clang.

4 years agosymm/rijndael-arm64-crypto.S: Fix bogus element-to-GP move.
Mark Wooding [Wed, 18 Sep 2019 17:24:49 +0000 (18:24 +0100)]
symm/rijndael-arm64-crypto.S: Fix bogus element-to-GP move.

Spotted by Clang's assembler.  GAS is obviously too lenient.