catacomb
7 years agoMerge branch 'master' of git.distorted.org.uk:~mdw/publish/public-git/catacomb
Mark Wooding [Mon, 13 Jun 2016 21:00:00 +0000 (22:00 +0100)]
Merge branch 'master' of git.distorted.org.uk:~mdw/publish/public-git/catacomb

* 'master' of git.distorted.org.uk:~mdw/publish/public-git/catacomb: (53 commits)
  rand/rand.c (rdrand_quick): Improve the loop.
  configure.ac, rand/noise.c: Get high-res time from `clock_gettime'.
  rand/noise.c: Make the high-res timer function be a bit more abstract.
  configure.ac, Makefile.am: Collect libs only needed by Catcomb itself.
  Makefile.am: Include $(PIXIE_LIBS) in the main library.
  rand/noise.c (noise_devrandom): Use OpenBSD system call `getentropy'.
  rand/noise.c (noise_devrandom): Use new Linux system call `getrandom'.
  rand/noise.c (noise_devrandom): Handle Linux's broken `/dev/urandom'.
  rand/noise.c (noise_devrandom): Refactor internals.
  src/noise.c: Make `bitcount' table be static and constant.
  rand/rand.c: Add support for x86 `RDRAND' instruction in `rand_quick'.
  base/dispatch.[ch]: Detect availability of the x86 `RDRAND' instruction.
  rand/rand.[ch]: Add external `rand_quick' function.
  rand/: Secure `rand' generator against fork problems.
  Release 2.2.2.
  math/mp-arith.c (mp_testbit): Want nonstrict comparison for bounds check.
  symm/salsa20-arm-neon.S: Mark the final-permutation stores as word-aligned.
  symm/: Add ARM NEON implementations of ChaCha and Salsa20.
  symm/{salsa20,chacha}-x86ish-sse2.S: Use numeric labels for internal loops.
  symm/salsa20-x86ish-sse2.S: Fix stray `##' comment to be `//'.
  ...

Conflicts:
debian/changelog

7 years agorand/rand.c (rdrand_quick): Improve the loop.
Mark Wooding [Mon, 6 Jun 2016 10:01:46 +0000 (11:01 +0100)]
rand/rand.c (rdrand_quick): Improve the loop.

The `RDRAND' instruction can fail, leaving carry clear.  Previously, I
just exposed the carry flag in a register (with `SETC'), and looped
around in C.

Rewrite the loop in assembler.  This is makes the flow cleaner, and
(coincidentally) avoids a dependency on the `SETcc' instructions (though
if I thought a processor might have `RDRAND' and not `SETcc', I wouldn't
have written the original code the way I did).  But the main benefit is
that I don't have nightmares about seeing

...; setc al; test al, al; ...

sequences any more.  There's still the issue of `i' being tested for
zero twice, but I don't think I can fix that without resorting to `asm
goto', and that has its own problems.

7 years agoconfigure.ac, rand/noise.c: Get high-res time from `clock_gettime'.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
configure.ac, rand/noise.c: Get high-res time from `clock_gettime'.

If it's available.

7 years agorand/noise.c: Make the high-res timer function be a bit more abstract.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
rand/noise.c: Make the high-res timer function be a bit more abstract.

You can tell that there's more coming from the indentation.  But there
shouldn't be any real change at this stage.

7 years agoconfigure.ac, Makefile.am: Collect libs only needed by Catcomb itself.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
configure.ac, Makefile.am: Collect libs only needed by Catcomb itself.

Currently there aren't any, but some may turn up soon.

Oddly, the `pkg-config' machinery already had all the right stuff in it:
it just wasn't being exercised.

7 years agoMakefile.am: Include $(PIXIE_LIBS) in the main library.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
Makefile.am: Include $(PIXIE_LIBS) in the main library.

After all, it needs to be able to contact the pixie.  I guess I've not
had to deal with many stupid systems which hide functions in `-lsocket'
recently.

7 years agorand/noise.c (noise_devrandom): Use OpenBSD system call `getentropy'.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
rand/noise.c (noise_devrandom): Use OpenBSD system call `getentropy'.

If it's available, it does the right thing.  I think.

7 years agorand/noise.c (noise_devrandom): Use new Linux system call `getrandom'.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
rand/noise.c (noise_devrandom): Use new Linux system call `getrandom'.

The new system call has pretty much the right semantics.  If it's
available, then try to use it.  Annoyingly, the syscall isn't supported
in the libc, so we have to do it the hard way.  On the plus side, this
means that the code will work if built on a system with the syscall
defined, and run on one with the right kernel, without introducing a
dependency on the libc.

If it fails because the kernel entropy pool isn't initialized, then
there's no point in messing with the devices because they won't be any
better.  If it fails because the call isn't there, then it proceeds with
other options.

7 years agorand/noise.c (noise_devrandom): Handle Linux's broken `/dev/urandom'.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
rand/noise.c (noise_devrandom): Handle Linux's broken `/dev/urandom'.

