catacomb-python
4 years agobuffer.c: Handle curve object as `PyObject *'.
Mark Wooding [Tue, 22 Oct 2019 10:27:49 +0000 (11:27 +0100)]
buffer.c: Handle curve object as `PyObject *'.

I've not checked, but I think this is the only place where a
pre- existing curve object was handled as `PyTypeObject *'.

4 years agobuffer.c: Delete pointless initialization.
Mark Wooding [Tue, 22 Oct 2019 10:27:12 +0000 (11:27 +0100)]
buffer.c: Delete pointless initialization.

The variable `cobj' will be set by `PyArg_ParseTuple' anyway.

4 years agopock: Use floor division on integers.
Mark Wooding [Tue, 22 Oct 2019 11:18:41 +0000 (12:18 +0100)]
pock: Use floor division on integers.

Python 3 wants to give me a float here, which is obviously wrong.

4 years agopock: Probe for the fixnum width by enquiring the largest fixnum value.
Mark Wooding [Tue, 22 Oct 2019 11:16:37 +0000 (12:16 +0100)]
pock: Probe for the fixnum width by enquiring the largest fixnum value.

Python 3 doesn't distinguish fixnums from bignums at the type level, so
this would run forever.  Instead, get (a guess at) the largest fixnum
value, and use that.

4 years agopock: Use `MPMul' so that we can avoid `reduce'.
Mark Wooding [Tue, 22 Oct 2019 11:14:10 +0000 (12:14 +0100)]
pock: Use `MPMul' so that we can avoid `reduce'.

For some reason, Python 3 hides `reduce' away in some library module.
Anyway, we have a very efficient mass-multiplier so we might as well use
it.

4 years agopwsafe: Trim an overly-long section boundary.
Mark Wooding [Mon, 21 Oct 2019 17:03:20 +0000 (18:03 +0100)]
pwsafe: Trim an overly-long section boundary.

4 years agocatacomb/pwsafe.py: Use `binascii' for Base64 conversion.
Mark Wooding [Mon, 21 Oct 2019 17:26:39 +0000 (18:26 +0100)]
catacomb/pwsafe.py: Use `binascii' for Base64 conversion.

The `.encode()' and `.decode()' string methods were apparently too
convenient, so Python 3 doesn't do Base64 conversion like this.
Instead, we have to use the steam-powered `binascii'.  And, to make
things even better, encoding produces `bytes' rather than `str' because,
err, it's not really text or something?  No idea.  Stoats.

4 years agocatacomb/pwsafe.py: Hack around the change in metaclass syntax.
Mark Wooding [Mon, 21 Oct 2019 17:17:21 +0000 (18:17 +0100)]
catacomb/pwsafe.py: Hack around the change in metaclass syntax.

Python 2 (all versions) want you to set `__metaclass__' within the class
body.  Python 3 ignores this, treating it like an ordinary class
attribute, and wants you to say `metaclass = ...' in the direct-
superclass list; but the latter is a syntax error to Python 2.

Instead, add a hack which constructs a anonymous class with the right
metaclass to use as a direct superclass.  It's awful, but it works.

4 years agocatacomb/pwsafe.py: Mark abstract storage-backend classes as lacking `NAME'.
Mark Wooding [Mon, 21 Oct 2019 17:20:42 +0000 (18:20 +0100)]
catacomb/pwsafe.py: Mark abstract storage-backend classes as lacking `NAME'.

Previously, they'd have a name of `None'.  This will make a later hack
work better.

4 years agocatacomb/pwsafe.py: Hack around the difference in octal literal syntax.
Mark Wooding [Mon, 21 Oct 2019 17:06:31 +0000 (18:06 +0100)]
catacomb/pwsafe.py: Hack around the difference in octal literal syntax.

Python 2.5 wants `0DIGITS', while Python 3 insists on `0oDIGITS'.  The
latter is prettier, but the difference is annoying.  We only need these
for Unix permissions, so just set up the ones we want in advance using
an explicit conversion from strings.

4 years agocatacomb/__init__.py: Implement `rich' comparisons on rationals.
Mark Wooding [Sun, 20 Oct 2019 01:29:36 +0000 (02:29 +0100)]
catacomb/__init__.py: Implement `rich' comparisons on rationals.

These are the only kind in Python 3, and they work everywhere.

4 years agocatacomb/__init__.py: Don't try to convert text strings to `ByteString'.
Mark Wooding [Mon, 21 Oct 2019 19:06:31 +0000 (20:06 +0100)]
catacomb/__init__.py: Don't try to convert text strings to `ByteString'.

This won't work in Python 3, so get used to the idea.

