chiark / gitweb /
secnet.git
5 years agoREADME.make-secnet-sites: Algorithm negotiation control keywords wip.xdh.v5
Ian Jackson [Sun, 15 Dec 2019 20:34:56 +0000 (20:34 +0000)]
README.make-secnet-sites: Algorithm negotiation control keywords

Write down the proposed new scheme, before we implement it.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoMake the `dh' property be listish
Mark Wooding [Thu, 2 Jan 2020 00:05:17 +0000 (00:05 +0000)]
Make the `dh' property be listish

(This was originally only part of a larger commit by Mark Wooding;
I (Ian Jackson) have split it out.)

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agomake-secnet-sites: Add XDH groups
Mark Wooding [Fri, 28 Apr 2017 21:51:36 +0000 (22:51 +0100)]
make-secnet-sites: Add XDH groups

(This was originally only part of a larger commit by Mark Wooding;
I (Ian Jackson) have split it out.)

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoxdh: End-to-end tests for the new DH key agreement groups
Ian Jackson [Thu, 2 Jan 2020 00:15:27 +0000 (00:15 +0000)]
xdh: End-to-end tests for the new DH key agreement groups

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoxdh.c: New module defining elliptic curve Diffie--Hellman functions.
Ian Jackson [Wed, 1 Jan 2020 23:56:47 +0000 (23:56 +0000)]
xdh.c: New module defining elliptic curve Diffie--Hellman functions.

This provides X25519 and X448 as premade Diffie--Hellman closures.  They
should be used directly rather than applied to arguments.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocrypto tests: Wire into Makefiles
Mark Wooding [Wed, 1 Jan 2020 23:56:39 +0000 (23:56 +0000)]
crypto tests: Wire into Makefiles

We make every .o file depend on $(cat_CATS) because that's easier than
trying to write out a list of which ones need the includes from
Catacomb.

(This is largely a commit by Mark Wooding supplied to me as a
work-in-progress, but I (Ian Jackson) have edited it to fit in with
the new subdirmk build system etc.)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocrypto-test: Generic test C file for XDH (X448, X25519)
Mark Wooding [Sat, 29 Apr 2017 12:55:40 +0000 (13:55 +0100)]
crypto-test: Generic test C file for XDH (X448, X25519)

This is a test driver for the field and curve arithmetic.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoec-field-test.c: Make the field-element type use internal format.
Mark Wooding [Fri, 27 Sep 2019 00:04:07 +0000 (01:04 +0100)]
ec-field-test.c: Make the field-element type use internal format.

And add a flag to distinguish the `bad' output from `..._quosqrt'.

5 years agocrypto-test.c: Don't print dead registers.
Mark Wooding [Fri, 27 Sep 2019 00:03:48 +0000 (01:03 +0100)]
crypto-test.c: Don't print dead registers.

5 years agocrypto test code for ed448
Mark Wooding [Thu, 26 Sep 2019 08:13:22 +0000 (09:13 +0100)]
crypto test code for ed448

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocrypto test code for keccak and sha3
Mark Wooding [Thu, 26 Sep 2019 03:46:03 +0000 (04:46 +0100)]
crypto test code for keccak and sha3

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocrypto-test: Support for text strings
Mark Wooding [Thu, 26 Sep 2019 03:45:38 +0000 (04:45 +0100)]
crypto-test: Support for text strings

This will be used in a moment.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: Extra massaging of keccak code
Mark Wooding [Thu, 26 Sep 2019 03:43:00 +0000 (04:43 +0100)]
catacomb-import-update: Extra massaging of keccak code

These .c files are not compiled yet, although this change does change
the output from --convert.

(This commit was originally an `@@@' commit from Mark Wooding,
"@@@ import-catacomb-crypto keccak/sha3".  I have added this commit
message.)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocrypto-test: C code for testing ed25519
Mark Wooding [Wed, 25 Sep 2019 20:13:09 +0000 (21:13 +0100)]
crypto-test: C code for testing ed25519

This is not wired into the build system yet.

(This commit was originally an `@@@' commit from Mark Wooding,
"@@@ ed25519".  I have added this commit message and folded
in a couple of subsequent commits which I felt should be included.)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocrypto-test: Introduce first version of new .c file.
Mark Wooding [Wed, 25 Sep 2019 19:38:06 +0000 (20:38 +0100)]
crypto-test: Introduce first version of new .c file.

This is not complete and does not compile yet.  It is not wired into
the build system.

That will come right at the end, because I have chosen not to generate
a fake history for the build machinery, which in the original
work-in-progress series underwent some churn and was then refactored
at the end.