On Linux, try to open `/dev/random' and make sure it's readable before
proceeding to `/dev/urandom'.  Generally we want to be reading
`/dev/urandom', but not if it hasn't been initialized properly.

7 years agorand/noise.c (noise_devrandom): Refactor internals.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
rand/noise.c (noise_devrandom): Refactor internals.

The objective is to make adding new ways of collecting high-quality
system entropy easier.

  * Add labels for success and exit, to make sure that whatever we add
    whatever's in the buffer to the pool, and then clear out the buffer.

  * Initialize `fd' to `-1' at the top, and close it on the way out to
    make sure it doesn't leak.

  * Change the main `open' condition to allow something to have opened the
    right file already.

This shouldn't change any observable behaviour, but it will make things
easier in future.

7 years agosrc/noise.c: Make `bitcount' table be static and constant.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/noise.c: Make `bitcount' table be static and constant.

7 years agorand/rand.c: Add support for x86 `RDRAND' instruction in `rand_quick'.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
rand/rand.c: Add support for x86 `RDRAND' instruction in `rand_quick'.

7 years agobase/dispatch.[ch]: Detect availability of the x86 `RDRAND' instruction.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
base/dispatch.[ch]: Detect availability of the x86 `RDRAND' instruction.

7 years agorand/rand.[ch]: Add external `rand_quick' function.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
rand/rand.[ch]: Add external `rand_quick' function.

This is a function which can be called frequently to top up the internal
entropy.

Internally, rename `TIMER' to `QUICK', and call the internal `quick'
function as well as the noise-source timer.  The `quick' core currently
doesn't do anything, but will act as a dispatcher to CPU-specific
entropy sources.

7 years agorand/: Secure `rand' generator against fork problems.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
rand/: Secure `rand' generator against fork problems.

This is fiddlier than it really ought to be.

  * Make the `i' and `irot' members be `unsigned short' to make space
    for a new member.  These members have well-constrained ranges, so
    this is safe.

  * Insert a new `gen' member to keep track of the pool's `generation
    number'.  Arrange that the global generator's generation number is
    initially zero.

  * Invent a new system-specific function `rand_generation' which
    returns a nonzero `generation number', which changes across forks
    and such things.

  * Have the output functions `rand_get' and `rand_getgood' check the
    generation number and force a `rand_gate' if it changes.

  * Arrange for `rand_gate' and `rand_stretch' to feed the generation
    number into the hashing, so that generators with different
    generations behave computationally independently.

7 years agoMerge branch '2.2.x'
Mark Wooding [Sat, 4 Jun 2016 01:15:53 +0000 (02:15 +0100)]
Merge branch '2.2.x'

* 2.2.x:
  Release 2.2.2.
  math/mp-arith.c (mp_testbit): Want nonstrict comparison for bounds check.

7 years agoRelease 2.2.2. 2.2.2
Mark Wooding [Sat, 4 Jun 2016 00:14:08 +0000 (01:14 +0100)]
Release 2.2.2.

7 years agomath/mp-arith.c (mp_testbit): Want nonstrict comparison for bounds check.
Mark Wooding [Fri, 3 Jun 2016 21:25:02 +0000 (22:25 +0100)]
math/mp-arith.c (mp_testbit): Want nonstrict comparison for bounds check.

7 years agosymm/salsa20-arm-neon.S: Mark the final-permutation stores as word-aligned.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
symm/salsa20-arm-neon.S: Mark the final-permutation stores as word-aligned.

This was just an oversight when I was hacking the initial code.

7 years agosymm/: Add ARM NEON implementations of ChaCha and Salsa20.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
symm/: Add ARM NEON implementations of ChaCha and Salsa20.

7 years agosymm/{salsa20,chacha}-x86ish-sse2.S: Use numeric labels for internal loops.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
symm/{salsa20,chacha}-x86ish-sse2.S: Use numeric labels for internal loops.

7 years agosymm/salsa20-x86ish-sse2.S: Fix stray `##' comment to be `//'.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
symm/salsa20-x86ish-sse2.S: Fix stray `##' comment to be `//'.

Not sure how this one slipped through the net.  Oh, well; it didn't
cause any damage.

7 years agoconfigure.ac: Detect plain `arm' as an ARM CPU identifier.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
configure.ac: Detect plain `arm' as an ARM CPU identifier.

For some reason I've not discovered yet, my test machinery shows as
`arm-unknown-linux-gnueabi' rather than `armv7l-unknown-linux-gnueabi',
which inhibits building the fancy CPU-specific code.  This hid a build
failure from my test machinery, which is quite annoying.

7 years agobase/dispatch.c: Missing parens on call to `get_hwcaps'.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
base/dispatch.c: Missing parens on call to `get_hwcaps'.

This is only a problem on ARM hosts, but it breaks the build for
them (unsurprisingly).  For some reason, the test machinery I used
before committing the broken code came up with a slightly different
host-platform name which the configure script didn't recognize, so the
test environment didn't try to compile the broken code.

7 years agobase/dispatch.c: Stop parsing the auxiliary vector when we hit `AT_NULL'.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
base/dispatch.c: Stop parsing the auxiliary vector when we hit `AT_NULL'.

This doesn't seem too dreadful so far (partly because nothing is using
this machinery for something important, and partly because we're parsing
the vector from a file with known length), but fix it anyway.