Fortunately, this only matters for the empty string, so use
`ByteString.zero(0)' instead.

4 years agocatacomb/__init__.py: Hack because Python 3 `hex' builtin works differently.
Mark Wooding [Mon, 21 Oct 2019 19:01:45 +0000 (20:01 +0100)]
catacomb/__init__.py: Hack because Python 3 `hex' builtin works differently.

In Python 3, the `hex' builtin function converts its operand to an
integer (using the new `__index__' special method) and then converts
that to hex, rather than calling a special method directly.  The new
`bytes' type offers a `hex' method for conversion to hex, so we do the
same here.

4 years agocatacomb/__init__.py: Hack because Python 3 won't destructure arguments.
Mark Wooding [Mon, 21 Oct 2019 17:25:28 +0000 (18:25 +0100)]
catacomb/__init__.py: Hack because Python 3 won't destructure arguments.

Why?!

4 years ago*.py: Hack around the mapping change from `itervalues' to just `values', etc.
Mark Wooding [Mon, 21 Oct 2019 17:13:57 +0000 (18:13 +0100)]
*.py: Hack around the mapping change from `itervalues' to just `values', etc.

This change is only about accessing existing mappings.  We'll have to
set up our own mappings the hard way.

4 years ago*.py: Add explicit conversions between binary and text strings.
Mark Wooding [Mon, 21 Oct 2019 17:04:58 +0000 (18:04 +0100)]
*.py: Add explicit conversions between binary and text strings.

This doesn't do anything right now, but it'll be an important hook for
porting to Python 3.

4 years ago*.py: Add parentheses around `print' arguments.
Mark Wooding [Mon, 21 Oct 2019 16:57:29 +0000 (17:57 +0100)]
*.py: Add parentheses around `print' arguments.

For `print >>FILE', just switch to `FILE.write(...)' instead, with an
explicit newline.

4 years ago*.py: Hack around Python exception-catching syntax mismatch.
Mark Wooding [Mon, 21 Oct 2019 16:53:43 +0000 (17:53 +0100)]
*.py: Hack around Python exception-catching syntax mismatch.

There's no common syntax to capture the current exception value between
Python 2.5 and 3: the former wants

       try: ...
except EXCCLS, VAR: ...

while the latter wants

       try: ...
except EXCCLS as VAR: ...

Give up and dig the exception value out of `sys.exc_info()' instead.

4 years ago*.py: Upgrade old-fashioned `raise' syntax.
Mark Wooding [Mon, 21 Oct 2019 16:47:30 +0000 (17:47 +0100)]
*.py: Upgrade old-fashioned `raise' syntax.

4 years agocatacomb/pwsafe.py: Add missing `.errno' projection.
Mark Wooding [Mon, 21 Oct 2019 16:52:35 +0000 (17:52 +0100)]
catacomb/pwsafe.py: Add missing `.errno' projection.

4 years agomp.c: Fix misformatting.
Mark Wooding [Mon, 21 Oct 2019 10:46:14 +0000 (11:46 +0100)]
mp.c: Fix misformatting.

4 years agoalgorithms.c: Delete a spurious blank line.
Mark Wooding [Tue, 19 Nov 2019 22:35:49 +0000 (22:35 +0000)]
algorithms.c: Delete a spurious blank line.

4 years agomp.c: Use newer names for the internal `long' representation parameters.
Mark Wooding [Mon, 21 Oct 2019 10:43:43 +0000 (11:43 +0100)]
mp.c: Use newer names for the internal `long' representation parameters.

In Python 2.6, the `SHIFT' and `MASK' constants grew `PyLong_' prefixes,
but the old names were retained for compatibility; in Python 3, the old
names are gone.  Use the new names, defining them as necessary.

4 years agomp.c: Assert about the Python limb size statically.
Mark Wooding [Mon, 21 Oct 2019 10:40:39 +0000 (11:40 +0100)]
mp.c: Assert about the Python limb size statically.

Python extensions build with assertions off, so this was much less
helpful than it looked.

4 years ago*.c: Separate string function calls according to text/binary usage.
Mark Wooding [Mon, 21 Oct 2019 01:38:59 +0000 (02:38 +0100)]
*.c: Separate string function calls according to text/binary usage.

Don't use the `PyString_...' functions directly.  Instead, define two
collections of macros `TEXT_...' and `BIN_...', which can be used on
text and binary strings respectively.  The two sets are slightly
different, because they've been designed to adapt to Python 3's
different interfaces.

There are no `PyString...' calls remaining outside of these macros.

4 years ago*.c: Introduce a new input conversion for binary strings.
Mark Wooding [Mon, 21 Oct 2019 00:43:54 +0000 (01:43 +0100)]
*.c: Introduce a new input conversion for binary strings.

One of the major differences in Python 3 is that it firmly distinguishes
between binary and text strings: the former consist of small integers,
while the latter consist of Unicode scalars.  The Python 3 `s#'
conversion's main purpose is to accept text strings, and though it will
also accept binary strings it's not really ideal for the purpose.
Python 3 introduces a new conversion `y#' specifically for binary
strings, though this isn't quite what we want because, for some reason,
it /doesn't/ work with bufferish objects which require explicit release.

The best answer seems to be to introduce our own custom conversion for
binary strings, so we do this here, replacing all of the binary-input
argument conversions.  While we're at it, replace all of the by-steam
argument conversions using `PyObject_AsReadBuffer' too.

4 years ago*.c: Use the new `Py_hash_t' type.
Mark Wooding [Sun, 20 Oct 2019 23:33:22 +0000 (00:33 +0100)]
*.c: Use the new `Py_hash_t' type.

4 years ago*.c: Use `PyVarObject_HEAD_INIT' to initialize type object headers.
Mark Wooding [Sun, 20 Oct 2019 23:14:01 +0000 (00:14 +0100)]
*.c: Use `PyVarObject_HEAD_INIT' to initialize type object headers.

Define a suitable version if the Python headers don't do it for us.

4 years ago*.c: Use the new `Py_TYPE' and `Py_SIZE' macros; define them if necessary.
Mark Wooding [Sun, 20 Oct 2019 23:19:44 +0000 (00:19 +0100)]
*.c: Use the new `Py_TYPE' and `Py_SIZE' macros; define them if necessary.

Python 2.6 introduced macros to access object header fields, which is
handy because Python 3 changes the way object headers are
structured.  (I think the binary layout is unchanged, but the C-level
structuring is definitely different.)

This is the start of Python 3 porting work.

4 years ago*.c: Publish algorithm and crypto-group tables as `mapping' objects.
Mark Wooding [Wed, 13 Nov 2019 00:59:07 +0000 (00:59 +0000)]
*.c: Publish algorithm and crypto-group tables as `mapping' objects.

Previously, the algorithm tables were published as plain Python
dictionaries, and the group tables were published in a complicated way
through a read-only mapping object implemented in Python.

With the richer Python 3 mapping protocol, maintaining a separate custom
mapping object in Python seems much less attractive.  Also, the group
tables were read-only while the algorithm tables were mutable, which was
a rather unfortunate inconsistency.

Fix this mess by implementing a new simple mapping object, based on
Pyke's generic mapping machinery, and populating instances of it with
the necessary data.

4 years agopyke/mapping.c, key.c: Make the mapping code more intrusive and complete.
Mark Wooding [Mon, 18 Nov 2019 10:41:12 +0000 (10:41 +0000)]
pyke/mapping.c, key.c: Make the mapping code more intrusive and complete.

Previously, mapping classes would implement a minimum of Python-level
operations, such as iterating over keys and mapping lookups, and the
generic mapping code would just synthesize missing operations in terms
of these.

Instead, introduce a mapping-specific vtable pointer in object
structures which describes the mapping operations in a form similar to
mLib's `sym' interface, which is rather more efficient in terms of hash
probes, and have the generic mapping code synthesize all of the Python-
level operations from these.

Needless to say, this is very messy.  Sorry.

4 years agopyke/mapping.c: Introduce macro for unconstifying common keyword list.
Mark Wooding [Sun, 20 Oct 2019 21:57:54 +0000 (22:57 +0100)]
pyke/mapping.c: Introduce macro for unconstifying common keyword list.

4 years agopyke/pyke.c (newtype): Explicitly clear `ht_slots'.
Mark Wooding [Tue, 22 Oct 2019 17:53:50 +0000 (18:53 +0100)]
pyke/pyke.c (newtype): Explicitly clear `ht_slots'.

This makes things go very badly wrong in Python 3.  I'm not sure why it
doesn't go wrong in Python 2...

4 years ago*.c: Split the constant definitions into the various submodules.
Mark Wooding [Sun, 20 Oct 2019 22:18:09 +0000 (23:18 +0100)]
*.c: Split the constant definitions into the various submodules.

4 years agopyke/pyke.[ch]: Make type skeleton structures be read-only.
Mark Wooding [Sun, 20 Oct 2019 20:18:08 +0000 (21:18 +0100)]
pyke/pyke.[ch]: Make type skeleton structures be read-only.

We couldn't do this before because `INITTYPE_META' would write the
direct superclass to the `tp_base' slot in the skeleton before calling
`inittype'.  To make this work, then, we adjust `inittype' to take the
direct superclass as an extra argument and plug it into the newly
created heap-type; and `INITTYPE_META' needs adjusting to pass this
argument rather than trying to write to the skeleton directly.

Of course, then we need to actually mark the type skeletons as `const'.

4 years agoalgorithms.c, ec.c, field.c: Replace properties by member access.
Mark Wooding [Tue, 19 Nov 2019 08:29:49 +0000 (08:29 +0000)]
algorithms.c, ec.c, field.c: Replace properties by member access.

4 years agoalgorithms.c: Fix longstanding ugly hack with new `MEMRNM' macro.
Mark Wooding [Sun, 20 Oct 2019 15:15:39 +0000 (16:15 +0100)]
algorithms.c: Fix longstanding ugly hack with new `MEMRNM' macro.

4 years agopyke/pyke.h: Add a `MEMBER' variant with explicit member name.
Mark Wooding [Sun, 20 Oct 2019 11:43:40 +0000 (12:43 +0100)]
pyke/pyke.h: Add a `MEMBER' variant with explicit member name.

4 years ago*.c: Use Python `METH_NOARGS' methods where applicable.
Mark Wooding [Sun, 20 Oct 2019 20:00:18 +0000 (21:00 +0100)]
*.c: Use Python `METH_NOARGS' methods where applicable.

Rather than rolling our own.  We need a little extra machinery to insert
the table entries, especially for the generic mapping support, but this
still saves 95 lines of code.

The `CONVERT_CAREFULLY' macro recently added will check that we haven't
messed things up too badly.

4 years ago*.c: Use Python's facilities for defining class and static methods.
Mark Wooding [Tue, 19 Nov 2019 00:19:38 +0000 (00:19 +0000)]
*.c: Use Python's facilities for defining class and static methods.

These weren't available when this library was first written, but the
workaround is rather ugly and no longer necessary.

4 years ago*.c: Rearrange and reformat the class methods.
Mark Wooding [Mon, 18 Nov 2019 19:53:29 +0000 (19:53 +0000)]
*.c: Rearrange and reformat the class methods.

This is preparation for using Python's built-in facilities for marking
static and and class methods (which weren't around when this project
started out, which is why things are the rather strange way that they
are).

4 years ago*.c: Make all of the type-definition tables read-only.
Mark Wooding [Sun, 20 Oct 2019 21:46:05 +0000 (22:46 +0100)]
*.c: Make all of the type-definition tables read-only.

The hard part is a new collection of macros which strip the `const'
qualifier from the actual table definitions, after checking that they
actually have the correct type.

And then there's the slog of actually changing all of the definitions
and using the new macros.

4 years agocatacomb-python.h (GEN): Remove `const' from input table type carefully.
Mark Wooding [Mon, 21 Oct 2019 12:07:43 +0000 (13:07 +0100)]
catacomb-python.h (GEN): Remove `const' from input table type carefully.

We have this new machinery, so we should use it.

4 years agopyke/pyke.c: Check conversions hidden inside `KWLIST' and `KWMETH'.
Mark Wooding [Sun, 20 Oct 2019 18:24:37 +0000 (19:24 +0100)]
pyke/pyke.c: Check conversions hidden inside `KWLIST' and `KWMETH'.

Introduce a new macro `CONVERT_CAREFULLY' which checks (via a rather
sleazy hack) that its operand is of the expected type before converting
it to some other type.  This is protected by an `#ifdef' guard because
I'm thinking about adding it to a version of mLib, but I want to keep
the Pyke core independent of mLib.

Use this new macro to build better versions of `KWLIST' and `KWMETH',
which have casts hidden inside them, so that we can now be certain that
the method table entries match up with the functions.  (Spoiler: they
didn't, quite, and commit 19bff42f99d41cd9b8953ff61edfe35380b54d88,
backported onto the 1.1.x branch, fixes the bug that was found by this
change.)

4 years agopyke/pyke.h, key.c: Rename `INDEXERR' to `MAPERR'.
Mark Wooding [Sun, 20 Oct 2019 18:17:41 +0000 (19:17 +0100)]
pyke/pyke.h, key.c: Rename `INDEXERR' to `MAPERR'.

The name `INDEXERR' was pointlessly confusing, given the existing
`IXERR' which actually raises Python's `IndexError'.  It's important,
though, that `KEYERR' be reserved for Catacomb's `KeyError' exception,
which really is an error about (cryptographic) keys.  So `MAPERR' it is.

4 years agopyke/, ...: Extract utilities into a sort-of reusable library.
Mark Wooding [Sun, 20 Oct 2019 16:51:13 +0000 (17:51 +0100)]
pyke/, ...: Extract utilities into a sort-of reusable library.

This commit changes no code, but it moves a lot of it about.  Tidying up
will come later.

4 years agocatacomb-python.h: Delete a stray trailing `\'.
Mark Wooding [Tue, 22 Oct 2019 18:22:07 +0000 (19:22 +0100)]
catacomb-python.h: Delete a stray trailing `\'.

This doesn't actually hurt anything because of the following blank line,
but, umm, ...

4 years agocatacomb-python.h: Add a macro to declare module init functions.
Mark Wooding [Sun, 20 Oct 2019 17:18:05 +0000 (18:18 +0100)]
catacomb-python.h: Add a macro to declare module init functions.

4 years agoutil.c: Replace mLib `DISCARD' with a plain `(void)' cast.
Mark Wooding [Sun, 20 Oct 2019 17:56:07 +0000 (18:56 +0100)]
util.c: Replace mLib `DISCARD' with a plain `(void)' cast.

4 years agoutil.c: Rewrite `addmethods' to remove dependency on <mLib/darray.h>.
Mark Wooding [Sun, 20 Oct 2019 17:03:35 +0000 (18:03 +0100)]
util.c: Rewrite `addmethods' to remove dependency on <mLib/darray.h>.

4 years agocatacomb.c: Use a less awful version comparison.
Mark Wooding [Sun, 20 Oct 2019 20:03:38 +0000 (21:03 +0100)]
catacomb.c: Use a less awful version comparison.

4 years agocatacomb.c, util.c: Export `modname' and set it in main entry point.
Mark Wooding [Sun, 20 Oct 2019 16:57:11 +0000 (17:57 +0100)]
catacomb.c, util.c: Export `modname' and set it in main entry point.

This is preliminary work in splitting out the Catacomb-independent
utilities so that they can be used by other projects.

4 years ago*.c: Use `Py_XDECREF' where applicable.
Mark Wooding [Sat, 19 Oct 2019 13:31:40 +0000 (14:31 +0100)]
*.c: Use `Py_XDECREF' where applicable.

The Python 2.5 version of `Py_DECREF' isn't properly braced, so `if (x)
Py_DECREF(x);' provokes a dangling-`else' warning from the compiler.

4 years ago*.c: Reformat docstrings.
Mark Wooding [Fri, 22 Nov 2019 20:30:31 +0000 (20:30 +0000)]
*.c: Reformat docstrings.

No functional changes here: just changing how the strings are
represented in the source.

4 years agomp.c: Improve docstring.
Mark Wooding [Fri, 22 Nov 2019 20:22:45 +0000 (20:22 +0000)]
mp.c: Improve docstring.

4 years agopgen.c: Write a `pgen' status code as `PGST' consistently in docstrings.
Mark Wooding [Fri, 22 Nov 2019 18:34:56 +0000 (18:34 +0000)]
pgen.c: Write a `pgen' status code as `PGST' consistently in docstrings.

4 years agokey.c: Delete the `barf' function.
Mark Wooding [Sun, 20 Oct 2019 21:53:24 +0000 (22:53 +0100)]
key.c: Delete the `barf' function.

What even?

I think this must have been ancient debugging code, but it should never
have seen release.

4 years agobytestring.c: Delete unused buffer methods on `C.ByteString'.
Mark Wooding [Sun, 20 Oct 2019 21:07:40 +0000 (22:07 +0100)]
bytestring.c: Delete unused buffer methods on `C.ByteString'.

I think this was needed in some ancient Python in order to inherit the
buffer methods from `str', but Python 2.5 certainly works fine without.

4 years agobuffer.c: Give `BufferError' a text message.
Mark Wooding [Sun, 20 Oct 2019 20:08:32 +0000 (21:08 +0100)]
buffer.c: Give `BufferError' a text message.

4 years ago.gdbinit: Delete this ancient and inconvenient thing.
Mark Wooding [Mon, 21 Oct 2019 10:30:10 +0000 (11:30 +0100)]
.gdbinit: Delete this ancient and inconvenient thing.

4 years agocatacomb-python.h: Give up on Python versions prior to 2.5.
Mark Wooding [Fri, 22 Nov 2019 22:43:02 +0000 (22:43 +0000)]
catacomb-python.h: Give up on Python versions prior to 2.5.

4 years agofield.c: Push field-polynomial property into binary-field base class.
Mark Wooding [Wed, 23 Oct 2019 09:41:34 +0000 (10:41 +0100)]
field.c: Push field-polynomial property into binary-field base class.

Using the same code as for prime fields was a mistake, but sharing the
same code between polynomial- and normal-basis fields works just fine;
but there's no point in duplicating the property-table entry when
there's a perfectly good superclass to hang the property off -- and it
already has a property table!

4 years ago*.c: Use Python macros rather than functions where possible.
Mark Wooding [Sun, 24 Nov 2019 12:35:45 +0000 (12:35 +0000)]
*.c: Use Python macros rather than functions where possible.

4 years agocatacomb-python.h, *.c: Move definitions back into implementation files.
Mark Wooding [Sun, 20 Oct 2019 14:56:54 +0000 (15:56 +0100)]
catacomb-python.h, *.c: Move definitions back into implementation files.

The header was chock full of implementation details which weren't
needed by anything.  Move things which aren't needed further afield back
into their home files, and delete things like conversion functions which
aren't actually being used.

Also, some light reordering of the things that are left.

(This patch turns out to be remarkably commutative through the enormous
pile of changes coming up.)

4 years ago.gitignore: Reorder the patterns and make them more specific.
Mark Wooding [Sun, 24 Nov 2019 12:08:34 +0000 (12:08 +0000)]
.gitignore: Reorder the patterns and make them more specific.

Place recursively applicable patterns at the top (just `*.pyc' for
now).  Prefix others with `/' to keep them local.  Suffix directory
names with `/' for clarity's sake.

