Abandon the `m4'-based build system. And there was great rejoicing.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 1 Jun 2013 19:28:26 +0000 (20:28 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 5 Jun 2013 23:41:43 +0000 (00:41 +0100)
The makefile has been entirely rewritten using old-fashioned Automake.
I've used the undocumented `foo_OBJECTS' variables in a couple of places
to make parallel builds work, but those will disappear again in the
course of future rearrangements of the source tree.

A couple of the scungier programs for building boilerplate source files
have been replaced by the marvellous new template-substitution program
`multigen'.

The `qcc' script is a casualty of the rearrangements.  Supporting it is
easy, but probably pointless.  So it's gone.

Currently most of the generated code is left in the build tree (rather
than the source tree) and not distributed.  This wants to be fixed
later, but the exact machinery will be rather different.

This is only the start of a programme of overhauling Catacomb's ageing
and rather nasty build system.  The objective is to end up with modern-
looking build scripts, and a pleasant and sensible directory tree.  Not
much of the actual code will change during this, though lots of it will
move around.  In particular, the testing machinery is likely to be
overhauled quite a lot.

16 files changed:
.gitignore
.links
Makefile.am [new file with mode: 0644]
Makefile.m4 [deleted file]
build-setup [new file with mode: 0755]
configure.in
gengctab [deleted file]
genmodes [deleted file]
gthingtab.c.in [new file with mode: 0644]
mode.c.in [new file with mode: 0644]
mode.h.in [new file with mode: 0644]
modes.am.in [new file with mode: 0644]
multigen [new file with mode: 0755]
qcc.in [deleted file]
tests/.gitignore
tests/Makefile.m4 [deleted file]

index 7049d42..f1dff6f 100644 (file)
@@ -1,303 +1,8 @@
 KEYRING
 KEYRING
-Makefile.am
 Makefile.in
 Makefile.in
-_mpdiv.c
 aclocal.m4
 aclocal.m4
-arena-changes
-blowfish-cbc.c
-blowfish-cbc.h
-blowfish-cfb.c
-blowfish-cfb.h
-blowfish-counter.c
-blowfish-counter.h
-blowfish-ecb.c
-blowfish-ecb.h
-blowfish-ofb.c
-blowfish-ofb.h
-build
-cast128-cbc.c
-cast128-cbc.h
-cast128-cfb.c
-cast128-cfb.h
-cast128-counter.c
-cast128-counter.h
-cast128-ecb.c
-cast128-ecb.h
-cast128-ofb.c
-cast128-ofb.h
-cast128-tab.h
-cast256-cbc.c
-cast256-cbc.h
-cast256-cfb.c
-cast256-cfb.h
-cast256-counter.c
-cast256-counter.h
-cast256-ecb.c
-cast256-ecb.h
-cast256-ofb.c
-cast256-ofb.h
 config.h.in
 configure
 config.h.in
 configure
-des-cbc.c
-des-cbc.h
-des-cfb.c
-des-cfb.h
-des-counter.c
-des-counter.h
-des-ecb.c
-des-ecb.h
-des-ofb.c
-des-ofb.h
-des3-cbc.c
-des3-cbc.h
-des3-cfb.c
-des3-cfb.h
-des3-counter.c
-des3-counter.h
-des3-ecb.c
-des3-ecb.h
-des3-ofb.c
-des3-ofb.h
-des_sp.h
-desx-cbc.c
-desx-cbc.h
-desx-cfb.c
-desx-cfb.h
-desx-counter.c
-desx-counter.h
-desx-ecb.c
-desx-ecb.h
-desx-ofb.c
-desx-ofb.h
-et.c
-idea-cbc.c
-idea-cbc.h
-idea-cfb.c
-idea-cfb.h
-idea-counter.c
-idea-counter.h
-idea-ecb.c
-idea-ecb.h
-idea-ofb.c
-idea-ofb.h
-mars-cbc.c
-mars-cbc.h
-mars-cfb.c
-mars-cfb.h
-mars-counter.c
-mars-counter.h
-mars-ecb.c
-mars-ecb.h
-mars-ofb.c
-mars-ofb.h
-md2-hmac.c
-md2-hmac.h
-md2-mgf.c
-md2-mgf.h
-md4-hmac.c
-md4-hmac.h
-md4-mgf.c
-md4-mgf.h
-md5-hmac.c
-md5-hmac.h
-md5-mgf.c
-md5-mgf.h
-noekeon-cbc.c
-noekeon-cbc.h
-noekeon-cfb.c
-noekeon-cfb.h
-noekeon-counter.c
-noekeon-counter.h
-noekeon-ecb.c
-noekeon-ecb.h
-noekeon-ofb.c
-noekeon-ofb.h
-rc2-cbc.c
-rc2-cbc.h
-rc2-cfb.c
-rc2-cfb.h
-rc2-counter.c
-rc2-counter.h
-rc2-ecb.c
-rc2-ecb.h
-rc2-ofb.c
-rc2-ofb.h
-rc5-cbc.c
-rc5-cbc.h
-rc5-cfb.c
-rc5-cfb.h
-rc5-counter.c
-rc5-counter.h
-rc5-ecb.c
-rc5-ecb.h
-rc5-ofb.c
-rc5-ofb.h
-rijndael-cbc.c
-rijndael-cbc.h
-rijndael-cfb.c
-rijndael-cfb.h
-rijndael-counter.c
-rijndael-counter.h
-rijndael-ecb.c
-rijndael-ecb.h
-rijndael-ofb.c
-rijndael-ofb.h
-rijndael192-cbc.c
-rijndael192-cbc.h
-rijndael192-cfb.c
-rijndael192-cfb.h
-rijndael192-counter.c
-rijndael192-counter.h
-rijndael192-ecb.c
-rijndael192-ecb.h
-rijndael192-ofb.c
-rijndael192-ofb.h
-rijndael256-cbc.c
-rijndael256-cbc.h
-rijndael256-cfb.c
-rijndael256-cfb.h
-rijndael256-counter.c
-rijndael256-counter.h
-rijndael256-ecb.c
-rijndael256-ecb.h
-rijndael256-ofb.c
-rijndael256-ofb.h
-rmd128-hmac.c
-rmd128-hmac.h
-rmd128-mgf.c
-rmd128-mgf.h
-rmd160-hmac.c
-rmd160-hmac.h
-rmd160-mgf.c
-rmd160-mgf.h
-rmd256-hmac.c
-rmd256-hmac.h
-rmd256-mgf.c
-rmd256-mgf.h
-rmd320-hmac.c
-rmd320-hmac.h
-rmd320-mgf.c
-rmd320-mgf.h
-safer-cbc.c
-safer-cbc.h
-safer-cfb.c
-safer-cfb.h
-safer-counter.c
-safer-counter.h
-safer-ecb.c
-safer-ecb.h
-safer-ofb.c
-safer-ofb.h
-safersk-cbc.c
-safersk-cbc.h
-safersk-cfb.c
-safersk-cfb.h
-safersk-counter.c
-safersk-counter.h
-safersk-ecb.c
-safersk-ecb.h
-safersk-ofb.c
-safersk-ofb.h
-serpent-cbc.c
-serpent-cbc.h
-serpent-cfb.c
-serpent-cfb.h
-serpent-counter.c
-serpent-counter.h
-serpent-ecb.c
-serpent-ecb.h
-serpent-ofb.c
-serpent-ofb.h
-sha-hmac.c
-sha-hmac.h
-sha-mgf.c
-sha-mgf.h
-sha256-hmac.c
-sha256-hmac.h
-sha256-mgf.c
-sha256-mgf.h
-sha384-hmac.c
-sha384-hmac.h
-sha384-mgf.c
-sha384-mgf.h
-sha512-hmac.c
-sha512-hmac.h
-sha512-mgf.c
-sha512-mgf.h
-skipjack-cbc.c
-skipjack-cbc.h
-skipjack-cfb.c
-skipjack-cfb.h
-skipjack-counter.c
-skipjack-counter.h
-skipjack-ecb.c
-skipjack-ecb.h
-skipjack-ofb.c
-skipjack-ofb.h
-square-cbc.c
-square-cbc.h
-square-cfb.c
-square-cfb.h
-square-counter.c
-square-counter.h
-square-ecb.c
-square-ecb.h
-square-ofb.c
-square-ofb.h
-stamp-h.in
-tea-cbc.c
-tea-cbc.h
-tea-cfb.c
-tea-cfb.h
-tea-counter.c
-tea-counter.h
-tea-ecb.c
-tea-ecb.h
-tea-ofb.c
-tea-ofb.h
-tiger-hmac.c
-tiger-hmac.h
-tiger-mgf.c
-tiger-mgf.h
-twofish-cbc.c
-twofish-cbc.h
-twofish-cfb.c
-twofish-cfb.h
-twofish-counter.c
-twofish-counter.h
-twofish-ecb.c
-twofish-ecb.h
-twofish-ofb.c
-twofish-ofb.h
-xtea-cbc.c
-xtea-cbc.h
-xtea-cfb.c
-xtea-cfb.h
-xtea-counter.c
-xtea-counter.h
-xtea-ecb.c
-xtea-ecb.h
-xtea-ofb.c
-xtea-ofb.h
-sha224-hmac.c
-sha224-hmac.h
-sha224-mgf.c
-sha224-mgf.h
-whirlpool-hmac.c
-whirlpool-hmac.h
-whirlpool-mgf.c
-whirlpool-mgf.h
-whirlpool256-hmac.c
-whirlpool256-hmac.h
-whirlpool256-mgf.c
-whirlpool256-mgf.h
-junk
-deb-build
-has160-hmac.c
-has160-hmac.h
-has160-mgf.c
-has160-mgf.h
-profile
 COPYING.LIB
 COPYING
 autom4te.cache
 COPYING.LIB
 COPYING
 autom4te.cache
@@ -315,4 +20,6 @@ tinymp
 *.kr
 *.kr.old
 ylwrap
 *.kr
 *.kr.old
 ylwrap
+modes.am
 auto-version
 auto-version
+confsubst
diff --git a/.links b/.links
index 37a72a4..5f62873 100644 (file)
--- a/.links
+++ b/.links
@@ -2,3 +2,4 @@ COPYING.LIB
 getdate.y
 getdate.h
 auto-version
 getdate.y
 getdate.h
 auto-version