7 years agoMerge branch 'mdw/cpu-dispatch'
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
Merge branch 'mdw/cpu-dispatch'

* mdw/cpu-dispatch:
  Add support machinery for ARM hosts.
  base/dispatch.c: Add (unused) machinery for probing ELF auxilary vector.
  Add support for AMD64 processors and Microsoft Windows.
  symm/rijndael-x86-aseni.S: Unify encryption and decryption with a macro.
  symm/rijndael-x86-aesni.S: Use xmm5 instead of xmm7.
  symm/*.S: Symbolic names for shuffles.
  symm/chacha-x86-sse2.S: Fix the register allocation comment.
  Preprocess the assembler files.
  configure.ac: Improve the host CPU family detection.
  base/dispatch.c: Indent some preprocessor definitions properly.
  Add a pile of debug output around the CPU dispatching machinery.
  base/dispatch.c: Add documentation for some internal functions.
  base/dispatch.c: Add in more useful section markers.
  Support Intel's AES Native Instructions where available on x86 hardware.
  symm/: New SSE2 implementations of Salsa20 and ChaCha.
  symm/salsa20.c, symm/salsa20-core.h: Permute input matrix for SIMD.
  debian/rules: Run tests twice, once without any detected CPU features.
  base/dispatch.c: Check operating system support for XMM registers.
  configure.ac, base/dispatch.[ch]: CPU-specific implementations.
  configure.ac: Arrange to have an assembler available.

Conflicts:
configure.ac
symm/Makefile.am

7 years agoconfigure.ac: Turn on colour in the test output.
Mark Wooding [Sat, 21 May 2016 10:26:40 +0000 (11:26 +0100)]
configure.ac: Turn on colour in the test output.

It makes it easier to spot the bad ones in a vast spew of parallel test
runs across multiple target platforms.

7 years agosymm/BLKMODE-def.h: Fix alignment of separators in hexdump output.
Mark Wooding [Sat, 21 May 2016 10:07:15 +0000 (11:07 +0100)]
symm/BLKMODE-def.h: Fix alignment of separators in hexdump output.

Now the `:' markers actually correspond with the block boundaries.
Amazing, no?

7 years agoAdd support machinery for ARM hosts.
Mark Wooding [Sat, 21 May 2016 13:33:28 +0000 (14:33 +0100)]
Add support machinery for ARM hosts.

There's currently no ARM code here, but we can probe for the
features (and it seems to work).

7 years agobase/dispatch.c: Add (unused) machinery for probing ELF auxilary vector.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
base/dispatch.c: Add (unused) machinery for probing ELF auxilary vector.

Some platforms don't allow CPU feature-probing from userland, and rely
on the kernel informing processes in some other way.  ELF-ish systems
hide this information in the auxiliary vector, which is very hard to
find.  Add some machinery for doing this anyway.

7 years agoAdd support for AMD64 processors and Microsoft Windows.
Mark Wooding [Sat, 21 May 2016 13:33:28 +0000 (14:33 +0100)]
Add support for AMD64 processors and Microsoft Windows.

  * Slightly modify CPU-feature-probing code in `base/dispatch.c',
    mostly to use wider registers for the stack operations since there
    are no 32-bit `push' instructions.  The feature codes are the same
    for both, so there's no corresponding header-file change.

  * Add appropriate macros to `base/asm-common.h' for dealing with PIC
    on AMD64.  It's refreshingly straightforward.

  * Modify the existing assembler code to support the new environments.
    This is mostly tuning register allocation and prologue/epilogue
    sequences.

  * Use the fancy code on the new platforms.

7 years agosymm/rijndael-x86-aseni.S: Unify encryption and decryption with a macro.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
symm/rijndael-x86-aseni.S: Unify encryption and decryption with a macro.

7 years agosymm/rijndael-x86-aesni.S: Use xmm5 instead of xmm7.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
symm/rijndael-x86-aesni.S: Use xmm5 instead of xmm7.

The only reason is that (stupidly) the Windows 64-bit ABI designates
(the bottom 128 bits of) xmm7 as being callee-saved.

7 years agosymm/*.S: Symbolic names for shuffles.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
symm/*.S: Symbolic names for shuffles.

The magic constants for the various shuffles (actually, all rotations)
have irritated me.  Replace them with names, now we have a preprocessor.

7 years agosymm/chacha-x86-sse2.S: Fix the register allocation comment.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
symm/chacha-x86-sse2.S: Fix the register allocation comment.

The four rows can't all be in XMM0.

7 years agoPreprocess the assembler files.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
Preprocess the assembler files.

  * Rename the `*.s' files to `*.S'.

  * Create a new header `base/asm-common.h' containing useful
    definitions, particularly for dealing with the peculiarities of
    shared library code.

  * Convert the assembler files to use the new macros.

  * Convert the assembler files to use `//' for comments rather than
    `#' (as currently).  This is a bit annoying, but `#' is wanted by
    the preprocessor, and `/* ... */' doesn't work in Emacs's
    `asm-mode'.

The reason for doing all of this is because the C preprocessor will let
me do things like inventing symbolic names for registers, which will be
handy later when I add support for AMD64 processors, because most of the
code will be identical between 32- and 64-bit machines.

This change has the side-effect that the AESNI implementation no longer
uses PIC-ish means to find things when it doesn't need to.

7 years agoconfigure.ac: Improve the host CPU family detection.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
configure.ac: Improve the host CPU family detection.

In particular, also collect the ABI.

7 years agobase/dispatch.c: Indent some preprocessor definitions properly.
Mark Wooding [Wed, 18 May 2016 09:28:25 +0000 (10:28 +0100)]
base/dispatch.c: Indent some preprocessor definitions properly.

7 years agoAdd a pile of debug output around the CPU dispatching machinery.
Mark Wooding [Wed, 18 May 2016 09:29:03 +0000 (10:29 +0100)]
Add a pile of debug output around the CPU dispatching machinery.

Report on finding things in the environment, progress on runtime probes,
and the decisions about which implementations we pick.  Decision-making
isn't time-critical, so this is left in permanently.

7 years agobase/dispatch.c: Add documentation for some internal functions.
Mark Wooding [Wed, 18 May 2016 08:17:01 +0000 (09:17 +0100)]
base/dispatch.c: Add documentation for some internal functions.

7 years agobase/dispatch.c: Add in more useful section markers.
Mark Wooding [Wed, 18 May 2016 08:15:59 +0000 (09:15 +0100)]
base/dispatch.c: Add in more useful section markers.

There will be more sections.

7 years agobuild-setup: Use a slightly later ancient timestamp for dummy files.
Mark Wooding [Mon, 16 May 2016 09:05:52 +0000 (10:05 +0100)]
build-setup: Use a slightly later ancient timestamp for dummy files.

GNU Make secretly reserves extreme-valued timestamps for its own
internal purposes, and then complains about `Timestamp out of range'.
This is annoying enough; but for some reason I don't understand, at
least on Cygwin, instead of substituting its most ancient acceptable
timestamp, it uses its furthest into the future stamp with the result
that it gets stuck in a loop rebuilding makefiles.