4 years ago.gitignore: Delete some obsolete things.
Mark Wooding [Sun, 24 Nov 2019 11:35:32 +0000 (11:35 +0000)]
.gitignore: Delete some obsolete things.

I think `dist' and `deb-build' were from old private workflow that
shouldn't have leaked into the master repository.  I have a vague
recollection that `build-stamp' was from CDBS, which we no longer use.
I honestly have no idea what `py' and `test.py' were, but they've been
there from the beginning.

4 years agocatacomb/.gitignore: Delete obsolete file.
Mark Wooding [Sun, 24 Nov 2019 12:05:48 +0000 (12:05 +0000)]
catacomb/.gitignore: Delete obsolete file.

I think this was only created because Subversion ignore patterns didn't
affect subdirectories.

4 years agoMerge branch '1.3.x'
Mark Wooding [Mon, 25 Nov 2019 17:42:48 +0000 (17:42 +0000)]
Merge branch '1.3.x'

* 1.3.x: (101 commits)
  rand.c: Show keyword argument as optional.
  mp.c: Fix punctuation error in docstrings.
  t/t-*.py: Use the `WriteBuffer.contents' property.
  t/t-bytes.py: Check that indexing, slicing, etc. return `C.ByteString'.
  t/t-algorithms.py: Add a simple test for `Keccak1600.copy'.
  t/t-algorithms.py: Add tests for other HSalsa20 and HChaCha key sizes.
  t/t-algorithms.py: Add AEAD tests.
  t/t-algorithms.py: Add tests for the new `KeySZ.pad' method.
  catacomb/__init__.py (KeySZRange.pad): Return correct value.
  algorithms.c: Propagate `AEADF_NOAAD' to `aad' objects.
  algorithms.c (AEADAAD.copy): Propagate the hashed length to the copy.
  t/: Add a test suite.
  ec.c: Don't lose error status when constructing points from a sequence.
  ec.c: Free partially constructed points coordinatewise.
  *.c: Be more careful about `PySequence_Size'.
  key.c: Reformat the rest of the `KeyError' constructor.
  key.c: Parse `KeyError' constructor arguments by hand.
  catacomb-python.h: Add a macro for raising `OverflowError'.
  key.c: Collect `KeyError' argument count as a separate step.
  key.c: Use tuple functions on `KeyError' argument tuple.
  ...