(This commit was originally an `@@@' commit from Mark Wooding,
"@@@ crypto-test".  I have added this commit message and folded
in a couple of subsequent commits which I felt should be included.)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoCatacomb import: Provide fake-mLib-bits.h
Mark Wooding [Sat, 29 Apr 2017 12:55:40 +0000 (13:55 +0100)]
Catacomb import: Provide fake-mLib-bits.h

Here we provide a fake version of <mLib/bits.h>, for the benefit of
the code from Catacomb.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
5 years agou64.h: Provide u64get{lo,hi} and u64not
Mark Wooding [Thu, 26 Sep 2019 03:45:18 +0000 (04:45 +0100)]
u64.h: Provide u64get{lo,hi} and u64not

These are for the benefit of fake-mLib-bits.h.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoMakefiles: Make cat_CATS variable available in toplevel
Ian Jackson [Wed, 1 Jan 2020 13:11:44 +0000 (13:11 +0000)]
Makefiles: Make cat_CATS variable available in toplevel

This is slightly clumsy, but it will enable us to talk about these
files in Dir.sd.mk, which is going to be necessary.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoMakefiles: Better workaround for make bug (Debian #4073)
Ian Jackson [Wed, 1 Jan 2020 13:48:14 +0000 (13:48 +0000)]
Makefiles: Better workaround for make bug (Debian #4073)

make likes to delete intermediate files.  The result can be that it
rebuilds things needlessly.  In this case, eax-aes-test.o,
eax-aes.trun etc.  We worked around this by marking them .PRECIOUS
with a pattern rule this is not ideal as it stops make deleting
half-built broken files in case of error.

A better workaround is to mention the files explicitly by name (ie,
not with a pattern).  This stops that effect and doesn't have side
effects.

For us it (empirically) doesn't actually matter whether it's the .o or
the .trun that we mark intermediate.

We can conveniently extend this to all test binaries.  This will be
relevant as we are going to introduce more of these that are partly
builtt from auto-generated or auto-massaged inputs.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years ago.gitignore: Ignore .trun and .tconfirm files en masse
Ian Jackson [Wed, 1 Jan 2020 13:12:24 +0000 (13:12 +0000)]
.gitignore: Ignore .trun and .tconfirm files en masse

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoMakefiles: Rename test stamp files to .tconfirm (from .confirm)
Ian Jackson [Wed, 1 Jan 2020 13:03:57 +0000 (13:03 +0000)]
Makefiles: Rename test stamp files to .tconfirm (from .confirm)

This seems to go with .trun and will make talking about them in
patterns etc. a bit more principled.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoMakefiles: Rename test executables to end in .trun
Ian Jackson [Wed, 1 Jan 2020 15:19:21 +0000 (15:19 +0000)]
Makefiles: Rename test executables to end in .trun

Having these end in -test makes it hard to talk about them en masse
without including handwritten stuff.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: Rename directory variables
Ian Jackson [Tue, 31 Dec 2019 17:08:55 +0000 (17:08 +0000)]
catacomb-import-update: Rename directory variables

There are three directories, not two, now.  The previous arrangement's
variablenames, which now take different values at different times, are
confusing.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: Investigate donor during convert
Ian Jackson [Tue, 31 Dec 2019 17:28:58 +0000 (17:28 +0000)]
catacomb-import-update: Investigate donor during convert

The information we collect here isn't used in --convert mode.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: commit_changes: Introduce $idir
Ian Jackson [Tue, 31 Dec 2019 17:08:52 +0000 (17:08 +0000)]
catacomb-import-update: commit_changes: Introduce $idir

This replaces all references to $DONOR_IMPORT_DIR.  This makes the
code shorter and will make the next commit less noisy.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: Abolish a now-unused variable
Ian Jackson [Tue, 31 Dec 2019 16:32:21 +0000 (16:32 +0000)]
catacomb-import-update: Abolish a now-unused variable

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: --convert: Check the .mk is unchanged
Ian Jackson [Tue, 31 Dec 2019 15:46:00 +0000 (15:46 +0000)]
catacomb-import-update: --convert: Check the .mk is unchanged

The .mk lists donor and output files, the relationship between which
is primarily recorded in catacomb-import-update, but also encoded in
the .mk which is loaded by the makefiles to know what to build and
when.  This change to --convert detects if the .mk corresponding to
this version of the script is different to that which generated the
actually-effective one in the import commit.

If this check trips, --import must be rerun.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoCatacomb: Make arrangements for running convert in `cat' subdir
Ian Jackson [Tue, 31 Dec 2019 13:57:49 +0000 (13:57 +0000)]
Catacomb: Make arrangements for running convert in `cat' subdir

This arranges that each file from catacomb-import-update --convert is
a possible target in cat/, and can be relied on in this and other
makefiles.

None of them are used yet, although we do wire the building into
`all'.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoUpdate crypto code from Catacomb 2.5.0.
Ian Jackson [Tue, 31 Dec 2019 17:33:13 +0000 (17:33 +0000)]
Update crypto code from Catacomb 2.5.0.

This change committed automatically by `catacomb-import-update'.

Detailed list of changes:
  Initial import of debian/copyright.
  Initial import of math/f25519.c.
  Initial import of math/f25519.h.
  Initial import of math/fgoldi.c.
  Initial import of math/fgoldi.h.
  Initial import of math/montladder.h.
  Initial import of math/qfarith.h.
  Initial import of math/scaf.c.
  Initial import of math/scaf.h.
  Initial import of math/scmul.h.
  Initial import of math/t/f25519.
  Initial import of math/t/fgoldi.
  Initial import of pub/ed25519.c.
  Initial import of pub/ed25519.h.
  Initial import of pub/ed448.c.
  Initial import of pub/ed448.h.
  Initial import of pub/t/ed25519.djb.
  Initial import of pub/t/ed25519.local.
  Initial import of pub/t/ed448.
  Initial import of pub/t/x25519.
  Initial import of pub/t/x25519.slow.
  Initial import of pub/t/x448.
  Initial import of pub/t/x448.slow.
  Initial import of pub/x25519.c.
  Initial import of pub/x25519.h.
  Initial import of pub/x448.c.
  Initial import of pub/x448.h.
  Updated secnet-import.auto.mk.
  Initial import of symm/keccak1600.c.
  Initial import of symm/keccak1600.h.
  Initial import of symm/sha3.c.
  Initial import of symm/sha3.h.
  Initial import of symm/t/SHA3_224LongMsg.rsp.
  Initial import of symm/t/SHA3_224Monte.rsp.
  Initial import of symm/t/SHA3_224ShortMsg.rsp.
  Initial import of symm/t/SHA3_256LongMsg.rsp.
  Initial import of symm/t/SHA3_256Monte.rsp.
  Initial import of symm/t/SHA3_256ShortMsg.rsp.
  Initial import of symm/t/SHA3_384LongMsg.rsp.
  Initial import of symm/t/SHA3_384Monte.rsp.
  Initial import of symm/t/SHA3_384ShortMsg.rsp.
  Initial import of symm/t/SHA3_512LongMsg.rsp.
  Initial import of symm/t/SHA3_512Monte.rsp.
  Initial import of symm/t/SHA3_512ShortMsg.rsp.
  Initial import of symm/t/SHAKE128LongMsg.rsp.
  Initial import of symm/t/SHAKE128ShortMsg.rsp.
  Initial import of symm/t/SHAKE128VariableOut.rsp.
  Initial import of symm/t/SHAKE256LongMsg.rsp.
  Initial import of symm/t/SHAKE256ShortMsg.rsp.
  Initial import of symm/t/SHAKE256VariableOut.rsp.
  Initial import of symm/t/keccak1600.
  Initial import of symm/t/sha3.local.

Upstream-Revision: ad7da99a043dab9addc7fce6b22b30f12c7676e6

5 years agocatacomb-import-update: --import: Write .mk file
Ian Jackson [Tue, 31 Dec 2019 14:14:52 +0000 (14:14 +0000)]
catacomb-import-update: --import: Write .mk file

This provides some variables that will be used by secnet's makefiles
to arrange that we run --convert at the right times.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: Write conversion output to cat/ subdir
Ian Jackson [Tue, 31 Dec 2019 12:45:50 +0000 (12:45 +0000)]
catacomb-import-update: Write conversion output to cat/ subdir

This avoids mixing this automunged stuff from Catacomb with normal
secnet code and will thereby avoid accidental manual edits.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: Install the conversion outputs at the end
Ian Jackson [Tue, 31 Dec 2019 14:23:52 +0000 (14:23 +0000)]
catacomb-import-update: Install the conversion outputs at the end

This makes this more suitable for use with make, as it doesn't write
"wrong" output files.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: Prepare for out-of-tree builds
Ian Jackson [Tue, 31 Dec 2019 13:35:58 +0000 (13:35 +0000)]
catacomb-import-update: Prepare for out-of-tree builds

The input directory should be relative to $0, not to `.'.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: Handle deletion
Ian Jackson [Tue, 31 Dec 2019 13:13:25 +0000 (13:13 +0000)]
catacomb-import-update: Handle deletion

If files are removed from the list to be processed, they should be
removed from the import directory, not left lying around stale.

(Files that disappear from Catacomb upstream would always produce an
error, and will still do so.)

This means we key off %changed.  If there is no entry in
%DONOR_REV_MAP then it means the file is being deleted; if the entry
is undef ie means the file is being added.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: Import catacomb's licence notice too
Ian Jackson [Tue, 31 Dec 2019 12:50:43 +0000 (12:50 +0000)]
catacomb-import-update: Import catacomb's licence notice too

This seems to me to be necessary to comply with the licence.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: Improve import change listing algorithm
Ian Jackson [Tue, 31 Dec 2019 12:55:19 +0000 (12:55 +0000)]
catacomb-import-update: Improve import change listing algorithm

Treat each file separately for the purposes of whether to say "Initial
import."  That now becomes an entry in the detailed change list.

We must change the variable @paths there to @lpaths, since the
surrounding code uses @paths for the complete set of paths, not just
the ones to pass to git-log.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: Improve a warning message
Ian Jackson [Tue, 31 Dec 2019 12:52:38 +0000 (12:52 +0000)]
catacomb-import-update: Improve a warning message

This is a bit incomprehensible without the filename.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: Separate import from convert
Ian Jackson [Tue, 31 Dec 2019 11:04:25 +0000 (11:04 +0000)]
catacomb-import-update: Separate import from convert

We want the actual source (PFM) in the secnet git repository, so we
should include the *un*converted files, and convert at build time.

So program is now to be called twice: --import, to update the local
git repository from ../catacomb into ./catacomb-import, and --convert,
to massage those into the output files we want for secnet.

We have a new variable $DOCONVERT which says which mode we're working
in.  It is most convenient to test this in note_path and convert_*,
rather than at each call site.

The only nontrivial changes are to commit_changes, where we no longer
care about recip paths and just use donor paths.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agocatacomb-import-update: Rename from import-catacomb-crypto
Ian Jackson [Tue, 31 Dec 2019 12:47:30 +0000 (12:47 +0000)]
catacomb-import-update: Rename from import-catacomb-crypto

We are going to make an output directory for it, which will be called
catacomb-import.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoimport-catacomb-crypto: Add use strict and fix a bug revealed
Ian Jackson [Tue, 31 Dec 2019 12:33:24 +0000 (12:33 +0000)]
import-catacomb-crypto: Add use strict and fix a bug revealed

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoimport-catacomb-crypto: Do not go mad on initial import
Ian Jackson [Tue, 31 Dec 2019 10:44:58 +0000 (10:44 +0000)]
import-catacomb-crypto: Do not go mad on initial import

I think the branch I received must have had its initial import done
with a different version of this script.  When I tried it, I got
"argument list too long" because the whole history of every relevant
file had been included in the commit message.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoimport-catacomb-crypto: Add emacs Local Variables block
Ian Jackson [Tue, 31 Dec 2019 10:43:16 +0000 (10:43 +0000)]
import-catacomb-crypto: Add emacs Local Variables block

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoimport-catacomb-crypto: New script, but needs some work
Mark Wooding [Wed, 25 Sep 2019 11:07:17 +0000 (12:07 +0100)]
import-catacomb-crypto: New script, but needs some work

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agounaligned.h: Add macros for reading and writing little-endian 32-bit words.
Mark Wooding [Wed, 26 Apr 2017 10:53:05 +0000 (11:53 +0100)]
unaligned.h: Add macros for reading and writing little-endian 32-bit words.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
5 years agoAdjust the DH closure protocol to handle public values as raw binary.
Mark Wooding [Fri, 28 Apr 2017 21:51:36 +0000 (22:51 +0100)]
Adjust the DH closure protocol to handle public values as raw binary.

Responsibility for hex-encoding the public value now lies with the
individual DH group implementation, rather than the common site-level
machinery.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
5 years agoIntroduce negotiation for Diffie--Hellman groups.
Mark Wooding [Sat, 29 Apr 2017 12:55:40 +0000 (13:55 +0100)]
Introduce negotiation for Diffie--Hellman groups.

For the most part, this slots into the space previously prepared for
it.  However, there are a few subtleties.

The most significant one is that existing Secnets don't pay attention to
the high 16 cap bits.  To bring them into availability, we introduce a
signalling system.  If bit 15 is set, then

  * all of the bits are scanned for capabilities, and

  * it is expected that sender has advertised its DH groups explicitly.

If the bit is clear, then we have the old situation:

  * firstly, only the low 16 bits are scanned for transform cap bits,
    and

  * secondly, it is assumed that the sender only implements traditional
    integer Diffie--Hellman, cap 10, with some appropriately determined
    group.

We also set the explicit bit if one of the high capability bits is set.

As part of this, add a parameter to the `diffie-hellman' closure to
configure its advertised group cap.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
5 years agosite.c: Allocate and free the Diffie--Hellman secret buffers each time.
Mark Wooding [Sat, 29 Apr 2017 12:55:40 +0000 (13:55 +0100)]
site.c: Allocate and free the Diffie--Hellman secret buffers each time.

This will allow us to maybe use a different Diffie--Hellman group, with
different size requirements, to communicate with the same peer at a
later time.  We can't do this yet, of course, but the negotiation
machinery is coming soon.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
5 years agosite.c: Abstract out generation of the Diffie--Hellman private secret.
Mark Wooding [Sat, 29 Apr 2017 12:55:40 +0000 (13:55 +0100)]
site.c: Abstract out generation of the Diffie--Hellman private secret.

I want to make this more complicated, so it makes sense to have the
logic in one place.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
5 years agodh.c, secnet.8: Allow `diffie-hellman' to take a dictionary of arguments.
Mark Wooding [Sat, 29 Apr 2017 12:55:40 +0000 (13:55 +0100)]
dh.c, secnet.8: Allow `diffie-hellman' to take a dictionary of arguments.

I want to add more optional arguments to this, but it'll get rather
unwieldy.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
5 years agosite.c: Pass the length of the actual shared secret to the transform.
Mark Wooding [Sat, 29 Apr 2017 12:55:40 +0000 (13:55 +0100)]
site.c: Pass the length of the actual shared secret to the transform.

The `set_new_transform' function used to grow its `sharedsecret' buffer
to accommodate the chosen transform's desired key length, and then tells
the transform that this is the size of its secret.

Unfortunately this is pretty much a lie.  In particular, the traditional
DH closure doesn't actually do anything to fill the rest of the buffer
with random stuff.  Probably there ought to be a KDF here, but:

  * we can't introduce a KDF globally without breaking compatibility
    with old clients; and

  * the new EAX-based transform has its own cheap-and-cheerful (but
    effective) SHA512-based KDF baked into it.

Anyway, the result is that, if the DH group produces short shared
secrets, and the transform has an explicit key size it wants, then
everything will seem to work right up until the transform tries to use
uninitialized memory as key material.  Then the good news is that the
two sites likely end up using different keys and can't talk to each
other.  The /bad/ news is that their keys don't have enough entropy, and
an adversary may be able to impersonate them to each other.

We're probably not in this situation yet.  We have two transforms and
one DH group type.  One transform has its own KDF, so is unaffected by
this.  The other, the old `serpent256-cbc (or is it `serpent-cbc256'?)
transform, wants 608 bits (76 bytes) of key.  It gets these directly
from the big-endian base-256 encoded DH shared secret, so we OK unless
the DH field is smaller than 608 bits.  But if it is then you have other
problems.

Surprisingly, the fix is for the site code to ignore the transform's
reported key size entirely.  It tells the transform the size of the
shared secret, and if the transform is unhappy then it can fail or apply
a KDF by itself.

Of course, now we're doing this, there's no need for the transform to
advertise a desired key length, so remove this.  Also, this means that
the shared secret buffer isn't going to change size any more, so we can
remove all of the machinery for that, too.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
5 years agoChange our view of the Diffie--Hellman closure protocol.
Mark Wooding [Sat, 29 Apr 2017 12:55:40 +0000 (13:55 +0100)]
Change our view of the Diffie--Hellman closure protocol.

Rename `len' to `secret_len' and `ceil_len' to `shared_len', and label
these as the required private secret length and generated shared-secret
length respectively.  There's no functional change: that's what these
variables were being used for anyway.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
5 years agosite.c, dh.c, secnet.h: Allow the dh `makeshared' method to fail.
Mark Wooding [Wed, 26 Apr 2017 10:53:05 +0000 (11:53 +0100)]
site.c, dh.c, secnet.h: Allow the dh `makeshared' method to fail.

The only current implementation still can't, and won't, but change the
interface to acknowledge the possibility, and fix callers to propagate
failures.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
5 years agostest: Test sha512 hash closure
Ian Jackson [Wed, 1 Jan 2020 23:47:07 +0000 (23:47 +0000)]
stest: Test sha512 hash closure

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agostest: New `hashclosure' variable
Ian Jackson [Wed, 1 Jan 2020 23:46:02 +0000 (23:46 +0000)]
stest: New `hashclosure' variable

This will let us test setting the `hash' key, which controls hashing
for algorithms which don't imply the hash.  In particular it will let
us test things other than the sha1 which we previously hardcoded.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agosha512.c, etc.: Provide `sha512' as a hash function for signing.
Mark Wooding [Fri, 28 Apr 2017 21:51:44 +0000 (22:51 +0100)]
sha512.c, etc.: Provide `sha512' as a hash function for signing.

SHA-1 is really creaky these days, though to be fair its use in Secnet
does not depend on collision resistance.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
5 years agosha512.[ch]: Remove a bunch of unused code.
Mark Wooding [Fri, 28 Apr 2017 21:51:36 +0000 (22:51 +0100)]
sha512.[ch]: Remove a bunch of unused code.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
5 years agotest-example: Use subdirmk's new &:macro feature wip.pubkeys.v2
Ian Jackson [Mon, 30 Dec 2019 12:02:26 +0000 (12:02 +0000)]
test-example: Use subdirmk's new &:macro feature

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agosite: Always advertise all capabilities
Ian Jackson [Sat, 14 Dec 2019 15:19:32 +0000 (15:19 +0000)]
site: Always advertise all capabilities

The first version that can cope with this is 0.3.0 which is already
quite old (September 2013).  All older versions are quite badly
broken: eg, they use the serpent256-cbc transform.

This is the next phase in eventually getting rid of the distinction
between early and late capabilities.  When every running version of
secnet has this commit, we can declare every capability early since
every secnet will always advertise them early.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agobuild system: Fix race bug in recheck target
Ian Jackson [Sat, 14 Dec 2019 13:35:45 +0000 (13:35 +0000)]
build system: Fix race bug in recheck target

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agodh: Fix mpz padding bug in use of write_mpbin
Ian Jackson [Sun, 8 Dec 2019 13:15:37 +0000 (13:15 +0000)]
dh: Fix mpz padding bug in use of write_mpbin

If the BN needs less than buflen bytes, write_mpbin would write only
the first len bytes.  dh_makeshared wouldn't notice.  The remaining
bytes will be left uninitialised.

In current code this is only called from site.c, where it so happens
right now that this buffer is always zero on entry.  So the effect is
thst we pad the bignum with zeroes at the LS end, which is wrong.

We can't just change this because it's baked into the protocol.
So actually implement it properly.

We do this in the write_mpbin function, renaming it, because the old
API for write_mpbin invites precisely this error.

I don't think this is of an significant consequence
cryptographically.  Perhaps we should introduce a non-anomalous
version of DH over prime fields.  Or perhaps we should just leave it
as is and expect to switch to X448 or something.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agodh: move write_mpbin in to dh.c
Ian Jackson [Sun, 8 Dec 2019 13:13:34 +0000 (13:13 +0000)]
dh: move write_mpbin in to dh.c

This function has a hazardous API.  In fact, the one call site misuses
it, as we shall see in a moment.

If we wanted a thing like this with a less hazardous API we probably
wouldn't base it on mpz_get_str nowadays.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agostest: Print spawn rune on a line by itself
Ian Jackson [Sun, 8 Dec 2019 13:04:01 +0000 (13:04 +0000)]
stest: Print spawn rune on a line by itself

Especially useful with SECNET_STEST_DIVERT_*=i...: now you can c&p the
whole line.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agostest: Allow SECNET_STEST_DIVERT_*='i <some stuff>'
Ian Jackson [Sun, 8 Dec 2019 12:56:16 +0000 (12:56 +0000)]
stest: Allow SECNET_STEST_DIVERT_*='i <some stuff>'

Eg,
  SECNET_STEST_DIVERT_inside='i gdb --args'
which causes it to print something like this
  spawn UDP_PRELOAD_DIR=./stest/d-nonnego-oo/s LD_PRELOAD=./stest/udp-preload.so:libgtk3-nocsd.so.0 gdb --args ./secnet -dvnc ./stest/d-nonnego-oo/inside.conf
which is convenient.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agostest: Require SECNET_STEST_DIVERT_* paths to start / or ./
Ian Jackson [Sun, 8 Dec 2019 12:51:40 +0000 (12:51 +0000)]
stest: Require SECNET_STEST_DIVERT_* paths to start / or ./

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agostest: When SECNET_STEST_DIVERT_* set, print diverted command too
Ian Jackson [Sun, 8 Dec 2019 12:50:21 +0000 (12:50 +0000)]
stest: When SECNET_STEST_DIVERT_* set, print diverted command too

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agostest: Move puts $argl into divert branches
Ian Jackson [Sun, 8 Dec 2019 12:49:55 +0000 (12:49 +0000)]
stest: Move puts $argl into divert branches

We're going to want to do something slightly different in each one.

No functional change yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agostest: Honour SECNET_STEST_TIMEOUT_MUL to multiply timeouts
Ian Jackson [Sun, 8 Dec 2019 12:46:11 +0000 (12:46 +0000)]
stest: Honour SECNET_STEST_TIMEOUT_MUL to multiply timeouts

This is handy, for example, when running under valgrind.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agostest: Introduce adj-after
Ian Jackson [Sun, 8 Dec 2019 11:24:39 +0000 (11:24 +0000)]
stest: Introduce adj-after

We are going to want this to do something more complicated.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoparallel bisect scripts: Honour $1 as iteration count
Ian Jackson [Sun, 8 Dec 2019 10:58:45 +0000 (10:58 +0000)]
parallel bisect scripts: Honour $1 as iteration count

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoparallel bisect scripts: Better logging
Ian Jackson [Sun, 8 Dec 2019 02:15:48 +0000 (02:15 +0000)]
parallel bisect scripts: Better logging

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoparallel bisect scripts: ad-hoc
Ian Jackson [Sun, 8 Dec 2019 02:07:02 +0000 (02:07 +0000)]
parallel bisect scripts: ad-hoc

This is as I just used to bisect a P(1/256) bug.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agosite: Move earlier all things needed for slog
Ian Jackson [Sun, 8 Dec 2019 10:19:19 +0000 (10:19 +0000)]
site: Move earlier all things needed for slog

Before this we actually read uninitialised memory!
But it was st->log_events which was generally all-bit-zero.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agolog: Remove a now-redundant conditional
Ian Jackson [Sun, 8 Dec 2019 10:19:02 +0000 (10:19 +0000)]
log: Remove a now-redundant conditional

system_log is always non-NULL now.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agolog: Provide system_log from the very start
Ian Jackson [Sun, 8 Dec 2019 10:17:27 +0000 (10:17 +0000)]
log: Provide system_log from the very start

It is just too inconvenient not to have this while reading the config.
Set up a default system_log which logs to stderr.  When setup_log
is called, system_log will be overwritten and this struct is no
longer used.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agolog: Break out logfile_file_init
Ian Jackson [Sun, 8 Dec 2019 10:16:55 +0000 (10:16 +0000)]
log: Break out logfile_file_init

We are going to reuse this.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agostest: Add test for load-private
Ian Jackson [Sat, 7 Dec 2019 16:05:37 +0000 (16:05 +0000)]
stest: Add test for load-private

The resulting interface for privkey() is a bit odd: it's either a list
of a string, and we look at both ends.  Ah well, it's only test code.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoload-private: Use cfgfile_log, not system_log
Ian Jackson [Sat, 7 Dec 2019 16:30:17 +0000 (16:30 +0000)]
load-private: Use cfgfile_log, not system_log

Otherwise if this goes wrong, we segfault, because system_log is in
fact not available this early.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agosecnet: Provide `load-private' verb
Ian Jackson [Sat, 7 Dec 2019 14:25:53 +0000 (14:25 +0000)]
secnet: Provide `load-private' verb

This allows the config file to specify the use of the scheme loadpriv
call with an arbitrary private key file and algorithm, without having
to enable the private key negotiation system.

This is the private key counterpart to
  secnet: Provide `make-public' verb

Like the first provision of `make-public', there is a bug: we use
system_log for reporting errors, but that is not set up until after
the configuration is read.  So errors turn into segfaults.  We will
fix that in a moment.

Aside from that, with this change, new public key schemes can just
provide an entry in the sigschemes table.  They do not need to (and
should not) define their own toplevel config bindings.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoprivcache: Break out DEFAULT_MAXPRIV_BYTES
Ian Jackson [Sat, 7 Dec 2019 16:31:08 +0000 (16:31 +0000)]
privcache: Break out DEFAULT_MAXPRIV_BYTES

We're going to reuse this.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agosecnet: loadpriv interface: Return a closure_t too
Ian Jackson [Sat, 7 Dec 2019 14:57:04 +0000 (14:57 +0000)]
secnet: loadpriv interface: Return a closure_t too

We are going to want this for the `load-private' verb.
This is the private key counterpart to:
   secnet: loadpub interface: Return a closure_t too

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoprivcache: Minor style fixes
Ian Jackson [Sat, 7 Dec 2019 15:41:06 +0000 (15:41 +0000)]
privcache: Minor style fixes

We had some unconventional-for-secnet whitespace around `='.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoprivcache: Regularise error handling in missing defhash case
Ian Jackson [Sat, 7 Dec 2019 14:49:50 +0000 (14:49 +0000)]
privcache: Regularise error handling in missing defhash case

Now it is clearer to see that we don't leak sigpriv;

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoprivcache; uncached_load_file: Introduce error_out
Ian Jackson [Sat, 7 Dec 2019 14:43:54 +0000 (14:43 +0000)]
privcache; uncached_load_file: Introduce error_out

The error handling here is a bit fragile: we rely on not having set
`ok' inappropriately.  Indeed actually we *do* set `ok'
inappropriately if we lack defhash, but in that case we set sigpriv to
0 so do return 0 as needed.  So we are fixing a latent bug.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoCL_GET_STR_ARG: Move into util.h
Ian Jackson [Sat, 7 Dec 2019 14:19:44 +0000 (14:19 +0000)]
CL_GET_STR_ARG: Move into util.h

Move this handy macro from pubkeys.c so that we can reuse it.
(And rename it appropriately.)

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoprivcache: Break out uncached_load_file
Ian Jackson [Sat, 7 Dec 2019 14:13:24 +0000 (14:13 +0000)]
privcache: Break out uncached_load_file

We are going to want to reuse this to make a new entrypoint.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoprivcache: Transpose scheme lookup and file opening
Ian Jackson [Sat, 7 Dec 2019 14:04:58 +0000 (14:04 +0000)]
privcache: Transpose scheme lookup and file opening

This makes no real difference, except that it provides a different
error message if both things are wrong.

This new odrering is more consistent with a change we are about to
make.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoprivcache: uncached_get: Introduce `databuf' local
Ian Jackson [Sat, 7 Dec 2019 14:02:49 +0000 (14:02 +0000)]
privcache: uncached_get: Introduce `databuf' local

This is a bit more convenient and will also make a future commit much
easier too read.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoprivcache: uncached_get: Introduce `defhash' local
Ian Jackson [Sat, 7 Dec 2019 14:01:57 +0000 (14:01 +0000)]
privcache: uncached_get: Introduce `defhash' local

This is a bit more convenient and will also make a future commit much
easier too read.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoprivcache: uncached_get: Introduce `path' local
Ian Jackson [Sat, 7 Dec 2019 13:01:32 +0000 (13:01 +0000)]
privcache: uncached_get: Introduce `path' local

This is a bit more convenient and will also make a future commit much
easier too read.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agostest/t-Cnonnego-onr: New test
Ian Jackson [Thu, 5 Dec 2019 01:24:02 +0000 (01:24 +0000)]
stest/t-Cnonnego-onr: New test

Check that the new site can initiate key exchange when talking to a
old one, as well as vice versa.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agostest: Make it possible to have kex initiated by `outside'
Ian Jackson [Thu, 5 Dec 2019 01:23:16 +0000 (01:23 +0000)]
stest: Make it possible to have kex initiated by `outside'

Introduce new `initiator' variable.  No functional change (other than
to messages) with existing tests.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agosest/t-Cnonnego-on: New test
Ian Jackson [Thu, 5 Dec 2019 00:58:16 +0000 (00:58 +0000)]
sest/t-Cnonnego-on: New test

See if we can do key exchange with an older secnet, if the user has
told us where to find one to try it with.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agostest: Machinery for runing an old secnet if a test wants
Ian Jackson [Thu, 5 Dec 2019 00:58:10 +0000 (00:58 +0000)]
stest: Machinery for runing an old secnet if a test wants

Tests can now set oldsecnet(SITE).

Old secnets want a "filename" key in their log config.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agotest-common: Framework for compatibility tests
Ian Jackson [Fri, 6 Dec 2019 23:00:53 +0000 (23:00 +0000)]
test-common: Framework for compatibility tests

Now normal tests must start with a letter.  Ones starting with C
require OLD_SECNET_DIR.  (Right now that must be both source and build
dir because it's tedious to have to distinguish them and pass both.)

Update comprehensive-test to (i) notice if the user forgot to set
this (ii) make it into an absolute path.  Note that comprehensive-test
therefore has a different default to `make check': If OLD_SECNET_DIR
is not set, `make check' will do none of those tests, but
comprehensive-test will complain (and wants "" to disable those
tests).

We do not need to print this variable in our debugging output about
how we are running secnet (or how the user who specifies _DIVERT_=i
should run it).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agotest-common: Use $(wildcard ) rather than $(shell echo )
Ian Jackson [Thu, 5 Dec 2019 01:18:26 +0000 (01:18 +0000)]
test-common: Use $(wildcard ) rather than $(shell echo )

This is probably a bit faster, but more relevantly it would DTRT if
for some reason there were no applicable tests.  Which is going to
happen in a moment, when we add some machinery before the applicable
test.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agomtest/t-filter: New test for --filter mode
Ian Jackson [Wed, 4 Dec 2019 22:06:37 +0000 (22:06 +0000)]
mtest/t-filter: New test for --filter mode

Checked the output with
  env -u LESS git-diff --color --word-diff -w :test-example/sites :mtest/e-filter.sites
and it looks right.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agomake-secnet-sites: Provide --filter mode
Ian Jackson [Wed, 4 Dec 2019 16:56:31 +0000 (16:56 +0000)]
make-secnet-sites: Provide --filter mode

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agoREADME.make-secnet-sites: Slightly restructure mode docs
Ian Jackson [Wed, 4 Dec 2019 16:54:59 +0000 (16:54 +0000)]
README.make-secnet-sites: Slightly restructure mode docs

This will make it easier to add a new mode.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agomake-secnet-sites: OpConf: Move positional_args to OpBase
Ian Jackson [Wed, 4 Dec 2019 16:51:52 +0000 (16:51 +0000)]
make-secnet-sites: OpConf: Move positional_args to OpBase

This is actually a general-purpose input/output file handler.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
5 years agomake-secnet-sites: OpUserv: Rename sitesfile to outputfile
Ian Jackson [Wed, 4 Dec 2019 16:50:48 +0000 (16:50 +0000)]
make-secnet-sites: OpUserv: Rename sitesfile to outputfile

This is not entirely right for OpUserv because OpUserv reads it too.
But this is going to make sense when we reuse more of OpBase.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>