Using the second year of the epoch seems to fix the problem.

7 years agoShore up the `grand' protocol.
Mark Wooding [Sun, 15 May 2016 23:25:05 +0000 (00:25 +0100)]
Shore up the `grand' protocol.

This is a bit of a mess, really.  There are two main problems.

  * Firstly, the business of comparing function pointers simply doesn't
    work on Windows, because the dynamic linker is too hopeless.  If the
    class implementation is in a different module from Catacomb itself,
    then the vtable may have a pointer to an import-library stub, which
    won't compare equal to the library's idea of the default method
    function.

    It's basically a mistake to have tried to use the same functions as
    both user interface and default implementation.  Split the two
    apart.  Leave the hacky function-pointer comparisons in the user-
    interface functions for compatibility with existing out-of-tree
    generators, which will carry on working about as well as they ever
    did.

    Note, however, that the defaulting strategy is now less `clever',
    and implementations which don't provide native versions of all the
    methods may end up suffering more than they used to.

  * The `grand_range' function was simply broken if the `raw' method's
    output is too small.  Synthesizing a full uniform-value-in-range
    from a narrow primitive generator in single precision arithmetic is
    rather difficult, so rather than do that I've decided to insist that
    all `raw' methods have a range of at least a byte's worth, so we can
    synthesize a word generator out of bytes if necessary, and then use
    that to satisfy the original larger range request.

This is all a bit unsatisfactory, really.  I must remember to revisit it
when all of these gets made out of a proper object system.

7 years agobuild: Abolish the `$e', `$o' and `$t' variables.
Mark Wooding [Sun, 15 May 2016 14:30:40 +0000 (15:30 +0100)]
build: Abolish the `$e', `$o' and `$t' variables.

I don't think anything ever used `$o'.  Use of `$e' gets in the way of
Automake's magic handling of executable suffixes under Cygwin.  This is
especially acute when executables are listed as tests to be run, because
Autoconf is buggy and sometimes strips off the suffix and sometimes
doesn't.

So we write everything out longhand.  Sorry.

7 years agomath/mp.h: Muffle `unused value' warnings from `MP_COPY'.
Mark Wooding [Sun, 15 May 2016 11:32:17 +0000 (12:32 +0100)]
math/mp.h: Muffle `unused value' warnings from `MP_COPY'.

Nobody cares.

7 years agorand/noise.c: Use `sigjmp_buf' to escape the freewheel generator.
Mark Wooding [Sun, 15 May 2016 11:31:36 +0000 (12:31 +0100)]
rand/noise.c: Use `sigjmp_buf' to escape the freewheel generator.

I'd never noticed there was a separate type before.  This shouldn't have
been a surprise.

7 years agoMakefile.am: Say `-no-undefined' to libtool for the sake of Cygwin.
Mark Wooding [Sun, 15 May 2016 11:30:27 +0000 (12:30 +0100)]
Makefile.am: Say `-no-undefined' to libtool for the sake of Cygwin.

7 years agosymm/modes.am.in: Banish the very boring per-mode tests to `modes/'.
Mark Wooding [Sun, 15 May 2016 14:04:58 +0000 (15:04 +0100)]
symm/modes.am.in: Banish the very boring per-mode tests to `modes/'.