4 years agorand.c: Show keyword argument as optional.
Mark Wooding [Fri, 22 Nov 2019 17:23:46 +0000 (17:23 +0000)]
rand.c: Show keyword argument as optional.

4 years agomp.c: Fix punctuation error in docstrings.
Mark Wooding [Fri, 22 Nov 2019 18:56:54 +0000 (18:56 +0000)]
mp.c: Fix punctuation error in docstrings.

4 years agot/t-*.py: Use the `WriteBuffer.contents' property.
Mark Wooding [Sun, 17 Nov 2019 23:46:49 +0000 (23:46 +0000)]
t/t-*.py: Use the `WriteBuffer.contents' property.

4 years agot/t-bytes.py: Check that indexing, slicing, etc. return `C.ByteString'.
Mark Wooding [Sun, 17 Nov 2019 23:44:57 +0000 (23:44 +0000)]
t/t-bytes.py: Check that indexing, slicing, etc. return `C.ByteString'.

4 years agot/t-algorithms.py: Add a simple test for `Keccak1600.copy'.
Mark Wooding [Sun, 17 Nov 2019 23:42:26 +0000 (23:42 +0000)]
t/t-algorithms.py: Add a simple test for `Keccak1600.copy'.

4 years agot/t-algorithms.py: Add tests for other HSalsa20 and HChaCha key sizes.
Mark Wooding [Sun, 17 Nov 2019 23:42:00 +0000 (23:42 +0000)]
t/t-algorithms.py: Add tests for other HSalsa20 and HChaCha key sizes.