+confsubst
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..98c246a
--- /dev/null
@@ -0,0 +1,1120 @@
+### -*-makefile-*-
+###
+### Build script for Catacomb
+###
+### (c) 2013 Straylight/Edgeware
+###
+
+###----- Licensing notice ---------------------------------------------------
+###
+### This file is part of Catacomb.
+###
+### Catacomb is free software; you can redistribute it and/or modify
+### it under the terms of the GNU Library General Public License as
+### published by the Free Software Foundation; either version 2 of the
+### License, or (at your option) any later version.
+###
+### Catacomb is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+### GNU Library General Public License for more details.
+###
+### You should have received a copy of the GNU Library General Public
+### License along with Catacomb; if not, write to the Free
+### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+### MA 02111-1307, USA.
+
+###--------------------------------------------------------------------------
+### Miscellaneous useful definitions.
+
+## Some convenient abbreviations for file suffixes.
+e                       = $(EXEEXT)
+o                       = $(OBJEXT)
+t                       = t$e
+
+## Installation directories.
+archincludedir          = $(pkglibdir)/include
+
+###--------------------------------------------------------------------------
+### Initial values of common variables.
+
+SUBDIRS                         =
+
+EXTRA_DIST              =
+CLEANFILES              =
+DISTCLEANFILES          =
+MAINTAINERCLEANFILES    =
+SUFFIXES                =
+TESTS                   =
+BUILT_SOURCES           =
+
+bin_PROGRAMS            =
+noinst_PROGRAMS                 =
+lib_LTLIBRARIES                 =
+noinst_LTLIBRARIES      =
+pkginclude_HEADERS      =
+nodist_pkginclude_HEADERS =
+archinclude_HEADERS     =
+nodist_archinclude_HEADERS =
+dist_man_MANS           =
+
+###--------------------------------------------------------------------------
+### Standard configuration substitutions.
+
+## Substitute tags in files.
+confsubst = $(top_srcdir)/confsubst
+EXTRA_DIST             += confsubst
+
+SUBSTITUTIONS = \
+               prefix=$(prefix) exec_prefix=$(exec_prefix) \
+               libdir=$(libdir) includedir=$(includedir) \
+               PACKAGE=$(PACKAGE) VERSION=$(VERSION)
+
+V_SUBST = $(V_SUBST_$(V))
+V_SUBST_ = $(V_SUBST_$(AM_DEFAULT_VERBOSITY))
+V_SUBST_0 = @echo "  SUBST  $@";
+SUBST = $(V_SUBST)$(confsubst)
+
+###--------------------------------------------------------------------------
+### The main library.
+
+lib_LTLIBRARIES                += libcatacomb.la
+libcatacomb_la_LIBADD   = $(CATACOMB_LIBS)
+libcatacomb_la_LDFLAGS  = -version-info $(LIBTOOL_VERSION_INFO)
+libcatacomb_la_SOURCES  =
+nodist_libcatacomb_la_SOURCES =
+
+###--------------------------------------------------------------------------
+### Basic utilities.
+
+## The locked-memory arena.
+pkginclude_HEADERS     += arena.h
+libcatacomb_la_SOURCES += arena.c
+
+## Constant-type operations.
+pkginclude_HEADERS     += ct.h
+libcatacomb_la_SOURCES += ct.c
+
+## Acceptable key-size descriptions.
+pkginclude_HEADERS     += keysz.h
+libcatacomb_la_SOURCES += keysz.c keysz-conv.c
+
+## System-level memory locking.
+pkginclude_HEADERS     += lmem.h
+libcatacomb_la_SOURCES += lmem.c
+
+## Clearing secrets from memory.
+pkginclude_HEADERS     += paranoia.h
+
+###--------------------------------------------------------------------------
+### Main multiprecision integer library.
+
+## This library is unfortunately intertwined with some of the code generation
+## programs, so we must be rather careful.  The important bits of the maths
+## library needed by these programs is separated out into `libmpbase'.  There
+## is work going on to fix this unpleasant situation by generating the
+## relevant files from Python scripts rather than C programs, using
+## information gathered by `configure'.
+noinst_LTLIBRARIES     += libmpbase.la
+libcatacomb_la_LIBADD  += libmpbase.la
+libmpbase_la_SOURCES    =
+$(libmpbase_la_OBJECTS): mptypes.h
+
+## Additional buffer I/O functions for mathematical objects.
+pkginclude_HEADERS     += buf.h
+libcatacomb_la_SOURCES += buf.c
+
+## Infrastructure for fast exponentiation.
+pkginclude_HEADERS     += exp.h
+libcatacomb_la_SOURCES += exp.c
+
+## Main user-visible multiprecision arithmetic.
+pkginclude_HEADERS     += mp.h
+libmpbase_la_SOURCES   += mp-arith.c
+TESTS                  += mp-arith.$t
+libmpbase_la_SOURCES   += mp-const.c
+libcatacomb_la_SOURCES += mp-exp.c mp-exp.h
+libcatacomb_la_SOURCES += mp-gcd.c
+TESTS                  += mp-gcd.$t
+libmpbase_la_SOURCES   += mp-io.c
+libcatacomb_la_SOURCES += mp-jacobi.c
+TESTS                  += mp-jacobi.$t
+libmpbase_la_SOURCES   += mp-mem.c
+libmpbase_la_SOURCES   += mp-misc.c
+libcatacomb_la_SOURCES += mp-modexp.c
+TESTS                  += mp-modexp.$t
+libcatacomb_la_SOURCES += mp-modsqrt.c
+TESTS                  += mp-modsqrt.$t
+libcatacomb_la_SOURCES += mp-sqrt.c
+TESTS                  += mp-sqrt.$t
+libcatacomb_la_SOURCES += mp-test.c
+EXTRA_DIST             += tests/mp
+
+## Computing Fibonacci numbers.
+pkginclude_HEADERS     += mp-fibonacci.h
+libcatacomb_la_SOURCES += mp-fibonacci.c
+TESTS                  += mp-fibonacci.$t
+
+## Special memory allocation for multiprecision integers.
+pkginclude_HEADERS     += mparena.h
+libmpbase_la_SOURCES   += mparena.c
+
+## Barrett reduction, an efficient method for modular reduction.
+pkginclude_HEADERS     += mpbarrett.h
+libcatacomb_la_SOURCES += mpbarrett.c
+TESTS                  += mpbarrett.$t
+libcatacomb_la_SOURCES += mpbarrett-exp.c mpbarrett-mexp.c mpbarrett-exp.h
+TESTS                  += mpbarrett-exp.$t mpbarrett-mexp.$t
+EXTRA_DIST             += tests/mpbarrett
+
+## Solving congruences using the Chinese Remainder Theorem.
+pkginclude_HEADERS     += mpcrt.h
+libcatacomb_la_SOURCES += mpcrt.c
+TESTS                  += mpcrt.$t
+EXTRA_DIST             += tests/mpcrt
+
+## Conversions between machine-native and multiprecision integers.
+pkginclude_HEADERS     += mpint.h
+libcatacomb_la_SOURCES += mpint.c
+TESTS                  += mpint.$t
+EXTRA_DIST             += tests/mpint
+
+## Table of upper and lower limits of various types of machine integers, as
+## multiprecision integers.
+nodist_archinclude_HEADERS += mplimits.h
+nodist_libcatacomb_la_SOURCES += mplimits.c
+CLEANFILES             += mplimits.h mplimits.c
+noinst_PROGRAMS                += genlimits
+genlimits_LDADD                 = libmpbase.la
+mplimits.c: genlimits$e
+       $(AM_V_GEN)./genlimits c >mplimits.c.new && \
+               mv mplimits.c.new mplimits.c
+mplimits.h: genlimits$e
+       $(AM_V_GEN)./genlimits h >mplimits.h.new && \
+               mv mplimits.h.new mplimits.h
+$(genlimits_OBJECTS): mptypes.h
+mplimits.lo: mplimits.h
+
+## Montgomery reduction, a clever method for modular arithmetic.
+pkginclude_HEADERS     += mpmont.h
+libcatacomb_la_SOURCES += mpmont.c
+TESTS                  += mpmont.$t
+libcatacomb_la_SOURCES += mpmont-exp.c mpmont-mexp.c mpmont-exp.h
+TESTS                  += mpmont-exp.$t mpmont-mexp.$t
+EXTRA_DIST             += tests/mpmont
+
+## Efficient multiplication of many small numbers.
+pkginclude_HEADERS     += mpmul.h
+libcatacomb_la_SOURCES += mpmul.c
+TESTS                  += mpmul.$t
+
+## Generating random numbers.
+pkginclude_HEADERS     += mprand.h
+libcatacomb_la_SOURCES += mprand.c
+
+## Efficient reduction modulo numbers with conveninent binary
+## representations.
+pkginclude_HEADERS     += mpreduce.h
+libcatacomb_la_SOURCES += mpreduce.c mpreduce-exp.h
+TESTS                  += mpreduce.$t
+EXTRA_DIST             += tests/mpreduce
+
+## Iteratiion over the bianry representation of multiprecision integers.
+pkginclude_HEADERS     += mpscan.h
+libmpbase_la_SOURCES   += mpscan.c
+
+## Conversion between multiprecision integers and their textual
+## representations.
+pkginclude_HEADERS     += mptext.h
+libmpbase_la_SOURCES   += mptext.c
+TESTS                  += mptext.$t
+libcatacomb_la_SOURCES += mptext-dstr.c
+libcatacomb_la_SOURCES += mptext-file.c
+libcatacomb_la_SOURCES += mptext-len.c
+libmpbase_la_SOURCES   += mptext-string.c
+EXTRA_DIST             += tests/mptext
+
+## Basic types used in the representation of multiprecision integers.
+nodist_archinclude_HEADERS += mptypes.h
+BUILT_SOURCES          += mptypes.h
+CLEANFILES             += mptypes.h
+noinst_PROGRAMS                += mptypes
+mptypes.h: mptypes$e
+       $(AM_V_GEN)./mptypes >mptypes.h.new && mv mptypes.h.new mptypes.h
+
+## Low-level multiprecision arithmetic.
+pkginclude_HEADERS     += mpx.h bitops.h mpw.h
+libmpbase_la_SOURCES   += mpx.c
+TESTS                  += mpx.$t
+libmpbase_la_SOURCES   += karatsuba.h mpx-kmul.c mpx-ksqr.c
+TESTS                  += mpx-kmul.$t mpx-ksqr.$t
+noinst_PROGRAMS                += bittest
+TESTS                  += bittest
+EXTRA_DIST             += tests/mpx
+
+## A quick-and-dirty parser, used for parsing descriptions of groups, fields,
+## etc.
+pkginclude_HEADERS     += rho.h
+libcatacomb_la_SOURCES += rho.c
+TESTS                  += rho.$t
+
+## Pollard's `rho' algorithm for determining discrete logarithms.
+pkginclude_HEADERS     += qdparse.h
+libcatacomb_la_SOURCES += qdparse.c
+
+###--------------------------------------------------------------------------
+### Prime number checking, searching, and related jobs.
+
+## Generating Lim--Lee groups, i.e., unit groups of finite fields without
+## small subgroups (except for the obvious ones).
+pkginclude_HEADERS     += limlee.h
+libcatacomb_la_SOURCES += limlee.c
+
+## A table of small prime numbers.
+nodist_pkginclude_HEADERS += primetab.h
+nodist_libcatacomb_la_SOURCES += primetab.c
+CLEANFILES             += primetab.h primetab.c
+BUILT_SOURCES          += primetab.h primetab.c
+noinst_PROGRAMS                += genprimes
+primetab.h: primetab.c
+primetab.c: genprimes$e
+       $(AM_V_GEN)./genprimes -hprimetab.h -cprimetab.c \
+               -sCATACOMB_PRIMETAB_H \
+               -n256 -t"unsigned short" -iprimetab
+
+## Filtering candidate prime numbers by checking for small factors
+## efficiently.
+pkginclude_HEADERS     += pfilt.h
+libcatacomb_la_SOURCES += pfilt.c
+
+## Generating prime numbers (and other kinds of numbers which need searching
+## for).
+pkginclude_HEADERS     += pgen.h
+libcatacomb_la_SOURCES += pgen.c
+libcatacomb_la_SOURCES += pgen-gcd.c
+libcatacomb_la_SOURCES += pgen-simul.c
+libcatacomb_la_SOURCES += pgen-stdev.c
+TESTS                  += pgen.$t
+EXTRA_DIST             += tests/pgen
+
+## Finding primitive elements in finite fields.
+pkginclude_HEADERS     += prim.h
+libcatacomb_la_SOURCES += prim.c
+
+## Iterating over all prime numbers from a given starting point.
+pkginclude_HEADERS     += primeiter.h
+libcatacomb_la_SOURCES += primeiter.c
+TESTS                  += primeiter.$t
+primeiter.lo: wheel.h
+
+## The Miller--Rabin primality test.
+pkginclude_HEADERS     += rabin.h
+libcatacomb_la_SOURCES += rabin.c
+
+## Finding `strong' primes, using Gordon's algorithm.  Once upon a time,
+## products of these kinds of numbers were harder to factor.
+pkginclude_HEADERS     += strongprime.h
+libcatacomb_la_SOURCES += strongprime.c
+
+## A `wheel', used by the prime iteration machinery.
+nodist_pkginclude_HEADERS += wheel.h
+nodist_libcatacomb_la_SOURCES += wheel.c
+CLEANFILES             += wheel.h wheel.c
+noinst_PROGRAMS                += genwheel
+wheel.h: wheel.c
+wheel.c: genwheel$e
+       $(AM_V_GEN)./genwheel -hwheel.h -cwheel.c \
+               -sCATACOMB_WHEEL_H \
+               -n5 -t"unsigned char" -iwheel
+
+###--------------------------------------------------------------------------
+### Binary polynomial arithmetic.
+
+## User-visible binary polynomial arithmetic.
+pkginclude_HEADERS     += gf.h
+libcatacomb_la_SOURCES += gf-arith.c
+TESTS                  += gf-arith.$t
+libcatacomb_la_SOURCES += gf-exp.c gf-exp.h
+libcatacomb_la_SOURCES += gf-gcd.c
+TESTS                  += gf-gcd.$t
+EXTRA_DIST             += tests/gf
+
+## Low-level binary polynomial arithmetic.
+pkginclude_HEADERS     += gfx.h
+libcatacomb_la_SOURCES += gfx.c
+TESTS                  += gfx.$t
+libcatacomb_la_SOURCES += gfx-kmul.c
+TESTS                  += gfx-kmul.$t
+libcatacomb_la_SOURCES += gfx-sqr.c
+gfx-sqr.lo: gfx-sqr-tab.h
+TESTS                  += gfx-sqr.$t
+CLEANFILES             += gfx-sqr-tab.h
+noinst_PROGRAMS                += gfx-sqr-mktab
+gfx-sqr-tab.h: gfx-sqr-mktab$e
+       $(AM_V_GEN)./gfx-sqr-mktab >gfx-sqr-tab.h.in && \
+               mv gfx-sqr-tab.h.in gfx-sqr-tab.h
+EXTRA_DIST             += tests/gfx
+
+## Conversions between normal and polynomial basis representations for binary
+## fields.
+pkginclude_HEADERS     += gfn.h
+libcatacomb_la_SOURCES += gfn.c
+TESTS                  += gfn.$t
+EXTRA_DIST             += tests/gfn
+
+## Efficient reduction modulo sparse polynomials.
+pkginclude_HEADERS     += gfreduce.h
+libcatacomb_la_SOURCES += gfreduce.c gfreduce-exp.h
+TESTS                  += gfreduce.$t
+EXTRA_DIST             += tests/gfreduce
+
+###--------------------------------------------------------------------------
+### Abstractions for various kinds of algebraic objects.
+
+## Abstract cyclic groups.
+pkginclude_HEADERS     += group.h group-guts.h
+libcatacomb_la_SOURCES += group-dstr.c
+libcatacomb_la_SOURCES += group-exp.c group-exp.h
+libcatacomb_la_SOURCES += group-file.c
+libcatacomb_la_SOURCES += group-parse.c
+libcatacomb_la_SOURCES += group-stdops.c
+libcatacomb_la_SOURCES += group-string.c
+libcatacomb_la_SOURCES += g-bin.c
+libcatacomb_la_SOURCES += g-prime.c
+libcatacomb_la_SOURCES += g-ec.c
+EXTRA_DIST             += group-test.c
+TESTS                  += group-test.$t
+EXTRA_DIST             += tests/group
+
+## Abstract finite fields.
+pkginclude_HEADERS     += field.h field-guts.h
+libcatacomb_la_SOURCES += field.c
+libcatacomb_la_SOURCES += field-exp.c field-exp.h
+libcatacomb_la_SOURCES += field-parse.c
+libcatacomb_la_SOURCES += f-binpoly.c
+libcatacomb_la_SOURCES += f-niceprime.c
+libcatacomb_la_SOURCES += f-prime.c
+
+## Table of built-in binary fields.
+pkginclude_HEADERS     += bintab.h
+libcatacomb_la_SOURCES += bintab.c
+CLEANFILES             += bintab.c
+EXTRA_DIST             += bintab.in bin-gentab.awk
+bintab.c: bintab.in bin-gentab.awk mpdump$e
+       $(AM_V_GEN)awk -f $(srcdir)/bin-gentab.awk \
+               <$(srcdir)/bintab.in >bintab.c.new && \
+       mv bintab.c.new bintab.c
+
+## Table of built-in prime fields.
+pkginclude_HEADERS     += ptab.h
+libcatacomb_la_SOURCES += ptab.c
+CLEANFILES             += ptab.c
+EXTRA_DIST             += ptab.in p-gentab.awk
+ptab.c: ptab.in p-gentab.awk mpdump$e
+       $(AM_V_GEN)awk -f $(srcdir)/p-gentab.awk \
+               <$(srcdir)/ptab.in >ptab.c.new && \
+       mv ptab.c.new ptab.c
+
+## A utility for building multiprecision integer constants.
+noinst_PROGRAMS                += mpdump
+mpdump_LDADD            = libmpbase.la
+$(mpdump_OBJECTS): mptypes.h
+
+###--------------------------------------------------------------------------
+### Elliptic curve arithmetic.
+
+## Basic elliptic curve arithmetic.
+pkginclude_HEADERS     += ec.h ec-guts.h
+libcatacomb_la_SOURCES += ec.c
+libcatacomb_la_SOURCES += ec-exp.c ec-exp.h
+libcatacomb_la_SOURCES += ec-info.c
+TESTS                  += ec-info.$t
+libcatacomb_la_SOURCES += ec-bin.c
+TESTS                  += ec-bin.$t
+libcatacomb_la_SOURCES += ec-prime.c
+TESTS                  += ec-prime.$t
+EXTRA_DIST             += tests/ec
+
+## The standard `raw' encoding (`EC2OSP') of elliptic curve points.
+pkginclude_HEADERS     += ec-raw.h
+libcatacomb_la_SOURCES += ec-raw.c
+
+## Test infrastructure for elliptic curves.
+pkginclude_HEADERS     += ec-test.h
+libcatacomb_la_SOURCES += ec-test.c
+TESTS                  += ec-test.$t
+
+## A table of built-in elliptic curves.
+pkginclude_HEADERS     += ectab.h
+libcatacomb_la_SOURCES += ectab.c
+CLEANFILES             += ectab.c
+EXTRA_DIST             += ectab.in ec-gentab.awk
+ectab.c: ectab.in ec-gentab.awk mpdump$e
+       $(AM_V_GEN)awk -f $(srcdir)/ec-gentab.awk \
+               <$(srcdir)/ectab.in >ectab.c.new && \
+       mv ectab.c.new ectab.c
+
+###--------------------------------------------------------------------------
+### Autogenerated lists.
+
+## Fancy template substitutions.
+multigen                = python $(srcdir)/multigen
+EXTRA_DIST             += multigen
+
+## The heart of this is an enormous cross-product of crypto primitives and
+## the corresponding modes of operation.  Rather than write it out longhand,
+## we generate it using `multigen'.  Unfortunately, this needs to be done
+## at the Automake level, which causes some interesting bootstrapping
+## problems.
+include modes.am
+
+EXTRA_DIST             += modes.am.in modes.am
+MAINTAINERCLEANFILES   += $(srcdir)/modes.am
+
+## Generate the lists.
+$(srcdir)/modes.am: modes.am.in
+       $(AM_V_GEN)$(multigen) -g $(srcdir)/modes.am.in $(srcdir)/modes.am \
+               blkc="$(BLKCS)" \
+                       blkcmode="$(BLKCMODES)" \
+                       blkcciphermode="$(BLKCCIPHERMODES)" \
+               hash="$(HASHES)" \
+                       hashmode="$(HASHMODES)" \
+                       hashciphermode="$(HASHCIPHERMODES)" \
+                       hashmacmode="$(HASHMACMODES)"
+
+## Initialize lists of known classes.
+ALL_CIPHERS             = $(CIPHER_MODES)
+ALL_HASHES              = $(HASHES)
+ALL_MACS                = $(MAC_MODES)
+
+###--------------------------------------------------------------------------
+### Block ciphers.
+
+BLKCS                   =
+BLKCMODES               =
+
+BLKCCIPHERMODES                 =
+BLKCMODES              += $(BLKCCIPHERMODES)
+
+## A tool for translating the AES-contest test vectors into a form our test
+## rigs understand.
+EXTRA_DIST             += tests/aes-trans
+
+## Block cipher utility macros, mainly used in mode implementations.
+pkginclude_HEADERS     += blkc.h
+
+## Source code and headers for the block ciphers.
+libcatacomb_la_SOURCES += $(BLKC_C)
+pkginclude_HEADERS     += $(BLKC_H)
+
+## Schneier's `Blowfish' block cipher.
+BLKCS                  += blowfish
+blowfish.lo: blowfish-tab.h
+CLEANFILES             += blowfish-tab.h
+noinst_PROGRAMS                += blowfish-mktab
+blowfish-tab.h: blowfish-mktab$e
+       $(AM_V_GEN)./blowfish-mktab >blowfish-tab.h.new && \
+               mv blowfish-tab.h.new blowfish-tab.h
+
+## Adams and Tavares' `CAST' block ciphers.
+BLKCS                  += cast128 cast256
+libcatacomb_la_SOURCES += cast-s.c cast-sk.c cast-base.h cast-tab.h
+cast256.$t: tests/cast256
+EXTRA_DIST             += tests/cast256.aes
+MAINTAINERCLEANFILES   += $(srcdir)/tests/cast256
+tests/cast256: tests/cast256.aes
+       $(AM_V_GEN)$(srcdir)/tests/aes-trans CAST256 \
+               <$(srcdir)/tests/cast256.aes \
+               >$(srcdir)/tests/cast256.new && \
+       mv $(srcdir)/tests/cast256.new $(srcdir)/tests/cast256
+
+## IBM's `DES' block cipher, by Feistel, Coppersmith, and others.
+BLKCS                  += des des3
+libcatacomb_la_SOURCES += des-base.h des-base.c desx-tab.h
+des-base.lo: des-tab.h
+CLEANFILES             += des-tab.h
+noinst_PROGRAMS                += des-mktab
+des-tab.h: des-mktab$e
+       $(AM_V_GEN)./des-mktab >des-tab.h.new && \
+               mv des-tab.h.new des-tab.h
+
+## Rivest's `DESX' variant, with pre- and post-whitening.
+BLKCS                  += desx
+libcatacomb_la_SOURCES += desx-tab.h
+
+## Lai and Massey's IDEA.
+BLKCS                  += idea
+
+## IBM's `MARS' block cipher.
+BLKCS                  += mars
+mars.lo: mars-tab.h
+CLEANFILES             += mars-tab.h
+noinst_PROGRAMS                += mars-mktab
+mars-tab.h: mars-mktab$e
+       $(AM_V_GEN)./mars-mktab >mars-tab.h.new && \
+               mv mars-tab.h.new mars-tab.h
+mars.$t: tests/mars
+EXTRA_DIST             += tests/mars.aes
+MAINTAINERCLEANFILES   += $(srcdir)/tests/mars
+tests/mars: tests/mars.aes
+       $(AM_V_GEN)$(srcdir)/tests/aes-trans Mars \
+               <$(srcdir)/tests/mars.aes \
+               >$(srcdir)/tests/mars.new && \
+       mv $(srcdir)/tests/mars.new $(srcdir)/tests/mars
+
+## Daemen, Peeters, Van Assche and Rijmen's `Noekeon'.
+BLKCS                  += noekeon
+
+## Rivest's `RC2' block cipher.
+BLKCS                  += rc2
+libcatacomb_la_SOURCES += rc2-tab.h
+
+## Rivest's `RC5'.
+BLKCS                  += rc5
+
+## Daemen and Rijmen's `Rijndael' block cipher, selected as AES.
+BLKCS                  += rijndael rijndael192 rijndael256
+libcatacomb_la_SOURCES += rijndael-base.h rijndael-base.c
+rijndael-base.lo: rijndael-tab.h
+CLEANFILES             += rijndael-tab.h
+noinst_PROGRAMS                += rijndael-mktab
+rijndael-tab.h: rijndael-mktab$e
+       $(AM_V_GEN)./rijndael-mktab >rijndael-tab.h.new && \
+               mv rijndael-tab.h.new rijndael-tab.h
+rijndael.$t: tests/rijndael
+EXTRA_DIST             += tests/rijndael.aes
+MAINTAINERCLEANFILES   += $(srcdir)/tests/rijndael
+tests/rijndael: tests/rijndael.aes
+       $(AM_V_GEN)$(srcdir)/tests/aes-trans Rijndael \
+               <$(srcdir)/tests/rijndael.aes \
+               >$(srcdir)/tests/rijndael.new && \
+       mv $(srcdir)/tests/rijndael.new $(srcdir)/tests/rijndael
+
+## Massey's `SAFER' block ciphers.
+BLKCS                  += safer safersk
+safer.lo: safer-tab.h
+CLEANFILES             += safer-tab.h
+noinst_PROGRAMS                += safer-mktab
+safer-tab.h: safer-mktab$e
+       $(AM_V_GEN)./safer-mktab >safer-tab.h.new && \
+               mv safer-tab.h.new safer-tab.h
+
+## Anderson, Biham and Knudsen's `Serpent' block cipher.
+BLKCS                  += serpent
+libcatacomb_la_SOURCES += serpent-sbox.h
+noinst_PROGRAMS                += serpent-check
+TESTS                  += serpent-check
+serpent.$t: tests/serpent
+EXTRA_DIST             += tests/serpent.aes
+MAINTAINERCLEANFILES   += $(srcdir)/tests/serpent
+tests/serpent: tests/serpent.aes
+       $(AM_V_GEN)$(srcdir)/tests/aes-trans Serpent -v rev=1 \
+               <$(srcdir)/tests/serpent.aes \
+               >$(srcdir)/tests/serpent.new && \
+       mv $(srcdir)/tests/serpent.new $(srcdir)/tests/serpent
+
+## The National Security Agency's `Skipjack' block cipher.  You don't want to
+## use this.
+BLKCS                  += skipjack
+libcatacomb_la_SOURCES += skipjack-tab.h
+
+## Daemen and Rijmen's `Square' block cipher.
+BLKCS                  += square
+square.lo: square-tab.h
+CLEANFILES             += square-tab.h
+noinst_PROGRAMS                += square-mktab
+square-tab.h: square-mktab$e
+       $(AM_V_GEN)./square-mktab >square-tab.h.new && \
+               mv square-tab.h.new square-tab.h
+
+## Wheeler and Needham's `TEA' and `XTEA' block ciphers.
+BLKCS                  += tea xtea
+
+## Schneier, Kelsey, Whiting, Wagner, Hall and Ferguson's `Twofish' block
+## cipher.
+BLKCS                  += twofish
+twofish.lo: twofish-tab.h
+CLEANFILES             += twofish-tab.h
+noinst_PROGRAMS                += twofish-mktab
+twofish-tab.h: twofish-mktab$e
+       $(AM_V_GEN)./twofish-mktab >twofish-tab.h.new && \
+               mv twofish-tab.h.new twofish-tab.h
+twofish.$t: tests/twofish
+EXTRA_DIST             += tests/twofish.aes
+MAINTAINERCLEANFILES   += $(srcdir)/tests/twofish
+tests/twofish: tests/twofish.aes
+       $(AM_V_GEN)$(srcdir)/tests/aes-trans Twofish \
+               <$(srcdir)/tests/twofish.aes \
+               >$(srcdir)/tests/twofish.new && \
+       mv $(srcdir)/tests/twofish.new $(srcdir)/tests/twofish
+
+## The old NIST modes for DES.
+BLKCCIPHERMODES                += cbc cfb ecb ofb
+
+## Counter mode.
+BLKCCIPHERMODES                += counter
+
+###--------------------------------------------------------------------------
+### Hash functions.
+
+HASHES                  =
+HASHMODES               =
+
+HASHCIPHERMODES                 =
+HASHMODES              += $(HASHCIPHERMODES)
+
+HASHMACMODES            =
+HASHMODES              += $(HASHMACMODES)
+
+## Common definitions for hash functions.
+pkginclude_HEADERS     += hash.h
+
+## Source code and headers for the hash functions.
+libcatacomb_la_SOURCES += $(HASH_C)
+pkginclude_HEADERS     += $(HASH_H)
+
+## Lim and KISA's `HAS-160', recommended for use with KCDSA.
+HASHES                 += has160
+
+## Rivest's `MD' series of hash functions
+HASHES                 += md2 md4 md5
+libcatacomb_la_SOURCES += md2-tab.h
+
+## Dobbertin, Bosselaers and Preneel's `RIPEMD' suite.
+HASHES                 += rmd128 rmd160 rmd256 rmd320
+
+## The National Security Agency's `SHA-1' hash function.
+HASHES                 += sha
+
+## The National Security Agency's `SHA-2' suite.
+HASHES                 += sha224 sha256
+HASHES                 += sha384 sha512
+
+## Anderson and Biham's `Tiger' hash function.
+HASHES                 += tiger
+libcatacomb_la_SOURCES += tiger-base.h
+tiger.lo: tiger-tab.h
+CLEANFILES             += tiger-tab.h
+noinst_PROGRAMS                += tiger-mktab
+tiger-tab.h: tiger-mktab$e
+       $(AM_V_GEN)./tiger-mktab >tiger-tab.h.new && \
+               mv tiger-tab.h.new tiger-tab.h
+
+## Barreto and Rijmen's `Whirlpool' hash function.
+HASHES                 += whirlpool whirlpool256
+whirlpool.lo: whirlpool-tab.h
+CLEANFILES             += whirlpool-tab.h
+noinst_PROGRAMS                += whirlpool-mktab
+whirlpool-tab.h: whirlpool-mktab$e
+       $(AM_V_GEN)./whirlpool-mktab >whirlpool-tab.h.new && \
+               mv whirlpool-tab.h.new whirlpool-tab.h
+
+## Bellare, Canetti and Krawczyk's `HMAC' mode for message authentication.
+HASHMACMODES           += hmac
+
+## MGF1, used in OAEP and PSS.
+HASHCIPHERMODES                += mgf
+
+###--------------------------------------------------------------------------
+### Other symmetric primitives.
+
+## The CRC32 algorithm, which is useful, but has no worthwhile security.
+pkginclude_HEADERS     += crc32.h
+libcatacomb_la_SOURCES += crc32.c
+ALL_HASHES             += crc32=gcrc32
+
+## Rivest's `RC4' stream cipher.
+pkginclude_HEADERS     += rc4.h
+libcatacomb_la_SOURCES += rc4.c
+TESTS                  += rc4.$t
+EXTRA_DIST             += tests/rc4
+ALL_CIPHERS            += rc4
+
+## Coppersmith and Rogaway's `SEAL' pseudorandom function.
+pkginclude_HEADERS     += seal.h
+libcatacomb_la_SOURCES += seal.c
+TESTS                  += seal.$t
+EXTRA_DIST             += tests/seal
+ALL_CIPHERS            += seal
+###--------------------------------------------------------------------------
+### Autogenerated mode implementations.
+
+## The master stamp file, indicating that we generated all of the sources.
+CLEANFILES             += modes-gen-stamp
+EXTRA_DIST             += mode.h.in mode.c.in
+modes-gen-stamp:
+       $(AM_V_at)touch modes-gen-stamp
+       $(AM_V_GEN)$(multigen) -g $(srcdir)/mode.c.in \
+               @base-@mode.c \
+               base="$(BLKCS)" mode="$(BLKCMODES)"
+       $(AM_V_at)$(multigen) -g $(srcdir)/mode.c.in \
+               @base-@mode.c \
+               base="$(HASHES)" mode="$(HASHMODES)"
+       $(AM_V_at)$(multigen) -g $(srcdir)/mode.h.in \
+               @base-@mode.h \
+               base="$(BLKCS)" mode="$(BLKCMODES)"
+       $(AM_V_at)$(multigen) -g $(srcdir)/mode.h.in \
+               @base-@mode.h \
+               base="$(HASHES)" mode="$(HASHMODES)"
+       $(AM_V_at)touch modes-gen-stamp
+
+## The individual mode interfaces and implementations.
+pkginclude_HEADERS     += $(MODE_H)
+
+## Generated implementations.
+BUILT_SOURCES          += $(GENMODES_C)
+CLEANFILES             += $(GENMODES_C)
+nodist_libcatacomb_la_SOURCES += $(GENMODES_C)
+$(GENMODES_C): modes-gen-stamp
+
+## Generated interfaces.
+BUILT_SOURCES          += $(GENMODES_H)
+CLEANFILES             += $(GENMODES_H)
+nodist_pkginclude_HEADERS += $(GENMODES_H)
+$(GENMODES_H): modes-gen-stamp
+
+###--------------------------------------------------------------------------
+### Tables of classes for encryption, hashing, and message authentication.
+
+## The skeleton for the class tables.
+EXTRA_DIST             += gthingtab.c.in
+
+## Table of cipher classes.
+pkginclude_HEADERS     += gcipher.h
+CLEANFILES             += gciphertab.c
+nodist_libcatacomb_la_SOURCES += gciphertab.c
+gciphertab.c: gthingtab.c.in
+       $(AM_V_GEN)$(multigen) -g $(srcdir)/gthingtab.c.in gciphertab.c \
+               what=gcipher cls=gccipher thing="$(ALL_CIPHERS)"
+
+## Table of hash classes.
+pkginclude_HEADERS     += ghash.h ghash-def.h
+CLEANFILES             += ghashtab.c
+nodist_libcatacomb_la_SOURCES += ghashtab.c
+ghashtab.c: gthingtab.c.in
+       $(AM_V_GEN)$(multigen) -g $(srcdir)/gthingtab.c.in ghashtab.c \
+               what=ghash cls=gchash thing="$(ALL_HASHES)"
+
+## Table of MAC classes.
+pkginclude_HEADERS     += gmac.h
+CLEANFILES             += gmactab.c
+nodist_libcatacomb_la_SOURCES += gmactab.c
+gmactab.c: gthingtab.c.in
+       $(AM_V_GEN)$(multigen) -g $(srcdir)/gthingtab.c.in gmactab.c \
+               what=gmac cls=gcmac thing="$(ALL_MACS)"
+
+###--------------------------------------------------------------------------
+### Testing for symmetric crypto things.
+
+## Run the test programs.
+TESTS                  += $(SYMM_TESTS)
+EXTRA_DIST             += $(SYMM_TEST_FILES)
+
+## A piece of sample text for round-trip testing encryption modes.
+EXTRA_DIST             += daftstory.h
+
+###--------------------------------------------------------------------------
+### Key management.
+
+## Assistance for elliptic-curve keys.
+pkginclude_HEADERS     += ec-keys.h
+libcatacomb_la_SOURCES += ec-fetch.c
+
+## Managing keys and keyring files.
+pkginclude_HEADERS     += key.h
+libcatacomb_la_SOURCES += key-attr.c
+libcatacomb_la_SOURCES += key-fetch.c
+libcatacomb_la_SOURCES += key-file.c
+libcatacomb_la_SOURCES += key-io.c
+libcatacomb_la_SOURCES += key-misc.c
+libcatacomb_la_SOURCES += key-moan.c
+
+## Managing key data.
+pkginclude_HEADERS     += key-data.h
+libcatacomb_la_SOURCES += key-binary.c
+libcatacomb_la_SOURCES += key-data.c
+libcatacomb_la_SOURCES += key-flags.c
+libcatacomb_la_SOURCES += key-pack.c
+libcatacomb_la_SOURCES += key-pass.c
+libcatacomb_la_SOURCES += key-text.c
+
+## Error reporting.
+pkginclude_HEADERS     += key-error.h
+libcatacomb_la_SOURCES += key-error.c
+
+## Reading passphrases.
+pkginclude_HEADERS     += passphrase.h
+libcatacomb_la_SOURCES += passphrase.c
+
+## Interfacing with the passphrase pixie.
+pkginclude_HEADERS     += pixie.h
+libcatacomb_la_SOURCES += pixie-common.c
+
+###--------------------------------------------------------------------------
+### Secret sharing.
+
+## Efficient sharing over GF(2^8).
+pkginclude_HEADERS     += gfshare.h
+libcatacomb_la_SOURCES += gfshare.c
+gfshare.lo: gfshare-tab.h
+CLEANFILES             += gfshare-tab.h
+noinst_PROGRAMS                += gfshare-mktab
+gfshare-tab.h: gfshare-mktab$e
+       $(AM_V_GEN)./gfshare-mktab >gfshare-tab.h.new && \
+               mv gfshare-tab.h.new gfshare-tab.h
+TESTS                  += gfshare.$t
+
+## Number-theoretic sharing over GF(p).
+pkginclude_HEADERS     += share.h
+libcatacomb_la_SOURCES += share.c
+TESTS                  += share.$t
+
+###--------------------------------------------------------------------------
+### Public-key cryptography.
+
+## The Blum--Blum--Shub random-bit generator.
+pkginclude_HEADERS     += bbs.h
+libcatacomb_la_SOURCES += bbs-fetch.c
+libcatacomb_la_SOURCES += bbs-gen.c
+libcatacomb_la_SOURCES += bbs-jump.c
+TESTS                  += bbs-jump.$t
+libcatacomb_la_SOURCES += bbs-rand.c
+TESTS                  += bbs-rand.$t
+EXTRA_DIST             += tests/bbs
+
+## Plain Diffie--Hellman, in Schorr groups.
+pkginclude_HEADERS     += dh.h
+libcatacomb_la_SOURCES += dh-check.c
+libcatacomb_la_SOURCES += dh-fetch.c
+libcatacomb_la_SOURCES += dh-gen.c
+libcatacomb_la_SOURCES += dh-kcdsa.c
+libcatacomb_la_SOURCES += dh-limlee.c
+libcatacomb_la_SOURCES += dh-param.c
+TESTS                  += dh-param.$t
+
+## The National Security Agency's Digital Signature Algorithm.
+pkginclude_HEADERS     += dsa.h
+libcatacomb_la_SOURCES += dsa-gen.c
+TESTS                  += dsa-gen.$t
+libcatacomb_la_SOURCES += dsa-misc.c
+libcatacomb_la_SOURCES += dsa-sign.c
+TESTS                  += dsa-sign.$t
+libcatacomb_la_SOURCES += dsa-verify.c
+TESTS                  += dsa-verify.$t
+libcatacomb_la_SOURCES += dsa-check.c
+EXTRA_DIST             += tests/dsa
+
+## Generalization of DSA to arbitrary cyclic groups.
+pkginclude_HEADERS     += gdsa.h
+libcatacomb_la_SOURCES += gdsa.c
+TESTS                  += gdsa.$t
+EXTRA_DIST             += tests/gdsa
+
+## KISA `KCDSA', generalized to arbitrary cyclic groups.
+pkginclude_HEADERS     += gkcdsa.h
+libcatacomb_la_SOURCES += gkcdsa.c
+TESTS                  += gkcdsa.$t
+EXTRA_DIST             += tests/gkcdsa
+
+## General key validity checking machinery.
+pkginclude_HEADERS     += keycheck.h
+libcatacomb_la_SOURCES += keycheck.c
+libcatacomb_la_SOURCES += keycheck-mp.c
+libcatacomb_la_SOURCES += keycheck-report.c
+
+## The Rivest--Shamir--Adleman trapdoor one-way function.
+pkginclude_HEADERS     += rsa.h
+libcatacomb_la_SOURCES += rsa-fetch.c
+libcatacomb_la_SOURCES += rsa-gen.c
+libcatacomb_la_SOURCES += rsa-priv.c
+libcatacomb_la_SOURCES += rsa-pub.c
+libcatacomb_la_SOURCES += rsa-recover.c
+libcatacomb_la_SOURCES += oaep.c
+libcatacomb_la_SOURCES += pkcs1.c
+libcatacomb_la_SOURCES += pss.c
+EXTRA_DIST             += rsa-test.c
+TESTS                  += rsa-test.$t
+EXTRA_DIST             += tests/rsa
+
+###--------------------------------------------------------------------------
+### Random number generators.
+
+## The FIPS186 generator used to generate DSA domain parameters.
+pkginclude_HEADERS     += dsarand.h
+libcatacomb_la_SOURCES += dsarand.c
+
+## Knuth's lagged-Fibonacci generator.
+pkginclude_HEADERS     += fibrand.h
+libcatacomb_la_SOURCES += fibrand.c
+
+## The FIPS 140--2 random number generator tests.
+pkginclude_HEADERS     += fipstest.h
+libcatacomb_la_SOURCES += fipstest.c
+
+## Interface for generic random number sources.
+pkginclude_HEADERS     += grand.h
+libcatacomb_la_SOURCES += grand.c
+
+## A simple linear-congruential generator.
+pkginclude_HEADERS     += lcrand.h
+libcatacomb_la_SOURCES += lcrand.c
+TESTS                  += lcrand.$t
+EXTRA_DIST             += tests/lcrand
+
+## Maurer's universal statistical test.
+pkginclude_HEADERS     += maurer.h
+libcatacomb_la_SOURCES += maurer.c
+
+## System-specific noise acquisition.
+pkginclude_HEADERS     += noise.h
+libcatacomb_la_SOURCES += noise.c
+
+## Cryptographic laundering for true random data generation.
+pkginclude_HEADERS     += rand.h
+libcatacomb_la_SOURCES += rand.c
+
+## The SSL v3 pseudorandom function.
+pkginclude_HEADERS     += sslprf.h
+libcatacomb_la_SOURCES += sslprf.c
+TESTS                  += sslprf.$t
+EXTRA_DIST             += tests/sslprf
+
+## The TLS v1 pseudorandom function.
+pkginclude_HEADERS     += tlsprf.h
+libcatacomb_la_SOURCES += tlsprf.c
+TESTS                  += tlsprf.$t
+EXTRA_DIST             += tests/tlsprf
+
+###--------------------------------------------------------------------------
+### The `catcrypt' library.
+
+noinst_LTLIBRARIES     += libcatcrypt.la
+libcatcrypt_la_SOURCES  =
+
+## The main library.
+libcatcrypt_la_SOURCES += cc.h
+libcatcrypt_la_SOURCES += cc-enc.c
+libcatcrypt_la_SOURCES += cc-hash.c
+libcatcrypt_la_SOURCES += cc-kem.c
+libcatcrypt_la_SOURCES += cc-list.c
+libcatcrypt_la_SOURCES += cc-progress.c
+libcatcrypt_la_SOURCES += cc-sig.c
+libcatcrypt_la_SOURCES += cc-subcmd.c
+
+## Date parsing.
+libcatcrypt_la_SOURCES += getdate.h
+libcatcrypt_la_SOURCES += getdate.y
+
+###--------------------------------------------------------------------------
+### Utility programs.
+
+UTILS_LIBS              = libcatcrypt.la libcatacomb.la $(LIBS)
+
+## Generate and verify datestamped cookies.
+bin_PROGRAMS           += cookie
+cookie_LDADD            = $(UTILS_LIBS)
+dist_man_MANS          += cookie.1
+
+## Asymmetric message encryption and decryption with deniable authentication.
+bin_PROGRAMS           += catcrypt
+catcrypt_LDADD          = $(UTILS_LIBS)
+dist_man_MANS          += catcrypt.1
+
+## Signing and verifying files.
+bin_PROGRAMS           += catsign
+catsign_LDADD           = $(UTILS_LIBS)
+dist_man_MANS          += catsign.1
+
+## Issue and verify signatures on directory trees.
+bin_PROGRAMS           += dsig
+dsig_LDADD              = $(UTILS_LIBS)
+dist_man_MANS          += dsig.1
+
+## Compute factorials to arbitrary precision.
+bin_PROGRAMS           += factorial
+factorial_LDADD                 = $(UTILS_LIBS)
+
+## Compute Fibonacci numbers to arbitrary precision.
+bin_PROGRAMS           += fibonacci
+fibonacci_LDADD                 = $(UTILS_LIBS)
+
+## Compute hashes of files.
+bin_PROGRAMS           += hashsum
+hashsum_LDADD           = $(UTILS_LIBS)
+dist_man_MANS          += hashsum.1
+
+## Key management utility.
+bin_PROGRAMS           += key
+key_SOURCES             = keyutil.c
+key_LDADD               = $(UTILS_LIBS)
+dist_man_MANS          += key.1 keyring.5
+
+## Generate passphrases with given entropy using wordlists and Markov models.
+bin_PROGRAMS           += mkphrase
+mkphrase_LDADD          = $(UTILS_LIBS)
+dist_man_MANS          += mkphrase.1
+
+## Performance testing.
+bin_PROGRAMS           += perftest
+perftest_LDADD          = $(UTILS_LIBS)
+
+## Remember passphrases for limited periods of time.
+bin_PROGRAMS           += pixie
+pixie_SOURCES           = pixie.c
+pixie_LDADD             = libcatacomb.la
+dist_man_MANS          += pixie.1
+EXTRA_DIST             += xpixie
+
+## Generate random data.
+bin_PROGRAMS           += rspit
+rspit_LDADD             = $(UTILS_LIBS)
+
+###--------------------------------------------------------------------------
+### Testing.
+
+SUFFIXES               += .c .$t .to
+.c.to:
+       $(AM_V_CC)$(COMPILE) -c -DTEST_RIG -DSRCDIR=\"$(srcdir)\" $< -o $@
+.to.$t: libcatacomb.la
+       $(AM_V_CCLD)$(LINK) $< libcatacomb.la $(LIBS)
+.PRECIOUS: %.to
+CLEANFILES             += *.to *.$t
+
+###--------------------------------------------------------------------------
+### The pkg-config file.
+
+pkgconfigdir            = $(libdir)/pkgconfig
+pkgconfig_DATA          = catacomb.pc
+EXTRA_DIST             += catacomb.pc.in
+CLEANFILES             += catacomb.pc
+
+catacomb.pc: catacomb.pc.in Makefile
+       $(SUBST) $(srcdir)/catacomb.pc.in >$@.new $(SUBSTITUTIONS) && \
+               mv $@.new $@
+
+###--------------------------------------------------------------------------
+### Release tweaking.
+
+## Release number.
+dist-hook::
+       echo $(VERSION) >$(distdir)/RELEASE
+
+## Additional build tools.
+EXTRA_DIST             += auto-version
+
+###--------------------------------------------------------------------------
+### Debian.
+
+## General stuff.
+EXTRA_DIST             += debian/rules
+EXTRA_DIST             += debian/control
+EXTRA_DIST             += debian/changelog
+EXTRA_DIST             += debian/copyright
+
+## catacomb-bin
+EXTRA_DIST             += debian/catacomb-bin.prerm
+EXTRA_DIST             += debian/catacomb-bin.postinst
+EXTRA_DIST             += debian/catacomb-bin.config
+EXTRA_DIST             += debian/catacomb-bin.templates
+
+###----- That's all, folks --------------------------------------------------
diff --git a/Makefile.m4 b/Makefile.m4
deleted file mode 100644 (file)
index 636d9b6..0000000
+++ /dev/null
@@ -1,495 +0,0 @@
-## -*-m4-*-
-##
-## $Id$
-##
-## Makefile for Catacomb
-##
-## (c) 1999 Straylight/Edgeware
-##
-
-##----- Licensing notice ----------------------------------------------------
-##
-## This file is part of Catacomb.
-##
-## Catacomb is free software; you can redistribute it and/or modify
-## it under the terms of the GNU Library General Public License as
-## published by the Free Software Foundation; either version 2 of the
-## License, or (at your option) any later version.
-##
-## Catacomb is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-## GNU Library General Public License for more details.
-##
-## You should have received a copy of the GNU Library General Public
-## License along with Catacomb; if not, write to the Free
-## Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-## MA 02111-1307, USA.
-
-SUBDIRS = tests
-
-archincludedir = $(libdir)/catacomb/include
-
-## --- List handling macros ---
-##
-## List handling is nice, usually.  Unfortunately, I based this design on
-## TeX list macros rather than anything sensible...
-
-define(`_', `define(`_item', $1)define(`_item_2', $2)emit`'')
-define(`adorn', `pushdef(`emit', `$1`'_item`'$3')$2`'popdef(`emit')')
-define(`join',
-`pushdef(`emit', `adorn(``_(''_item`$2', `$3', ``)'')`'')$1`'popdef(`emit')')
-define(`addsuffix', `adorn(`', `$1', `$2')')
-define(`lit', `adorn(`', `$1', `')')
-define(`nl', `
-')
-
-define(`allwithsuffix',
-`addsuffix(`$1', `$3') addsuffix(`$2', `$3') dnl
-addsuffix(join(`$1', `-', `$2'), `$3')')
-
-## --- Autogenerated source files ---
-
-define(`ciphers', `dnl
-_(des) _(desx) _(des3) _(mars) dnl
-_(idea) _(safer) _(safersk) dnl
-_(blowfish) _(twofish) dnl
-_(tea) _(xtea) dnl
-_(rc2) _(rc5) dnl
-_(skipjack) dnl
-_(cast128) _(cast256) dnl
-_(square) _(rijndael) _(rijndael192) _(rijndael256) dnl
-_(serpent) _(noekeon)')
-define(`cipher_modes', `_(ecb) _(cbc) _(cfb) _(ofb) _(counter)')
-
-define(`hashes', `dnl
-_(md5) _(md4) _(md2) _(tiger) _(has160) dnl
-_(sha) _(sha224) _(sha256) _(sha384) _(sha512) dnl
-_(whirlpool) _(whirlpool256) dnl
-_(rmd128) _(rmd160) _(rmd256) _(rmd320)')
-define(`hash_modes', `_(mgf) _(hmac)')
-
-MODES = \
-       adorn(`$(srcdir)/', join(`ciphers', `-', `cipher_modes'), `.c') \
-       adorn(`$(srcdir)/', join(`ciphers', `-', `cipher_modes'), `.h') \
-       adorn(`$(srcdir)/', join(`hashes', `-', `hash_modes'), `.c') \
-       adorn(`$(srcdir)/', join(`hashes', `-', `hash_modes'), `.h')
-
-$(MODES): modes-stamp
-modes-stamp: genmodes
-       cd $(srcdir); ./genmodes "lit(`ciphers')" "lit(`cipher_modes')"
-       cd $(srcdir); ./genmodes "lit(`hashes')" "lit(`hash_modes')"
-       echo datestamp >modes-stamp
-
-define(`gen_tables', `dnl
-_(des) _(blowfish) _(twofish) dnl
-_(square) _(rijndael) _(whirlpool) dnl
-_(safer) _(mars) _(tiger) dnl
-_(gfshare) _(gfx-sqr)')
-
-autoheaders: \
-  addsuffix(`gen_tables', `-tab.h') \
-  primetab.h wheel.h mptypes.h mplimits.h
-define(`emit', `
-_item`'-tab.h: _item`'-mktab$(EXEEXT)
-       ./_item`'-mktab >_item`'-tab.h.new
-       mv _item`'-tab.h.new _item`'-tab.h')dnl
-gen_tables
-
-primetab.h: primetab.c
-primetab.c: genprimes$(EXEEXT)
-       ./genprimes -h primetab.h -c primetab.c \
-               -s CATACOMB_PRIMETAB_H -n 256 \
-               -t "unsigned short" -i primetab
-
-wheel.h: wheel.c
-wheel.c: genwheel$(EXEEXT)
-       ./genwheel -h wheel.h -c wheel.c \
-               -s CATACOMB_WHEEL_H -n 5 \
-               -t "unsigned char" -i wheel
-
-archinclude_HEADERS = mptypes.h mplimits.h
-mptypes.h: mptypes$(EXEEXT)
-       ./mptypes >mptypes.h.new
-       mv mptypes.h.new mptypes.h
-
-mplimits.h: genlimits$(EXEEXT)
-       ./genlimits h >mplimits.h.new
-       mv mplimits.h.new mplimits.h
-mplimits.c: genlimits$(EXEEXT)
-       ./genlimits c >mplimits.c.new
-       mv mplimits.c.new mplimits.c
-
-ectab.c: ectab.in ec-gentab.awk mpdump$(EXEEXT)
-       $(srcdir)/ec-gentab.awk <$(srcdir)/ectab.in >ectab.c.new
-       mv ectab.c.new ectab.c
-
-ptab.c: ptab.in p-gentab.awk mpdump$(EXEEXT)
-       $(srcdir)/p-gentab.awk <$(srcdir)/ptab.in >ptab.c.new
-       mv ptab.c.new ptab.c
-
-bintab.c: bintab.in bin-gentab.awk mpdump$(EXEEXT)
-       $(srcdir)/bin-gentab.awk <$(srcdir)/bintab.in >bintab.c.new
-       mv bintab.c.new bintab.c
-
-gciphertab.c: gengctab
-       $(srcdir)/gengctab gccipher gcipher >gciphertab.c.new \
-               "lit(join(`ciphers', `-', `cipher_modes')) \
-               lit(join(`hashes', `-', `_(mgf)')) \
-               rc4 seal"
-       mv gciphertab.c.new gciphertab.c
-
-gmactab.c: gengctab
-       $(srcdir)/gengctab gcmac gmac >gmactab.c.new \
-               "lit(join(`hashes', `-', `_(hmac)'))"
-       mv gmactab.c.new gmactab.c
-
-ghashtab.c: gengctab
-       $(srcdir)/gengctab gchash ghash >ghashtab.c.new \
-               "lit(`hashes') \
-               crc32=gcrc32"
-       mv ghashtab.c.new ghashtab.c
-
-BUILT_SOURCES = \
-       getdate.c modes-stamp gciphertab.c gmactab.c ghashtab.c \
-       addsuffix(join(`ciphers', `-', `cipher_modes'), `.c') \
-       addsuffix(join(`ciphers', `-', `cipher_modes'), `.h') \
-       addsuffix(join(`hashes', `-', `hash_modes'), `.c') \
-       addsuffix(join(`hashes', `-', `hash_modes'), `.h')
-
-## --- Building the main library ---
-
-lib_LTLIBRARIES = libcatacomb.la
-
-libcatacomb_la_LIBADD = $(CATACOMB_LIBS)
-libcatacomb_la_LDFLAGS = -version-info $(LIBTOOL_VERSION_INFO)
-## Middle number is the patchlevel.  Final number is the minor version.  The
-## difference between the first and last numbers is major version.
-
-pkginclude_HEADERS = \
-       arena.h paranoia.h buf.h ct.h qdparse.h keysz.h \
-       blkc.h hash.h gcipher.h ghash.h gmac.h grand.h ghash-def.h \
-       lcrand.h fibrand.h rc4.h seal.h rand.h noise.h fipstest.h maurer.h \
-       key.h key-error.h key-data.h passphrase.h pixie.h lmem.h \
-       mpx.h bitops.h mpw.h mpscan.h mparena.h mp.h mptext.h mpint.h \
-       exp.h mpbarrett.h mpmont.h mpreduce.h mp-exp.h \
-       mpcrt.h mprand.h mpmul.h mp-fibonacci.h \
-       gfx.h gf.h gfreduce.h gfn.h gf-exp.h \
-       primetab.h wheel.h pfilt.h rabin.h \
-       pgen.h primeiter.h prim.h strongprime.h limlee.h keycheck.h \
-       bbs.h rsa.h dh.h dsarand.h dsa.h gdsa.h gkcdsa.h \
-       tlsprf.h sslprf.h \
-       gfshare.h share.h \
-       rho.h \
-       field.h field-guts.h field-exp.h \
-       ec.h ec-guts.h ec-exp.h ec-test.h ectab.h ec-keys.h ec-raw.h \
-       ptab.h bintab.h group.h group-guts.h \
-       allwithsuffix(`ciphers', `cipher_modes', `.h') \
-       allwithsuffix(`hashes', `hash_modes', `.h') \
-       addsuffix(`cipher_modes', `-def.h') \
-       addsuffix(`hash_modes', `-def.h') crc32.h
-
-define(`MP_BASE',
-       `mpx.c mpx-kmul.c mpx-ksqr.c mpscan.c mparena.c \
-       mp-misc.c mp-mem.c mp-const.c mp-arith.c mp-io.c \
-       mptext.c mptext-string.c')
-
-define(`MP_SOURCES',
-       `qdparse.c \
-       mp-test.c mplimits.c \
-       mp-sqrt.c mp-gcd.c mp-jacobi.c mp-modsqrt.c mp-exp.c mp-modexp.c \
-       mpint.c mptext-file.c mptext-dstr.c \
-       mptext-len.c \
-       exp.c mpcrt.c mpmul.c mprand.c mp-fibonacci.c \
-       mpbarrett.c mpbarrett-exp.c mpbarrett-mexp.c mpbarrett-exp.h \
-       mpmont.c mpmont-exp.c mpmont-mexp.c mpmont-exp.h \
-       mpreduce.c mpreduce-exp.h \
-       group-stdops.c group-exp.c group-exp.h g-prime.c g-bin.c \
-         group-parse.c \
-       group-string.c group-file.c group-dstr.c \
-       rho.c buf.c ptab.c bintab.c \
-       GF_SOURCES PGEN_SOURCES EC_SOURCES')
-
-define(`GF_SOURCES',
-       `gfx.c gfx-kmul.c gfx-sqr.c gf-arith.c gf-exp.c gf-gcd.c \
-       gfreduce.c gfreduce-exp.h gfn.c')
-
-define(`EC_SOURCES',
-       `field.c field-parse.c field-exp.c \
-       f-prime.c f-niceprime.c f-binpoly.c \
-       ec.c ec-exp.c ec-prime.c ec-bin.c ec-test.c ec-info.c ectab.c \
-       ec-fetch.c ec-raw.c g-ec.c')
-
-define(`PGEN_SOURCES',
-       `pfilt.c primeiter.c rabin.c \
-       pgen.c pgen-stdev.c pgen-gcd.c pgen-simul.c \
-         prim.c strongprime.c limlee.c \
-       keycheck.c keycheck-mp.c keycheck-report.c \
-       bbs-rand.c bbs-gen.c bbs-jump.c bbs-fetch.c \
-       rsa-priv.c rsa-pub.c rsa-gen.c rsa-recover.c rsa-fetch.c \
-       oaep.c pkcs1.c pss.c \
-       dh-gen.c dh-limlee.c dh-kcdsa.c dh-check.c dh-fetch.c dh-param.c \
-       dsarand.c dsa-misc.c dsa-sign.c dsa-verify.c dsa-gen.c dsa-check.c \
-       gdsa.c gkcdsa.c \
-       key-data.c key-flags.c key-text.c key-binary.c key-pass.c \
-       key-pack.c key-misc.c key-file.c key-attr.c key-io.c key-moan.c \
-       key-error.c key-fetch.c \
-       primetab.c wheel.c share.c')
-
-libcatacomb_la_SOURCES = \
-       grand.c ct.c keysz.c keysz-conv.c \
-       lcrand.c fibrand.c rc4.c seal.c rand.c noise.c fipstest.c maurer.c \
-       arena.c \
-       passphrase.c pixie-common.c lmem.c \
-       tlsprf.c sslprf.c \
-       gfshare.c \
-       MP_BASE MP_SOURCES karatsuba.h \
-       gciphertab.c ghashtab.c gmactab.c \
-       des-base.c des-base.h \
-       desx-tab.h \
-       rc2-tab.h \
-       skipjack-tab.h \
-       cast-s.c cast-sk.c cast-base.h cast-tab.h \
-       rijndael-base.c rijndael-base.h \
-       md2-tab.h \
-       serpent-sbox.h skipjack-tab.h tiger-base.h \
-       daftstory.h \
-       addsuffix(join(`ciphers', `-', `cipher_modes'), `.c') \
-       addsuffix(join(`hashes', `-', `hash_modes'), `.c') \
-       addsuffix(`ciphers', `.c') addsuffix(`hashes', `.c') crc32.c
-
-des-base.lo: des-tab.h
-blowfish.lo: blowfish-tab.h
-twofish.lo: twofish-tab.h
-square.lo: square-tab.h
-rijndael-base.lo: rijndael-tab.h
-whirlpool.lo: whirlpool-tab.h
-safer.lo: safer-tab.h
-mars.lo: mars-tab.h
-tiger.lo: tiger-tab.h
-gfshare.lo: gfshare-tab.h
-gfx-sqr.lo: gfx-sqr-tab.h
-
-## --- Utility programs ---
-
-bin_PROGRAMS = \
-       dsig key pixie cookie rspit factorial fibonacci hashsum mkphrase \
-       catcrypt catsign
-noinst_LIBRARIES = libcatcrypt.a
-pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = catacomb.pc
-noinst_PROGRAMS = \
-       genprimes genwheel mptypes genlimits serpent-check bittest mpdump \
-       perftest \
-       addsuffix(`gen_tables', `-mktab')
-LDADD = libcatcrypt.a libcatacomb.la
-
-define(`LIBCAT_SRC', `cc.h getdate.h dnl
-       cc-sig.c cc-subcmd.c cc-enc.c cc-kem.c cc-hash.c \
-       cc-list.c cc-progress.c')
-libcatcrypt_a_SOURCES = LIBCAT_SRC getdate.y
-
-patsubst(MP_BASE MP_SOURCES, `\.c\>', `.lo') dsig.o keyutil.o rspit.o \
-       patsubst(LIBCAT_SRC, `\.c\>', `.o'): \
-       mptypes.h primetab.h wheel.h
-patsubst(MP_SOURCES, `\.c\>', `.lo'): mplimits.h
-
-dsig_SOURCES = dsig.c
-cookie_SOURCES = cookie.c
-catcrypt_SOURCES = catcrypt.c
-catsign_SOURCES = catsign.c
-key_SOURCES = keyutil.c
-hashsum_SOURCES = hashsum.c
-rspit_SOURCES = rspit.c
-factorial_SOURCES = factorial.c
-fibonacci_SOURCES = fibonacci.c
-perftest_SOURCES = perftest.c
-perftest_LDADD = $(CATACOMB_LIBS) $(LDADD)
-pixie_SOURCES = pixie.c pixie-common.c lmem.c arena.c passphrase.c
-pixie_LDADD = $(PIXIE_LIBS)
-pixie_CFLAGS = $(AM_CFLAGS)
-mkphrase_SOURCES = mkphrase.c
-mkphrase_LDADD = $(CATACOMB_LIBS) $(LDADD)
-bittest_SOURCES = bittest.c
-bittest_LDADD =
-
-define(`emit', `
-patsubst(_item, `[^a-zA-Z0-9]', `_')_mktab_SOURCES = _item`'-mktab.c
-patsubst(_item, `[^a-zA-Z0-9]', `_')_mktab_LDADD =')dnl
-gen_tables
-
-serpent_check_SOURCES = serpent-check.c
-serpent_check_LDADD =
-
-genprimes_SOURCES = genprimes.c
-genprimes_LDADD =
-
-genwheel_SOURCES = genwheel.c
-genwheel_LDADD =
-
-mptypes_SOURCES = mptypes.c
-mptypes_LDADD =
-
-genlimits_SOURCES = genlimits.c MP_BASE mptypes.h
-genlimits_LDADD =
-genlimits_CFLAGS = $(AM_CFLAGS)
-
-mpdump_SOURCES = mpdump.c MP_BASE
-mpdump_LDADD =
-mpdump_CFLAGS = $(AM_CFLAGS)
-
-## --- Install the pixie setuid-root if we can ---
-##
-## Bodge around a bug in Automake: it doesn't call `install-exec-hook' from
-## `install' if there are subdirectories.
-
-changequote(<, >)
-# install: install-exec-hook
-install-exec-hook:
-       @pixie="$(DESTDIR)$(bindir)/`echo pixie|sed $(transform)`"; \
-       if chown root $$pixie && chmod 4755 $$pixie; then \
-         echo "chown root $$pixie"; \
-         echo "chmod 4755 $$pixie"; \
-       else \
-         echo "***"; \
-         echo "*** You should probably install $$pixie setuid-root."; \
-         echo "***"; \
-       fi
-changequote(`, ')
-
-## --- Documentation ---
-
-man_MANS = \
-       key.1 dsig.1 cookie.1 catcrypt.1 catsign.1 hashsum.1 mkphrase.1 \
-       keyring.5 pixie.1
-
-## --- Prime group keyring ---
-
-#pkgdata_DATA = pgroups.kr
-
-$(srcdir)/pgroups.kr: ptab.in mkpgroups
-       cd $(srcdir) && rm -f pgroups.kr && ./mkpgroups <ptab.in
-
-## --- Other handy definitions ---
-
-EXTRA_DIST = \
-       Makefile.m4 genmodes gengctab $(man_MANS) xpixie \
-       group-test.c rsa-test.c \
-       ectab.in ec-gentab.awk \
-       ptab.in p-gentab.awk mkpgroups \
-       bintab.in bin-gentab.awk \
-       README.cipher README.hash README.random README.mp \
-       debian/rules debian/copyright debian/control debian/changelog \
-       debian/catacomb-bin.postinst debian/catacomb-bin.config \
-       debian/catacomb-bin.prerm debian/catacomb-bin.templates
-
-dist-hook:
-       @for i in getdate.c gciphertab.c ghashtab.c gmactab.c; do \
-         ln $$i $(distdir) || ln $(srcdir)/$$i $(distdir) || true; \
-       done
-       echo $(VERSION) >$(distdir)/RELEASE
-       @echo datestamp >$(distdir)/modes-stamp || true
-       @for i in calc tests; do \
-         mkdir $(distdir)/$$i; \
-         ln $(srcdir)/$$i/*[!~] $(distdir)/$$i; \
-       done || true
-#      kr=$$HOME/.catacomb/dsig-keyring; \
-#      if [ -r $$kr ]; then \
-#        cd $(distdir); \
-#        ../key -k $$kr extract -f -secret KEYRING; \
-#        find . -type f -print0 | ../dsig -k $$kr sign -0 -oMANIFEST; \
-#      fi
-
-## --- Testing ---
-
-define(`testprogs', `')
-
-define(`CTESTRIG',
-`define(`testprogs', testprogs \
-       $1.t$(EXEEXT))dnl
-$1.to: $1.c
-       $(COMPILE) -c -DTEST_RIG -DSRCDIR=\"$(srcdir)\" $(srcdir)/$1.c -o $1.to
-$1.t$(EXEEXT): $1.to libcatacomb.la
-       $(CC) $(CFLAGS) $(LDFLAGS) $1.to .libs/libcatacomb.a $(CATACOMB_LIBS) $(LIBS) -o $1.t$(EXEEXT)')
-
-CTESTRIG(rc4)
-CTESTRIG(seal)
-adorn(`nl`'CTESTRIG(', `ciphers', `)')
-adorn(`nl`'CTESTRIG(', `hashes', `)')
-adorn(`nl`'CTESTRIG(', join(`ciphers', `-', `cipher_modes'), `)')
-adorn(`nl`'CTESTRIG(', join(`hashes', `-', `hash_modes'), `)')
-CTESTRIG(lcrand)
-CTESTRIG(tlsprf)
-CTESTRIG(sslprf)
-CTESTRIG(mpx)
-CTESTRIG(mpx-kmul)
-CTESTRIG(mpx-ksqr)
-CTESTRIG(mp-arith)
-CTESTRIG(mp-modsqrt)
-CTESTRIG(mp-gcd)
-CTESTRIG(mp-jacobi)
-CTESTRIG(mp-sqrt)
-CTESTRIG(mp-modexp)
-CTESTRIG(mptext)
-CTESTRIG(mpint)
-CTESTRIG(mpbarrett)
-CTESTRIG(mpbarrett-exp)
-CTESTRIG(mpbarrett-mexp)
-CTESTRIG(mpmont)
-CTESTRIG(mpmont-exp)
-CTESTRIG(mpmont-mexp)
-CTESTRIG(mpreduce)
-CTESTRIG(mpcrt)
-CTESTRIG(mpmul)
-CTESTRIG(mp-fibonacci)
-CTESTRIG(rsa-test)
-CTESTRIG(gfx)
-CTESTRIG(gfx-sqr)
-CTESTRIG(gfx-kmul)
-CTESTRIG(gf-arith)
-CTESTRIG(gf-gcd)
-CTESTRIG(gfreduce)
-CTESTRIG(gfn)
-CTESTRIG(ec-prime)
-CTESTRIG(ec-bin)
-CTESTRIG(ec-test)
-CTESTRIG(ec-info)
-CTESTRIG(dh-param)
-CTESTRIG(group-test)
-CTESTRIG(gdsa)
-CTESTRIG(gkcdsa)
-CTESTRIG(pgen)
-CTESTRIG(primeiter)
-CTESTRIG(dsa-gen)
-CTESTRIG(dsa-sign)
-CTESTRIG(dsa-verify)
-CTESTRIG(bbs-rand)
-CTESTRIG(bbs-jump)
-CTESTRIG(gfshare)
-CTESTRIG(share)
-CTESTRIG(rho)
-
-TESTS = serpent-check bittest testprogs
-
-CLEANFILES = \
-       *.t$(EXEEXT) *.to *.kr.old \
-       mptypes.h mplimits.c mplimits.h \
-       primetab.c primetab.h wheel.c wheel.h \
-       ectab.c ptab.c bintab.c \
-       addsuffix(`gen_tables', `-tab.h')
-
-## --- Makefile building (haha!) ---
-
-$(srcdir)/Makefile.am: $(srcdir)/Makefile.m4
-       m4 $(srcdir)/Makefile.m4 >$(srcdir)/Makefile.am.new
-       mv $(srcdir)/Makefile.am.new $(srcdir)/Makefile.am
-
-DISTCLEANFILES = libtool
-
-MAINTAINERCLEANFILES = \
-       $(srcdir)/Makefile.am \
-       $(srcdir)/getdate.c getdate.c \
-       $(srcdir)/pgroups.kr \
-       $(MODES) modes-stamp $(srcdir)/modes-stamp
-
-##----- That's all, folks ---------------------------------------------------
diff --git a/build-setup b/build-setup
new file mode 100755 (executable)
index 0000000..50aabee
--- /dev/null
@@ -0,0 +1,2 @@
+#! /bin/sh -ex
+if [ ! -r modes.am ]; then touch -t197001010000.00 modes.am; fi
index eecc3a8..682b8d6 100644 (file)
@@ -30,6 +30,7 @@ dnl --- Boring boilerplate ---
 
 mdw_AUTO_VERSION
 AC_INIT(catacomb, AUTO_VERSION, mdw@distorted.org.uk)
 
 mdw_AUTO_VERSION
 AC_INIT(catacomb, AUTO_VERSION, mdw@distorted.org.uk)
+mdw_SILENT_RULES
 AC_CONFIG_SRCDIR(blkc.h)
 AC_CONFIG_AUX_DIR(.)
 AM_CONFIG_HEADER(config.h)
 AC_CONFIG_SRCDIR(blkc.h)
 AC_CONFIG_AUX_DIR(.)
 AM_CONFIG_HEADER(config.h)
@@ -113,7 +114,6 @@ dnl --- Done ---
 PKG_CHECK_MODULES(mLib, mLib >= 2.0.4)
 CFLAGS="$CFLAGS $mLib_CFLAGS"
 LIBS="$LIBS $mLib_LIBS"
 PKG_CHECK_MODULES(mLib, mLib >= 2.0.4)
 CFLAGS="$CFLAGS $mLib_CFLAGS"
 LIBS="$LIBS $mLib_LIBS"
-AC_OUTPUT(Makefile tests/Makefile catacomb.pc qcc,
-  chmod 755 qcc)
+AC_OUTPUT(Makefile)
 
 dnl ----- That's all, folks -------------------------------------------------
 
 dnl ----- That's all, folks -------------------------------------------------
diff --git a/gengctab b/gengctab
deleted file mode 100755 (executable)
index 9c8c17b..0000000
--- a/gengctab
+++ /dev/null
@@ -1,47 +0,0 @@
-#! /bin/sh
-
-set -e
-type=$1
-include=$2
-list=$3
-
-cat <<EOF
-/* -*-c-*-
- *
- * ${include}tab.c [generated]
- */
-
-#include <string.h>
-
-#include "$2.h"
-
-EOF
-for i in $list; do
-  name=`echo $i | sed 's/=.*$//'`
-  echo "#include \"$name.h\""
-done
-
-cat <<EOF
-
-const $type *const ${include}tab[] = {
-EOF
-for i in $list; do
-  c=`echo $i | sed 's/^.*=//; s/[^A-Za-z0-9_][^A-Za-z0-9_]*/_/g'`
-  echo "  &$c,"
-done
-cat <<EOF
-  0
-};
-
-const $type *${include}_byname(const char *p)
-{
-  const $type *const *c;
-
-  for (c = ${include}tab; *c; c++) {
-    if (strcmp(p, (*c)->name) == 0)
-      return (*c);
-  }
-  return (0);
-}
-
-EOF
diff --git a/genmodes b/genmodes
deleted file mode 100755 (executable)
index 76b82a6..0000000
--- a/genmodes
+++ /dev/null
@@ -1,64 +0,0 @@
-#! /bin/sh
-
-set -e
-baselist=$1
-extlist=$2
-
-for i in $baselist; do
-  I=`echo "$i" | tr -d '\n' | tr a-z A-Z | tr -c a-zA-Z0-9 _`
-  for j in $extlist; do
-    J=`echo "$j" | tr -d '\n' | tr a-z A-Z | tr -c a-zA-Z0-9 _`
-    guard="CATACOMB_${I}_${J}_H"
-    cat >$i-$j.h.new <<EOF
-/* -*-c-*-
- *
- * $i-$j.h [generated]
- */
-
-#ifndef $guard
-#define $guard
-
-#ifdef __cplusplus
-  extern "C" {
-#endif
-
-#ifndef CATACOMB_${J}_H
-#  include "$j.h"
-#endif
-
-#ifndef CATACOMB_${I}_H
-#  include "$i.h"
-#endif
-
-${J}_DECL($I, $i)
-
-#ifdef __cplusplus
-  }
-#endif
-
-#endif
-EOF
-    if cmp "$i-$j.h" "$i-$j.h.new" >/dev/null 2>&1; then
-      rm "$i-$j.h.new"
-    else
-      mv "$i-$j.h.new" "$i-$j.h"
-      echo >&2 "Written new $i-$j.h."
-    fi
-    cat >$i-$j.c.new <<EOF
-/* -*-c-*-
- *
- * $i-$j.c [generated]
- */
-
-#include "$i-$j.h"
-#include "$j-def.h"
-${J}_DEF($I, $i)
-EOF
-    if cmp "$i-$j.c" "$i-$j.c.new" >/dev/null 2>&1; then
-      rm "$i-$j.c.new"
-    else
-      mv "$i-$j.c.new" "$i-$j.c"
-      echo >&2 "Written new $i-$j.c."
-    fi
-  done
-done
diff --git a/gthingtab.c.in b/gthingtab.c.in
new file mode 100644 (file)
index 0000000..1c51520
--- /dev/null
@@ -0,0 +1,32 @@
+%## -*-c-*-
+%##
+%## Skeleton source file for tables of crypto classes
+%#
+/* -*-c-*- GENERATED from gthingtab.c.in
+ *
+ * @{what}tab.c
+ */
+
+#include <string.h>
+
+#include "@what.h"
+
+%repeat
+#include "@{thing:left}.h"
+%end
+
+const @cls *const @{what}tab[] = {
+%repeat
+  &@{thing:right:c},
+%end
+  0
+};
+
+const @cls *@{what}_byname(const char *p)
+{
+  const @cls *const *c;
+
+  for (c = @{what}tab; *c; c++)
+    if (strcmp(p, (*c)->name) == 0) return (*c);
+  return (0);
+}
diff --git a/mode.c.in b/mode.c.in
new file mode 100644 (file)
index 0000000..c46ef1c
--- /dev/null
+++ b/mode.c.in
@@ -0,0 +1,12 @@
+%## -*-c-*-
+%##
+%## Skeleton source file for modes of operation.
+%#
+/* -*-c-*- GENERATED from mode.c.in
+ *
+ * @base-@mode.c
+ */
+
+#include "@base-@mode.h"
+#include "@mode-def.h"
+@{mode:u}_DEF(@{base:u}, @base)
diff --git a/mode.h.in b/mode.h.in
new file mode 100644 (file)
index 0000000..fc4fb95
--- /dev/null
+++ b/mode.h.in
@@ -0,0 +1,31 @@
+%## -*-c-*-
+%##
+%## Skeleton header file for modes of operation.
+%#
+/* -*-c-*- GENERATED from mode.h.in
+ *
+ * @base-@mode.h
+ */
+
+#ifndef CATACOMB_@{base:u}_@{mode:u}_H
+#define CATACOMB_@{base:u}_@{mode:u}_H
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
+#ifndef CATACOMB_@{mode:u}_H
+#  include "@mode.h"
+#endif
+
+#ifndef CATACOMB_@{base:u}_H
+#  include "@base.h"
+#endif
+
+@{mode:u}_DECL(@{base:u}, @base)
+
+#ifdef __cplusplus
+  }
+#endif
+
+#endif
diff --git a/modes.am.in b/modes.am.in
new file mode 100644 (file)
index 0000000..88ee217
--- /dev/null
@@ -0,0 +1,67 @@
+%## -*-makefile-*-
+%#
+### -*-makefile-*- GENERATED from modes.make.in
+###
+### Lots of lists of crypto primitives in various modes of operation.
+
+SYMM_TESTS =
+
+GENMODES_C =
+GENMODES_H =
+
+%repeat
+GENMODES_C += @blkc-@blkcmode.c
+GENMODES_H += @blkc-@blkcmode.h
+SYMM_TESTS += @blkc-@blkcmode.$t
+%end
+
+%repeat
+GENMODES_C += @hash-@hashmode.c
+GENMODES_H += @hash-@hashmode.h
+SYMM_TESTS += @hash-@hashmode.$t
+%end
+
+MODE_H =
+%repeat
+MODE_H += @blkcmode.h @blkcmode-def.h
+%end
+%repeat
+MODE_H += @hashmode.h @hashmode-def.h
+%end
+
+BLKC_C =
+BLKC_H =
+%repeat
+BLKC_C += @blkc.c
+BLKC_H += @blkc.h
+SYMM_TESTS += @blkc.$t
+%end
+
+HASH_C =
+HASH_H =
+%repeat
+HASH_C += @hash.c
+HASH_H += @hash.h
+SYMM_TESTS += @hash.$t
+%end
+
+CIPHER_MODES =
+%repeat
+CIPHER_MODES += @blkc-@blkcciphermode
+%end
+%repeat
+CIPHER_MODES += @hash-@hashciphermode
+%end
+
+MAC_MODES =
+%repeat
+MAC_MODES += @hash-@hashmacmode
+%end
+
+SYMM_TEST_FILES =
+%repeat
+SYMM_TEST_FILES += tests/@blkc
+%end
+%repeat
+SYMM_TEST_FILES += tests/@hash
+%end
diff --git a/multigen b/multigen
new file mode 100755 (executable)
index 0000000..2d626c2
--- /dev/null
+++ b/multigen
@@ -0,0 +1,406 @@
+#! @PYTHON@
+###
+### Generate files by filling in simple templates
+###
+### (c) 2013 Straylight/Edgeware
+###
+
+###----- Licensing notice ---------------------------------------------------
+###
+### This file is part of Catacomb.
+###
+### Catacomb is free software; you can redistribute it and/or modify
+### it under the terms of the GNU Library General Public License as
+### published by the Free Software Foundation; either version 2 of the
+### License, or (at your option) any later version.
+###
+### Catacomb is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+### GNU Library General Public License for more details.
+###
+### You should have received a copy of the GNU Library General Public
+### License along with Catacomb; if not, write to the Free
+### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+### MA 02111-1307, USA.
+
+from __future__ import with_statement
+
+import itertools as IT
+import optparse as OP
+import os as OS
+import re as RX
+from cStringIO import StringIO
+from sys import argv, exit, stderr
+
+###--------------------------------------------------------------------------
+### Utilities.
+
+QUIS = OS.path.basename(argv[0])
+
+def die(msg):
+  stderr.write('%s: %s\n' % (QUIS, msg))
+  exit(1)
+
+def indexed(seq):
+  return IT.izip(IT.count(), seq)
+
+###--------------------------------------------------------------------------
+### Reading the input values.
+
+COLMAP = {}
+
+class Cursor (object):
+  def __init__(me, rel):
+    me._rel = rel
+    me._i = 0
+    me._row = rel[0]
+  def step(me):
+    me._i += 1
+    if me._i >= len(me._rel):
+      me._i = me._row = None
+      return False
+    me._row = me._rel[me._i]
+    return True
+  def reset(me):
+    me._i = 0
+    me._row = me._rel[0]
+  def __getitem__(me, i):
+    return me._row[i]
+  def __repr__(me):
+    return '#<Cursor %r[%d] = %r>' % (me._rel, me._i, me._row)
+
+class CursorSet (object):
+  def __init__(me):
+    me._map = {}
+    me._stack = []
+    me._act = None
+  def push(me, rels):
+    cc = []
+    rr = []
+    for r in rels:
+      if r in me._map: continue
+      c = me._map[r] = Cursor(r)
+      rr.append(r)
+      cc.append(c)
+    me._stack.append((me._act, rr))
+    me._act = cc
+  def step(me):
+    i = 0
+    while i < len(me._act):
+      if me._act[i].step(): return True
+      if i >= len(me._act): return False
+      me._act[i].reset()
+      i += 1
+    return False
+  def pop(me):
+    me._act, rels = me._stack.pop()
+    for r in rels: del me._map[r]
+  def get(me, rel, i):
+    return me._map[rel][i]
+
+class Relation (object):
+  def __init__(me, head):
+    me._head = head
+    me._rows = []
+    for i, c in indexed(head): COLMAP[c] = me, i
+  def addrow(me, row):
+    if len(row) != len(me._head):
+      die("mismatch: row `%s' doesn't match heading `%s'" %
+          (', '.join(row), ', '.join(head)))
+    me._rows.append(row)
+  def __len__(me):
+    return len(me._rows)
+  def __getitem__(me, i):
+    return me._rows[i]
+  def __repr__(me):
+    return '#<Relation %r>' % me._head
+
+def read_immediate(word):
+  head, rels = word.split('=', 1)
+  rel = Relation([c.strip() for c in head.split(',')])
+  for row in rels.split(): rel.addrow([c.strip() for c in row.split(',')])
+
+def read_file(spec):
+  file, head = spec.split(':', 1)
+  rel = Relation([c.strip() for c in head.split(',')])
+  cols = [c.strip() for c in head.split(',')]
+  with open(file) as f:
+    for line in f:
+      line = line.strip()
+      if line.startswith('#') or line == '': continue
+      rel.addrow(line.split())
+
+def read_thing(spec):
+  if spec.startswith('@'): read_file(spec[1:])
+  else: read_immediate(spec)
+
+###--------------------------------------------------------------------------
+### Template structure.
+
+class BasicTemplate (object):
+  pass
+
+class LiteralTemplate (BasicTemplate):
+  def __init__(me, text, **kw):
+    super(LiteralTemplate, me).__init__(**kw)
+    me._text = text
+  def relations(me):
+    return set()
+  def subst(me, out, cs):
+    out.write(me._text)
+  def __repr__(me):
+    return '#<LiteralTemplate %r>' % me._text
+
+class TagTemplate (BasicTemplate):
+  def __init__(me, rel, i, op, **kw):
+    super(TagTemplate, me).__init__(**kw)
+    me._rel = rel
+    me._i = i
+    me._op = op
+  def relations(me):
+    return set([me._rel])
+  def subst(me, out, cs):
+    val = cs.get(me._rel, me._i)
+    if me._op is not None: val = me._op(val)
+    out.write(val)
+  def __repr__(me):
+    return '#<TagTemplate %s>' % me._rel._head[me._i]
+
+class SequenceTemplate (BasicTemplate):
+  def __new__(cls, seq, **kw):
+    if len(seq) == 1:
+      return seq[0]
+    else:
+      me = super(SequenceTemplate, cls).__new__(cls, seq = seq, **kw)
+      tt = []
+      cls = type(me)
+      for t in seq:
+        if isinstance(t, cls): tt += t._seq
+        else: tt.append(t)
+      me._seq = tt
+      return me
+  def __init__(me, seq, **kw):
+    super(SequenceTemplate, me).__init__(**kw)
+  def relations(me):
+    rr = set()
+    for t in me._seq: rr.update(t.relations())
+    return rr
+  def subst(me, out, cs):
+    for t in me._seq: t.subst(out, cs)
+  def __repr__(me):
+    return '#<SequenceTemplate %r>' % me._seq
+
+class RepeatTemplate (BasicTemplate):
+  def __init__(me, sub):
+    me._sub = sub
+  def relations(me):
+    return set()
+  def subst(me, out, cs):
+    rr = me._sub.relations()
+    for r in rr:
+      if len(r) == 0: return
+    cs.push(rr)
+    while True:
+      me._sub.subst(out, cs)
+      if not cs.step(): break
+    cs.pop()
+  def __repr__(me):
+    return '#<RepeatTemplate %r>' % me._sub
+
+###--------------------------------------------------------------------------
+### Some slightly cheesy parsing machinery.
+
+class ParseState (object):
+  def __init__(me, file, text):
+    me._file = file
+    me._i = 0
+    me._it = iter(text.splitlines(True))
+    me.step()
+  def step(me):
+    me.curr = next(me._it, None)
+    if me.curr is not None: me._i += 1
+  def error(me, msg):
+    die('%s:%d: %s' % (me._file, me._i, msg))
+
+class token (object):
+  def __init__(me, name):
+    me._name = name
+  def __repr__(me):
+    return '#<%s>' % me._name
+
+EOF = token('eof')
+END = token('end')
+
+R_SIMPLETAG = RX.compile(r'@ (\w+)', RX.VERBOSE)
+R_COMPLEXTAG = RX.compile(r'@ { (\w+) ((?: : \w+)*) }', RX.VERBOSE)
+
+OPMAP = {}
+
+def defop(func):
+  name = func.func_name
+  if name.startswith('op_'): name = name[3:]
+  OPMAP[name] = func
+  return func
+
+@defop
+def op_u(val): return val.upper()
+
+@defop
+def op_l(val): return val.lower()
+
+R_NOTIDENT = RX.compile(r'[^a-zA-Z0-9_]+')
+@defop
+def op_c(val): return R_NOTIDENT.sub('_', val)
+
+def _pairify(val):
+  c = val.find('=')
+  if c >= 0: return val[:c], val[c + 1:]
+  else: return val, val
+
+@defop
+def op_left(val): return _pairify(val)[0]
+@defop
+def op_right(val): return _pairify(val)[1]
+
+def parse_text(ps):
+  tt = []
+  lit = StringIO()
+  def spill():
+    l = lit.getvalue()
+    if l: tt.append(LiteralTemplate(l))
+    lit.reset()
+    lit.truncate()
+  while True:
+    line = ps.curr
+    if line is None: break
+    elif line.startswith('%'):
+      if line.startswith('%#'): ps.step(); continue
+      elif line.startswith('%%'): line = line[1:]
+      else: break
+    i = 0
+    while True:
+      j = line.find('@', i)
+      if j < 0: break
+      lit.write(line[i:j])
+      m = R_SIMPLETAG.match(line, j)
+      if not m: m = R_COMPLEXTAG.match(line, j)
+      if not m: ps.error('invalid tag')
+      col = m.group(1)
+      try: rel, i = COLMAP[col]
+      except KeyError: ps.error("unknown column `%s'" % col)
+      wholeop = None
+      ops = m.lastindex >= 2 and m.group(2)
+      if ops:
+        for opname in ops[1:].split(':'):
+          try: op = OPMAP[opname]
+          except KeyError: ps.error("unknown operation `%s'" % opname)
+          if wholeop is None: wholeop = op
+          else: wholeop = (lambda f, g: lambda x: f(g(x)))(op, wholeop)
+      spill()
+      tt.append(TagTemplate(rel, i, wholeop))
+      i = m.end()
+    lit.write(line[i:])
+    ps.step()
+  spill()
+  return SequenceTemplate(tt)
+
+DIRECT = []
+
+def direct(rx):
+  def _(func):
+    DIRECT.append((RX.compile(rx, RX.VERBOSE), func))
+    return func
+  return _
+
+def parse_template(ps):
+  while ps.curr is not None and ps.curr.startswith('%#'): ps.step()
+  if ps.curr is None: return EOF
+  elif ps.curr.startswith('%'):
+    if ps.curr.startswith('%%'): return parse_text(ps)
+    for rx, func in DIRECT:
+      line = ps.curr[1:].strip()
+      m = rx.match(line)
+      if m:
+        ps.step()
+        return func(ps, m)
+    ps.error("unrecognized directive")
+  else:
+    return parse_text(ps)
+
+def parse_templseq(ps, nestp):
+  tt = []
+  while True:
+    t = parse_template(ps)
+    if t is END:
+      if nestp: break
+      else: ps.error("unexpected `end' directive")
+    elif t is EOF:
+      if nestp: ps.error("unexpected end of file")
+      else: break
+    tt.append(t)
+  return SequenceTemplate(tt)
+
+@direct(r'repeat')
+def dir_repeat(ps, m):
+  return RepeatTemplate(parse_templseq(ps, True))
+
+@direct(r'end')
+def dir_end(ps, m):
+  return END
+
+def compile_template(file, text):
+  ps = ParseState(file, text)
+  t = parse_templseq(ps, False)
+  return t
+
+###--------------------------------------------------------------------------
+### Main code.
+
+op = OP.OptionParser(
+  description = 'Generates files by filling in simple templates',
+  usage = 'usage: %prog [-gl] FILE [COL,...=VAL,... ... | @FILE:COL,...] ...',
+  version = 'Catacomb version @VERSION@')
+for short, long, kw in [
+  ('-l', '--list', dict(
+      action = 'store_const', const = 'list', dest = 'mode',
+      help = 'list filenames generated')),
+  ('-g', '--generate', dict(
+      action = 'store', metavar = 'PATH', dest = 'input',
+      help = 'generate output (default)'))]:
+  op.add_option(short, long, **kw)
+op.set_defaults(mode = 'gen')
+opts, args = op.parse_args()
+
+if len(args) < 1: op.error('missing FILE')
+filepat = args[0]
+for rel in args[1:]: read_thing(rel)
+filetempl = compile_template('<output>', filepat)
+
+def filenames(filetempl):
+  cs = CursorSet()
+  rr = filetempl.relations()
+  for r in rr:
+    if not len(r): return
+  cs.push(rr)
+  while True:
+    out = StringIO()
+    filetempl.subst(out, cs)
+    yield out.getvalue(), cs
+    if not cs.step(): break
+  cs.pop()
+
+if opts.mode == 'list':
+  for file, cs in filenames(filetempl): print file
+elif opts.mode == 'gen':
+  with open(opts.input) as f:
+    templ = RepeatTemplate(compile_template(opts.input, f.read()))
+  for file, cs in filenames(filetempl):
+    new = file + '.new'
+    with open(new, 'w') as out:
+      templ.subst(out, cs)
+    OS.rename(new, file)
+else:
+  raise Exception, 'What am I doing here?'
+
+###----- That's all, folks --------------------------------------------------
diff --git a/qcc.in b/qcc.in
deleted file mode 100644 (file)
index 70a1ab3..0000000
--- a/qcc.in
+++ /dev/null
@@ -1,14 +0,0 @@
-#! /bin/sh
-
-srcdir="@srcdir@"
-CC="@CC@" CFLAGS="@CFLAGS@" LDFLAGS="@LDFLAGS@"
-DEFS="@DEFS@ -I. -I${srcdir}"
-LDADD=".libs/libcatacomb.a @LIBS@"
-
-if [ "$1" = "-t" ]; then
-  shift
-  set -- -DTEST_RIG -DSRCDIR="\"$srcdir\"" "$@"
-fi
-
-echo $CC $DEFS $CFLAGS $LDFLAGS "$@" $LDADD
-exec $CC $DEFS $CFLAGS "$@" $LDADD
index e2894a1..8b605eb 100644 (file)
@@ -1,5 +1,3 @@
-Makefile.am
-Makefile.in
 cast256
 mars
 rijndael
 cast256
 mars
 rijndael
diff --git a/tests/Makefile.m4 b/tests/Makefile.m4
deleted file mode 100644 (file)
index 676d78a..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-## -*-fundamental-*-
-##
-## $Id: Makefile.m4,v 1.3 2004/04/08 01:36:15 mdw Exp $
-##
-## Build test vector files
-##
-## (c) 2000 Straylight/Edgeware
-##
-
-##----- Licensing notice ----------------------------------------------------
-##
-## This file is part of Catacomb.
-##
-## Catacomb is free software; you can redistribute it and/or modify
-## it under the terms of the GNU Library General Public License as
-## published by the Free Software Foundation; either version 2 of the
-## License, or (at your option) any later version.
-##
-## Catacomb is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-## GNU Library General Public License for more details.
-##
-## You should have received a copy of the GNU Library General Public
-## License along with Catacomb; if not, write to the Free
-## Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-## MA 02111-1307, USA.
-
-AUTOMAKE_OPTIONS = foreign
-
-## --- Building test rigs ---
-
-define(`aestests', `dnl
-_(`cast256', `CAST256')`'dnl
-_(`serpent', `Serpent', `-v rev=1')`'dnl
-_(`twofish', `Twofish')`'dnl
-_(`rijndael', `Rijndael')`'dnl
-_(`mars', `MARS')`'dnl
-')
-
-all: Makefile define(`_', ` $(srcdir)/$1')aestests
-
-define(`_', `dnl
-$(srcdir)/$1: $(srcdir)/$1.aes
-       cd $(srcdir); ./aes-trans $2 $3 <$1.aes >$1
-')
-aestests
-
-EXTRA_DIST = define(`_', ` $(srcdir)/$1')aestests
-MAINTAINERCLEANFILES = define(`_', ` $(srcdir)/$1')aestests
-
-## --- Building the Makefile ---
-
-$(srcdir)/Makefile.am: $(srcdir)/Makefile.m4
-       cd $(srcdir); m4 Makefile.m4 >Makefile.am
-
-##----- That's all, folks ---------------------------------------------------