Now that Automake has inflicted `subdir-objects' on us, we might as well
use the opportunity to tidy away the autogenerated `modes/' cruft
properly.

7 years agobuild: Cope with the `subdir-objects' world Automake wants us to live in.
Mark Wooding [Sun, 15 May 2016 13:57:12 +0000 (14:57 +0100)]
build: Cope with the `subdir-objects' world Automake wants us to live in.

Essentially, the Automake developers want to put the objects for
`PATH/TO/FILE.c' in `PATH/TO/FILE.o'.  This is wrongheaded, but we don't
seem to get much choice.  Unfortunately, it's also buggered.

This causes trouble for our precomputed source files.  The obvious
trouble happens if the source file we reference is explicitly in the
source tree, so we'll need to refer to the files differently in
`mumble_SOURCES' lines and the machinery which makes the generates the
files.  The obvious answer would be to introduce two variables for
referring to the precomptations tree.  This is where Automake's bugs
start to really bite.

The main problem is with Automake's automatic dependency-tracking
machinery.  For each object `FILE.o' which is going to be built, it
wants to make a `.deps/FILE.Po' file to track the detected dependencies.
Furthermore, the generated makefiles get unhappy if these files don't
already exist, so there's magic hung off the side of `config.status' to
make them.

This would be great, but the Automake machinery doesn't actually work
properly.  If you refer to a source file via a variable reference,
something like `$(things)/file.c', then Automake's `config.status' magic
creates a dependency-tracking file which is literally named
`.deps/$(things)/file.Po', and then the makefile gets upset when it
tries to include `$(things)/.deps/file.Po'.

So we have to write explicit relative paths to precomputed source file
names in `nodist_mumble_SOURCES' lists (because we make our own
arrangements for distributing them).

Even worse, in older Automake versions, the `distclean' rule prematurely
zaps the dependency-tracking files under `precomps/', so I've had to
split the precomputed sources into subdirectories for each main source
directory.

On the plus side, the `symm/' build tree is less of a mess now that all
of the boring per-mode objects are tucked away in their own
subdirectory.

8 years agodebian/control: have catacomb-dev Depends on the right version of mlib-dev. 2.2.1.1
Mark Wooding [Fri, 19 Feb 2016 09:09:11 +0000 (09:09 +0000)]
debian/control: have catacomb-dev Depends on the right version of mlib-dev.

Unaccountably this was previously entirely missing.

This is release 2.2.1.1.

8 years agoRelease 2.2.1. 2.2.1
Mark Wooding [Thu, 18 Feb 2016 16:44:03 +0000 (16:44 +0000)]
Release 2.2.1.

8 years agoconfigure.ac, debian/control: Depend on mLib 2.2.2.1 or later.
Mark Wooding [Thu, 18 Feb 2016 08:46:45 +0000 (08:46 +0000)]
configure.ac, debian/control: Depend on mLib 2.2.2.1 or later.

Commit 16810bbd... used CDCF_IGNSPC, which was introduced in 2.2.2; but
actually 2.2.2 has an unpleasant memory leak in `dstr_putf', so
encourage people not to use it.

8 years agodebian/: Fix the Build-Depends.
Mark Wooding [Thu, 18 Feb 2016 08:33:25 +0000 (08:33 +0000)]
debian/: Fix the Build-Depends.

  * pkg-config is needed to find mLib.

  * python is needed by a number of the build scripts.

8 years agodebian/source/format: Apparently I have to have one of these now.
Mark Wooding [Thu, 18 Feb 2016 08:33:09 +0000 (08:33 +0000)]
debian/source/format: Apparently I have to have one of these now.

8 years agomath/mptypes.c: Remove obsolete file.
Mark Wooding [Tue, 29 Dec 2015 00:07:02 +0000 (00:07 +0000)]
math/mptypes.c: Remove obsolete file.

This file became redundant back in 1c3d4cf... when `mpgen' took over its
job, but somehow it survived the purge of the old build system.

8 years agomath/mp-fibonacci.c: Fix spacing in comment.
Mark Wooding [Wed, 14 Oct 2015 22:25:16 +0000 (23:25 +0100)]
math/mp-fibonacci.c: Fix spacing in comment.

8 years agomath/mptext.c: Radically refactor `mp_read'.
Mark Wooding [Wed, 14 Oct 2015 10:00:51 +0000 (11:00 +0100)]
math/mptext.c: Radically refactor `mp_read'.

It used to be the largest function in the library -- possibly in my
codebase.

  * Split it into three main pieces: the special-purpose binary reader,
    an efficient stack-based general-radix reader, and a high-level
    syntax parser which picks out signs and base indicators.  This
    removes the complicated entangling of the base indicator parsing
    with the general-radix reader which was the worst feature of the old
    version.

  * Split commonly-used functionality out into separate functions,
    notably `char_digit' and `read_digit'.

The result is code which is easier to understand and actually shorter.