4 years agot/t-algorithms.py: Add AEAD tests.
Mark Wooding [Sun, 17 Nov 2019 23:41:36 +0000 (23:41 +0000)]
t/t-algorithms.py: Add AEAD tests.

4 years agot/t-algorithms.py: Add tests for the new `KeySZ.pad' method.
Mark Wooding [Sun, 17 Nov 2019 23:41:14 +0000 (23:41 +0000)]
t/t-algorithms.py: Add tests for the new `KeySZ.pad' method.

4 years agocatacomb/__init__.py (KeySZRange.pad): Return correct value.
Mark Wooding [Sun, 17 Nov 2019 23:23:41 +0000 (23:23 +0000)]
catacomb/__init__.py (KeySZRange.pad): Return correct value.

If the input is already a multiple of the modulus, then don't round up
to the next one.

4 years agoalgorithms.c: Propagate `AEADF_NOAAD' to `aad' objects.
Mark Wooding [Sun, 13 Oct 2019 23:55:20 +0000 (00:55 +0100)]
algorithms.c: Propagate `AEADF_NOAAD' to `aad' objects.

4 years agoalgorithms.c (AEADAAD.copy): Propagate the hashed length to the copy.
Mark Wooding [Sun, 13 Oct 2019 23:52:58 +0000 (00:52 +0100)]
algorithms.c (AEADAAD.copy): Propagate the hashed length to the copy.

4 years agoMerge branch '1.2.x' into 1.3.x
Mark Wooding [Mon, 25 Nov 2019 17:39:38 +0000 (17:39 +0000)]
Merge branch '1.2.x' into 1.3.x

* 1.2.x: (89 commits)
  t/: Add a test suite.
  ec.c: Don't lose error status when constructing points from a sequence.
  ec.c: Free partially constructed points coordinatewise.
  *.c: Be more careful about `PySequence_Size'.
  key.c: Reformat the rest of the `KeyError' constructor.
  key.c: Parse `KeyError' constructor arguments by hand.
  catacomb-python.h: Add a macro for raising `OverflowError'.
  key.c: Collect `KeyError' argument count as a separate step.
  key.c: Use tuple functions on `KeyError' argument tuple.
  key.c: Rename sad-path label to `end'.
  key.c: Delete duplicate setting of `errstring'.
  util.c (mkexc): Populate dictionary before constructing exception class.
  key.c: Only set the error code.
  catacomb.c, util.c: Publish `KERR_...' symbols as negative numbers.
  field.c: Delete the completely unused `getfe' function.
  key.c (convfilter): Fix sense of error tests.
  buffer.c, ec.c: Fix required size for EC `buffer' encoding.
  algorithms.c: Fix `max' property name in docstrings.
  catacomb/__init__.py (_HashBase): Check that integers are within bounds.
  debian/rules: Build using the provided Makefile.
  ...