8 years agomath/mptext.c: Reformat and refactor output functions.
Mark Wooding [Wed, 14 Oct 2015 09:55:56 +0000 (10:55 +0100)]
math/mptext.c: Reformat and refactor output functions.

  * Some layout fiddling.

  * Move some block-local variable declarations to the function head.

  * Split `digit_char' out as a separate function, seeing as it's used
    three times.

  * Rename the individual functions with a `write_...' prefix.  A
    corresponding (more invasive) refactoring of the input function will
    have similar names, so avoid the obvious conflict.

8 years agoRelease 2.2.0. 2.2.0
Mark Wooding [Mon, 20 Jul 2015 13:21:02 +0000 (14:21 +0100)]
Release 2.2.0.

8 years agoSupport Intel's AES Native Instructions where available on x86 hardware.
Mark Wooding [Mon, 25 May 2015 09:34:14 +0000 (10:34 +0100)]
Support Intel's AES Native Instructions where available on x86 hardware.

  * Add a detector for the CPU feature.

  * Implement AES in terms of the Intel AESNI instructions.

We can't use the fancy instructions to implement Rijndael with large
blocks, unfortunately; we /can/ (and do) use the rather cumbersome
key-scheduling instructions.

There's a slightly annoying endianness difference between Catacomb
(big-endian) and AESNI (little-endian).  Resolve this by (a) maintaining
the key schedule in little-endian order if we're using AESNI (and blocks
are exactly 128 bits); and (b) end-swapping the block on entry and exit
to the block cipher operations.

8 years agosymm/: New SSE2 implementations of Salsa20 and ChaCha.
Mark Wooding [Sat, 2 May 2015 16:05:20 +0000 (17:05 +0100)]
symm/: New SSE2 implementations of Salsa20 and ChaCha.

These are chosen at runtime if the CPU is suitable.

8 years agosymm/salsa20.c, symm/salsa20-core.h: Permute input matrix for SIMD.
Mark Wooding [Sat, 2 May 2015 16:05:20 +0000 (17:05 +0100)]
symm/salsa20.c, symm/salsa20-core.h: Permute input matrix for SIMD.

Maintain the input matrix in the Salsa20 context structure in a permuted
form which makes SIMD implementations of the core function rather more
efficient.

8 years agodebian/rules: Run tests twice, once without any detected CPU features.
Mark Wooding [Mon, 25 May 2015 18:37:01 +0000 (19:37 +0100)]
debian/rules: Run tests twice, once without any detected CPU features.

8 years agobase/dispatch.c: Check operating system support for XMM registers.
Mark Wooding [Sat, 30 May 2015 19:26:39 +0000 (20:26 +0100)]
base/dispatch.c: Check operating system support for XMM registers.

I found a technique for doing this described by Agner Fog: see

http://www.agner.org/optimize/#manual_asm

which is conveniently independent of any particular system.  Quite why
Intel don't document this clearly is something of a mystery to me.

8 years agoconfigure.ac, base/dispatch.[ch]: CPU-specific implementations.
Mark Wooding [Mon, 18 May 2015 22:21:02 +0000 (23:21 +0100)]
configure.ac, base/dispatch.[ch]: CPU-specific implementations.

We now have the capability for a function to have multiple CPU-specific
implementations, and to choose the most appropriate one at runtime.

The new `cpu_feature_p' function doesn't understand much in the way of
features yet, but is ready to grow later.

8 years agoconfigure.ac: Arrange to have an assembler available.
Mark Wooding [Sat, 2 May 2015 16:05:20 +0000 (17:05 +0100)]
configure.ac: Arrange to have an assembler available.

8 years agoMerge branch 'mdw/latin-dances'
Mark Wooding [Mon, 20 Jul 2015 12:53:44 +0000 (13:53 +0100)]
Merge branch 'mdw/latin-dances'

* mdw/latin-dances:
  progs/rspit.c: Include Salsa20 and ChaCha (and their variants).
  symm: Implement Bernstein's ChaCha stream cipher.
  symm: Implement Bernstein's Salsa20 stream cipher and its variants.

8 years agoprogs/rspit.c: Include Salsa20 and ChaCha (and their variants).
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
progs/rspit.c: Include Salsa20 and ChaCha (and their variants).

8 years agosymm: Implement Bernstein's ChaCha stream cipher.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
symm: Implement Bernstein's ChaCha stream cipher.

8 years agosymm: Implement Bernstein's Salsa20 stream cipher and its variants.
Mark Wooding [Fri, 13 Mar 2015 20:09:51 +0000 (20:09 +0000)]
symm: Implement Bernstein's Salsa20 stream cipher and its variants.

8 years agoprogs/key.c: Multiple output presentations for fingerprints.
Mark Wooding [Fri, 29 May 2015 17:54:29 +0000 (18:54 +0100)]
progs/key.c: Multiple output presentations for fingerprints.

Add a new presentation for base32 output, separated into groups of six
characters.

Also document the presentation styles better; include some other missing
options in usage messages; and patch an irrelevant memory leak.

8 years agoprogs/key.c: Use the mLib generic codec interface instead of base64_*.
Mark Wooding [Fri, 29 May 2015 17:49:35 +0000 (18:49 +0100)]
progs/key.c: Use the mLib generic codec interface instead of base64_*.

This means we can actually detect errors in the seed provided to `key
add -s'.