4 years agot/: Add a test suite.
Mark Wooding [Sat, 16 Nov 2019 18:53:24 +0000 (18:53 +0000)]
t/: Add a test suite.

It's fairly substantial, but far from complete.  It's also a little
strange in places because it's been sent backwards in time from the
future.

When building the Debian package, run the tests verbosely, so that if
the test crashes I stand a chance of figuring out where.

4 years agoec.c: Don't lose error status when constructing points from a sequence.
Mark Wooding [Sun, 24 Nov 2019 22:30:48 +0000 (22:30 +0000)]
ec.c: Don't lose error status when constructing points from a sequence.

The code would call `ecptxl_2' or `ecptxl_3' as appropriate, stash the
error status in `rc', and then fall out of the `if/else if' ladder to
`ok' -- which clobbers `rc', losing the error.  This is unfortunate if
the point has been partially filled in.

The right fix is to go unconditionally to `end'.  We already have `rc'
set appropriately, so `ok' isn't necessary; `ecptxl_2' has already
converted the point to internal form, and `ecptxl_3' constructs the
point in internal form anyway, so it would be wrong to drop into `fix'.

4 years agoec.c: Free partially constructed points coordinatewise.
Mark Wooding [Sun, 24 Nov 2019 22:16:53 +0000 (22:16 +0000)]
ec.c: Free partially constructed points coordinatewise.

The `EC_DESTROY' macro assumes that the other coordinates are null if
and only if `p->x' is.  This works badly with the current code
structure, which fills in coordinates as it goes along, and I think this
is a better fix than trying to maintain the coordinates in temporaries
until we're done.

4 years ago*.c: Be more careful about `PySequence_Size'.
Mark Wooding [Sun, 24 Nov 2019 16:36:24 +0000 (16:36 +0000)]
*.c: Be more careful about `PySequence_Size'.

This can be implemented by Python, so it can throw exceptions.
Fortunately, Python checks that the result is nonnegative, so we don't
have to worry about that.

4 years agokey.c: Reformat the rest of the `KeyError' constructor.
Mark Wooding [Sun, 24 Nov 2019 16:26:22 +0000 (16:26 +0000)]
key.c: Reformat the rest of the `KeyError' constructor.

4 years agokey.c: Parse `KeyError' constructor arguments by hand.
Mark Wooding [Sun, 24 Nov 2019 16:25:18 +0000 (16:25 +0000)]
key.c: Parse `KeyError' constructor arguments by hand.

This allows additional arguments to be stored, as is conventional for
exception classes.

4 years agocatacomb-python.h: Add a macro for raising `OverflowError'.
Mark Wooding [Sun, 24 Nov 2019 14:59:35 +0000 (14:59 +0000)]
catacomb-python.h: Add a macro for raising `OverflowError'.

4 years agokey.c: Collect `KeyError' argument count as a separate step.
Mark Wooding [Sun, 24 Nov 2019 16:21:09 +0000 (16:21 +0000)]
key.c: Collect `KeyError' argument count as a separate step.

4 years agokey.c: Use tuple functions on `KeyError' argument tuple.
Mark Wooding [Sun, 24 Nov 2019 16:19:14 +0000 (16:19 +0000)]
key.c: Use tuple functions on `KeyError' argument tuple.

4 years agokey.c: Rename sad-path label to `end'.
Mark Wooding [Sun, 24 Nov 2019 14:54:21 +0000 (14:54 +0000)]
key.c: Rename sad-path label to `end'.

Now we can use our exception-raising macros.

4 years agokey.c: Delete duplicate setting of `errstring'.
Mark Wooding [Sun, 24 Nov 2019 14:48:27 +0000 (14:48 +0000)]
key.c: Delete duplicate setting of `errstring'.

This code is a total mess, and doesn't work anyway.  Let's start
cleaning it up.

4 years agoutil.c (mkexc): Populate dictionary before constructing exception class.
Mark Wooding [Sun, 24 Nov 2019 15:07:08 +0000 (15:07 +0000)]
util.c (mkexc): Populate dictionary before constructing exception class.

It turns out that the dictionary contents are copied into the new class
rather than being used by reference, so populating it later doesn't
actually do anything.

4 years agokey.c: Only set the error code.
Mark Wooding [Sun, 24 Nov 2019 14:50:01 +0000 (14:50 +0000)]
key.c: Only set the error code.

This briefly makes the error string unavailable, but only because the
actual constructor isn't wired up -- and if it were wired up then it
would fail immediately because it's programmed to accept only a single
argument.

4 years agocatacomb.c, util.c: Publish `KERR_...' symbols as negative numbers.
Mark Wooding [Sun, 24 Nov 2019 15:11:46 +0000 (15:11 +0000)]
catacomb.c, util.c: Publish `KERR_...' symbols as negative numbers.

They're supposed to be, but the existing `setconstants' machinery isn't
clever enough to do this properly.

Fixing this involves adding a flags word to `struct nameval' to identify
which constants should really be signed, and some fancy footwork to
convert unsigned integers back to negative values without upsetting C.

4 years agofield.c: Delete the completely unused `getfe' function.
Mark Wooding [Sat, 23 Nov 2019 16:04:29 +0000 (16:04 +0000)]
field.c: Delete the completely unused `getfe' function.

It was introduced in the original commit, and never used at all.

4 years agokey.c (convfilter): Fix sense of error tests.
Mark Wooding [Thu, 21 Nov 2019 18:23:56 +0000 (18:23 +0000)]
key.c (convfilter): Fix sense of error tests.

So this never worked either.

4 years agobuffer.c, ec.c: Fix required size for EC `buffer' encoding.
Mark Wooding [Thu, 21 Nov 2019 19:53:22 +0000 (19:53 +0000)]
buffer.c, ec.c: Fix required size for EC `buffer' encoding.

The problem is zero coordinates: the point at infinity is encoded as a
zero length word, so zero coordinates must be encoded as a single zero
byte, preceded by a length word of 1 -- which overruns the output buffer
provided, unless we take special care, which we haven't.

4 years agoalgorithms.c: Fix `max' property name in docstrings.
Mark Wooding [Tue, 19 Nov 2019 22:33:12 +0000 (22:33 +0000)]
algorithms.c: Fix `max' property name in docstrings.

How embarrassing.

4 years agocatacomb/__init__.py (_HashBase): Check that integers are within bounds.
Mark Wooding [Sun, 17 Nov 2019 22:57:47 +0000 (22:57 +0000)]
catacomb/__init__.py (_HashBase): Check that integers are within bounds.

The version of the `struct' module included with Python 2.5 writes a
warning to `stderr' and truncates rather than raising an exception.  Do
the work ourselves.

4 years agodebian/rules: Build using the provided Makefile.
Mark Wooding [Sun, 17 Nov 2019 04:23:00 +0000 (04:23 +0000)]
debian/rules: Build using the provided Makefile.

There were several problems with the old system.  Firstly, it only
actually worked by accident: setting an explicit build directory caused
Debhelper to search there for a makefile (which it didn't find, for
obvious reasons) and fall back to the Python distutils system.  That
would be OK, but only because there's only been one Python version I've
wanted to support in Debian for ages; but that's likely to change.  And
it won't run tests properly.

Instead, delete the `-B' option (which will break the upcoming tests).
Now Debhelper will build via the Makefile.  Set the `PYTHONS'
environment variable to the Python versions supported in Debian.  And
set the prefix correctly during installation.