8 years agoprogs/key.c: Exit with `EXIT_FAILURE' on keyring open failure.
Mark Wooding [Fri, 29 May 2015 17:47:59 +0000 (18:47 +0100)]
progs/key.c: Exit with `EXIT_FAILURE' on keyring open failure.

Portability fix for a careless error.

8 years agorand/rand.c: Fix incorrect assertion.
Mark Wooding [Fri, 29 May 2015 13:41:13 +0000 (14:41 +0100)]
rand/rand.c: Fix incorrect assertion.

8 years agomath/ec-raw.[ch] (ec_ec2osp): Check that the requested flags are sane.
Mark Wooding [Thu, 28 May 2015 18:49:34 +0000 (19:49 +0100)]
math/ec-raw.[ch] (ec_ec2osp): Check that the requested flags are sane.

Also tests, just to make sure.

8 years agoMerge branch 'mdw/fixes'
Mark Wooding [Mon, 25 May 2015 17:59:52 +0000 (18:59 +0100)]
Merge branch 'mdw/fixes'

* mdw/fixes:
  symm/safer.[ch]: Correct description for `safer_setup'.
  symm/rc4.h: Mention that RC4 isn't really very good.
  symm/rc4.[ch]: Fix incorrect documentation on `rc4_rand'.
  symm/seal.c: Fix IV handling through `gcipher' interface.
  math/mpint.h: Add new conversions.
  math/mpint.[ch]: Consolidate the list of supplied conversions in header.
  progs/rspit.c: Update the baton more frequently if we can.
  progs/rspit.c: Higher resolution timing.
  progs/rspit.c: Handle large requested output.
  progs/rspit.c: Better handling of block cipher IVs.
  progs/rspit.c: Make the internal tables be const.
  rand/rand.[ch]: Spring-clean the random source cryptography.
  rand/rand.[ch]: Don't dynamically construct the global generator.
  symm/multigen: Some UI improvements.
  symm: Expunge stubby header files from the source tree.
  symm/Makefile.am: Modes files listed as `EXTRA_DIST' and `nodist_...'.
  symm/Makefile.am: Have modes things depend on `Makefile.am'.
  symm/modes.am.in: Fix `Generated from ...' header.

8 years agosymm/safer.[ch]: Correct description for `safer_setup'.
Mark Wooding [Wed, 18 Mar 2015 09:58:21 +0000 (09:58 +0000)]
symm/safer.[ch]: Correct description for `safer_setup'.

8 years agoconfigure.ac: Fix detection of the freewheel generator
Mark Wooding [Sat, 2 May 2015 16:05:20 +0000 (17:05 +0100)]
configure.ac: Fix detection of the freewheel generator

This has been broken since the `configure.ac' script was introduced in
commit ba6e6b64033b1f9de49feccb5c9cd438354481f7.

8 years agoprogs/key.1: General typesetting improvements.
Mark Wooding [Mon, 18 May 2015 22:21:33 +0000 (23:21 +0100)]
progs/key.1: General typesetting improvements.

9 years agomath/mpmont.c (mpmont_reduce): Segfault if Karatsuba product is short.
Mark Wooding [Fri, 10 Apr 2015 14:19:25 +0000 (15:19 +0100)]
math/mpmont.c (mpmont_reduce): Segfault if Karatsuba product is short.

In the Karatsuba branch, it's possible (e.g., if the input is actually
zero) that the result is short.  A later `MP_LEN(d) - n' then underflows
causing general badness.  Make sure the result is actually long enough.

9 years agopub/dsa-misc.c: Include a magic prefix in the hashing.
Mark Wooding [Mon, 31 Mar 2014 15:01:46 +0000 (16:01 +0100)]
pub/dsa-misc.c: Include a magic prefix in the hashing.

To prevent protocol interference.  In practice, I think including the
private key should be enough, because nobody would use that in any other
kind of hash, right...?

9 years agoprogs/catcrypt.1: Fix stupid typo.
Mark Wooding [Mon, 13 Apr 2015 16:22:00 +0000 (17:22 +0100)]
progs/catcrypt.1: Fix stupid typo.

9 years agosymm/rc4.h: Mention that RC4 isn't really very good.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
symm/rc4.h: Mention that RC4 isn't really very good.

9 years agosymm/rc4.[ch]: Fix incorrect documentation on `rc4_rand'.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
symm/rc4.[ch]: Fix incorrect documentation on `rc4_rand'.

9 years agosymm/seal.c: Fix IV handling through `gcipher' interface.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
symm/seal.c: Fix IV handling through `gcipher' interface.

  * Read the IV as octets (big-endian) rather than as a machine word.

  * Advertise a `block size' of 4 octets.

This is a compatibility break, but I don't think anyone was using SEAL,
and it was nearly impossible to use correctly through this interface
anyway.

9 years agomath/mpint.h: Add new conversions.
Mark Wooding [Wed, 18 Mar 2015 19:03:16 +0000 (19:03 +0000)]
math/mpint.h: Add new conversions.

Cover the remaining <mLib/bits.h> types, `long long', `intmax_t', and
`size_t'.

Conversions for the non-C89 types are only defined if the types are
actually detected.

9 years agomath/mpint.[ch]: Consolidate the list of supplied conversions in header.
Mark Wooding [Wed, 18 Mar 2015 18:59:28 +0000 (18:59 +0000)]
math/mpint.[ch]: Consolidate the list of supplied conversions in header.

Now there's only one source of ultimate conversion-related truth.

9 years agoprogs/rspit.c: Update the baton more frequently if we can.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
progs/rspit.c: Update the baton more frequently if we can.

9 years agoprogs/rspit.c: Higher resolution timing.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
progs/rspit.c: Higher resolution timing.

Use double-precision for representing time, as seconds since some
arbitrary epoch.  If we're strictly portable then time(3) is all we
have, and we have to convert with difftime(3); otherwise we can have
gettimeofday(2) and convert by hand.

9 years agoprogs/rspit.c: Handle large requested output.
Mark Wooding [Wed, 18 Mar 2015 19:04:47 +0000 (19:04 +0000)]
progs/rspit.c: Handle large requested output.

We could work with `off_t' throughout, but in fact we might be asked for
a /very/ large stream, and it turns out that there's a rather convenient
multiprecision integer library just waiting to be used.

9 years agoprogs/rspit.c: Better handling of block cipher IVs.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
progs/rspit.c: Better handling of block cipher IVs.

  * Check the IV length during option parsing, rather than at the end.

  * Don't accumulate IV material because we don't do that with keys.

9 years agoprogs/rspit.c: Make the internal tables be const.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
progs/rspit.c: Make the internal tables be const.

9 years agorand/rand.[ch]: Spring-clean the random source cryptography.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
rand/rand.[ch]: Spring-clean the random source cryptography.

  * Use Twofish in counter mode for the main mixing function, because it
    has lighter-weight key scheduling.

  * Use SHA256 rather than HMAC(RIPEMD-160) for digesting.  I don't
    think HMAC has anything useful to bring to the party here, and
    SHA256 is definitely closer to the security level we're aiming for
    now.

  * The context structure just contains a plain key now, rather than a
    scheduled HMAC key, but there's padding to retain binary
    compatibility.

  * Keys fed into `rand_key' are mangled by hashing with a constant
    prefix, mostly to sort out problems of length variation and so on.

  * We keep back 256 bits rather than 160 now.

All of this obviously means that the generator will produce different
output now if you try to use it in a deterministic mode.  Don't do that.
There are plenty of better deterministic generators in this library.  I
reserve the right to change this one again in the future.

9 years agorand/rand.[ch]: Don't dynamically construct the global generator.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
rand/rand.[ch]: Don't dynamically construct the global generator.

Now it always exists, and is statically initialized.  There should be no
observable change.

9 years agosymm/multigen: Some UI improvements.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
symm/multigen: Some UI improvements.

Previously the usage message (and the code!) suggested that you could
run multigen without any options, and it'd default to generating
output.  Well, that was true, only it wouldn't know which input file to
read and then it'd crash with the unusually unhelpful error

  TypeError: coercing to Unicode: need string or buffer, NoneType found

Changes to fix this:

  * There's no default mode any more.  You have to give `-l' or `-g'.
    The `-g' option now does double duty, setting the mode and storing
    an input file name.

  * Print the `no mode set' error in a more friendly way, now that we
    actually expect to see it.

  * Fix the usage message so that it's clear that `-g' takes an
    argument, which it always used to anyway.

  * Change the usage message so that it shows `-l' and `-g' as
    alternatives from which you must select one, rather than just
    optional things from which you might pick several.

Callers which worked before won't see any change.  Interactive use is
now a bit less dreadful.

9 years agosymm: Expunge stubby header files from the source tree.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
symm: Expunge stubby header files from the source tree.

Construct them at compile time instead.

9 years agosymm/Makefile.am: Modes files listed as `EXTRA_DIST' and `nodist_...'.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
symm/Makefile.am: Modes files listed as `EXTRA_DIST' and `nodist_...'.

The generated per-mode files were listed both as `nodist_...' and in
`EXTRA_DIST'.  Sort this out by just adding them to the appropriate
distribution list instead.

9 years agosymm/Makefile.am: Have modes things depend on `Makefile.am'.
Mark Wooding [Sun, 15 Mar 2015 02:11:40 +0000 (02:11 +0000)]
symm/Makefile.am: Have modes things depend on `Makefile.am'.

This is, after all, where the master list comes from.  This includes the
modes files, and the various generated lists.

9 years agosymm/modes.am.in: Fix `Generated from ...' header.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
symm/modes.am.in: Fix `Generated from ...' header.

9 years agopub/rsa-recover.c: Give up if we run out of prime numbers.
Mark Wooding [Fri, 13 Mar 2015 20:36:31 +0000 (20:36 +0000)]
pub/rsa-recover.c: Give up if we run out of prime numbers.

We have a 1/2 probability of winning for each prime, and `NPRIME' is at
least 256, so the chances of us giving up on an input which we could, in
fact, factor if we persevered are negligible.  We therefore neglect them.