catacomb-python
4 years ago.gdbinit: Delete this obsolete file. master
Mark Wooding [Tue, 7 Apr 2020 23:53:56 +0000 (00:53 +0100)]
.gdbinit: Delete this obsolete file.

It's set up for my particular development environment, using a Python
version that's not even supported any more.  And project-specific
`.gdbinit' files really don't work very well as things to distribute,
for vaguely obvious security reasons.

4 years agoMerge branch '1.3.x' into HEAD
Mark Wooding [Tue, 7 Apr 2020 23:59:00 +0000 (00:59 +0100)]
Merge branch '1.3.x' into HEAD

* 1.3.x:
  t/t-rand.py: Set the correct refernce seed value for `dsarand'.
  rand.c: More `Py_ssize_t' fixes.

4 years agot/t-rand.py: Set the correct refernce seed value for `dsarand'. 1.3.x
Mark Wooding [Tue, 7 Apr 2020 23:40:52 +0000 (00:40 +0100)]
t/t-rand.py: Set the correct refernce seed value for `dsarand'.

The number of steps taken is different on 32- and 64-bit platforms, with
no especially easy way to calculate it in a principled way.  Just use a
stupid case analysis to get the right answer.

4 years agoMerge branch '1.2.x' into 1.3.x
Mark Wooding [Tue, 7 Apr 2020 23:56:01 +0000 (00:56 +0100)]
Merge branch '1.2.x' into 1.3.x

* 1.2.x:
  rand.c: More `Py_ssize_t' fixes.

4 years agorand.c: More `Py_ssize_t' fixes.
Mark Wooding [Tue, 7 Apr 2020 23:19:14 +0000 (00:19 +0100)]
rand.c: More `Py_ssize_t' fixes.

4 years agoMerge branch '1.3.x'
Mark Wooding [Mon, 6 Apr 2020 02:38:50 +0000 (02:38 +0000)]
Merge branch '1.3.x'

* 1.3.x:
  ec.c: Fix length type which should have been `Py_ssize_t'.

4 years agoMerge branch '1.2.x' into 1.3.x
Mark Wooding [Mon, 6 Apr 2020 02:38:33 +0000 (02:38 +0000)]
Merge branch '1.2.x' into 1.3.x

* 1.2.x:
  ec.c: Fix length type which should have been `Py_ssize_t'.

4 years agoec.c: Fix length type which should have been `Py_ssize_t'.
Mark Wooding [Mon, 6 Apr 2020 02:34:24 +0000 (02:34 +0000)]
ec.c: Fix length type which should have been `Py_ssize_t'.

4 years agoMerge branch '1.3.x'
Mark Wooding [Wed, 27 Nov 2019 15:12:23 +0000 (15:12 +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 [Wed, 27 Nov 2019 15:11:08 +0000 (15:11 +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 negative constants correctly.
  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 negative constants correctly.
Mark Wooding [Sun, 24 Nov 2019 15:11:46 +0000 (15:11 +0000)]
catacomb.c, util.c: Publish negative constants correctly.

The various `KERR_...' constants and `PGEN_ABORT' are canonically
negative integers, but weren't published correctly.  Add a flags word to
`struct nameval' to identify constants which should really be signed,
and some fancy footwork to convert unsigned integers back to negative
values without upsetting C.  Adjust the `C' macro to spot negative
constants and mark them specially.

Not all is well.  In particular, the `KEXP_...' constants should /not/
be published as signed values, even if `time_t' is signed on the target
platform, because the Python bindings handle them exclusively as
`unsigned long' values.  To make this work, also introduce `CF' which
allows us to set the flags explicitly, and use it for `KEXP_...'.

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.

4 years agodebian/control: Add an explicit build-dependency on `dh-python'.
Mark Wooding [Mon, 25 Nov 2019 17:30:56 +0000 (17:30 +0000)]
debian/control: Add an explicit build-dependency on `dh-python'.

4 years agocatacomb/__init__.py: Make KMAC `copy' work.
Mark Wooding [Sun, 17 Nov 2019 03:14:51 +0000 (03:14 +0000)]
catacomb/__init__.py: Make KMAC `copy' work.

Two fixes needed:

  * Return the `new' object from `copy'.

  * Introduce a `_bare_new' class method to handle constructing the
    destination object, because `KMAC...' objects need a key argument.

4 years agocatacomb.c: Publish `RAND_IBITS' constant.
Mark Wooding [Sun, 17 Nov 2019 03:14:31 +0000 (03:14 +0000)]
catacomb.c: Publish `RAND_IBITS' constant.

This is a limit on how much you can request in `seed', so it's sort of
important.

4 years agorand.c: Fix `TrueRand' constructor so it can possibly work.
Mark Wooding [Fri, 15 Nov 2019 18:30:55 +0000 (18:30 +0000)]
rand.c: Fix `TrueRand' constructor so it can possibly work.

4 years agopubkey.c (RSAPriv): Fix segfault if `p' is provided but not `q'.
Mark Wooding [Fri, 15 Nov 2019 13:30:43 +0000 (13:30 +0000)]
pubkey.c (RSAPriv): Fix segfault if `p' is provided but not `q'.

Stupid typo.

4 years agocatacomb/__init__.py (_ShakeBase._copy): Actally copy the hash state.
Mark Wooding [Mon, 14 Oct 2019 00:04:46 +0000 (01:04 +0100)]
catacomb/__init__.py (_ShakeBase._copy): Actally copy the hash state.

Rather than sharing because that doesn't end well.

4 years agoalgorithms.c (ShakeNN.copy): Return the copy rather than the original.
Mark Wooding [Mon, 14 Oct 2019 00:03:58 +0000 (01:03 +0100)]
algorithms.c (ShakeNN.copy): Return the copy rather than the original.

4 years agoalgorithms.c (KECCAK.extract): Fix method name in keyword-args string.
Mark Wooding [Mon, 14 Oct 2019 00:00:20 +0000 (01:00 +0100)]
algorithms.c (KECCAK.extract): Fix method name in keyword-args string.

4 years agoalgorithms.c (hLATIN_prf): Allow all supported sizes of key.
Mark Wooding [Sun, 13 Oct 2019 23:59:30 +0000 (00:59 +0100)]
algorithms.c (hLATIN_prf): Allow all supported sizes of key.

4 years agoalgorithms.c: Add missing guard for `del' to property `set' functions.
Mark Wooding [Sun, 20 Oct 2019 00:19:18 +0000 (01:19 +0100)]
algorithms.c: Add missing guard for `del' to property `set' functions.

Continuing the work of 9444777c58c60253afdabf5b45011440845770e0.

4 years agoutil.c: Make `default' arguments optional in `get', `setdefault', `pop'.
Mark Wooding [Sun, 17 Nov 2019 01:34:12 +0000 (01:34 +0000)]
util.c: Make `default' arguments optional in `get', `setdefault', `pop'.

Alas, `pop' is a little trickier than the others.

4 years agoutil.c: Fix sense of error check in `popitem'.
Mark Wooding [Sun, 17 Nov 2019 01:33:34 +0000 (01:33 +0000)]
util.c: Fix sense of error check in `popitem'.

4 years agorand.c, pgen.c: Invalidate random generators from pgen events.
Mark Wooding [Fri, 9 Nov 2018 17:23:00 +0000 (17:23 +0000)]
rand.c, pgen.c: Invalidate random generators from pgen events.

I've not actually seen a crash from a Python program which keeps hold of
the random generator from a prime-generation event and tries to use it
after the operation has finished, but it was certainly possible.

Arrange for the event object to retain the random generator object (so
it always hands out the same one when requested), and invalidates it
when the event is itself invalidated.

This also involves messing with the `grand' code to cope with the idea
of invalidated random generators.

(cherry picked from commit d65d80d7c096e6afc500270ee29909f64869e5dc)

4 years agoec.c: Pass a dummy length argument to `PyObject_AsReadBuffer'.
Mark Wooding [Sat, 16 Nov 2019 22:42:32 +0000 (22:42 +0000)]
ec.c: Pass a dummy length argument to `PyObject_AsReadBuffer'.

Otherwise it just raises a `SystemException'.  So this code never
worked.

4 years agocatacomb-python.h, *.c: Fix how Python `pgen' handlers handle exceptions.
Mark Wooding [Thu, 14 Nov 2019 19:08:53 +0000 (19:08 +0000)]
catacomb-python.h, *.c: Fix how Python `pgen' handlers handle exceptions.

Oh, this was a mess.  The old code would convert an exception from a
Python handler into `PGEN_ABORT', and hope that the exception state was
still available when the overall operation ended.

This doesn't work.  In particular, steppers and testers are finalized by
calling them with `PGEN_DONE', and the interpreter doesn't like
re-entering Python with an exception set.  (In debug builds, this is an
assertion failure.)

Overhaul all of this nonsense.

  * Add a collection of utilities for saving and restoring the exception
    state.

  * Add a hook, in the `catacomb' module, for reporting `lost'
    exceptions, for the case where further exceptions are raised while
    responding to a first exception.

  * Use a larger `pypgev' structure to track the state of a Python event
    handler through the framework.  This structure holds a reference to
    the Python object itself, and a slot for recording an exception.

  * When a Python handler fails, stash the exception state in the slot
    provided by the `pypgev' structure if there isn't one already, and
    clear the pending exception.  If there is already an exception in
    the slot, then report the new exception through the hook described
    above.

  * Once a `pgen' operation completes, if it raised any exceptions at
    all, then the first of these is left in the exception slot.  If it
    fails otherwise, then we supply a generic exception.

4 years agopgen.c (pgev_python): Delete pointless refcount manipulation.
Mark Wooding [Thu, 14 Nov 2019 18:59:24 +0000 (18:59 +0000)]
pgen.c (pgev_python): Delete pointless refcount manipulation.

4 years agocatacomb/__init__.py: Awful bodge for symbol conflict.
Mark Wooding [Fri, 14 Jul 2017 22:19:41 +0000 (23:19 +0100)]
catacomb/__init__.py: Awful bodge for symbol conflict.

It seems that, in Debian jessie and later, the main Python binary now
exports `md5_init' and friends.  Unfortunately, this overrides
Catacomb's existing `md5_init' with a rather different version, and the
result is a segfault (on i386) or wrong answers (on amd64).

So, as an unpleasant bodge (while this broken thing makes its way
through Debian, see bug #868366), try to force the `RTLD_DEEPBIND' flag
when loading the module.  This is unfortunate, because Python doesn't
actually advertise this flag, at least in my version.

(cherry picked from commit a3ae4a9f590ef84d8e6eac0bc94873a9fd943073)

4 years agocatacomb/__init__.py: Rearrange the imports.
Mark Wooding [Fri, 14 Jul 2017 22:18:13 +0000 (23:18 +0100)]
catacomb/__init__.py: Rearrange the imports.

Sort the ordinary Python imports into alphabetical order (by module
name, rather than by import, if I'm only taking one or two symbols).
Move the main extension import into its own section, because it's going
to grow.

(cherry picked from commit 378ceeef4e0663d913cb448c32022522d39e7848)

4 years agocatacomb/__init__.py: Import `sys' as a whole.
Mark Wooding [Fri, 14 Jul 2017 22:16:02 +0000 (23:16 +0100)]
catacomb/__init__.py: Import `sys' as a whole.

We're only using `argv' in one place, so this isn't a significant
hardship.  And I'll want more things from `sys' soon.

(cherry picked from commit c04b289c577a5cdf6d5dd641f7b541d90a93adff)

4 years agomp.c, util.c: Use `Py_ssize_t' for lengths.
Mark Wooding [Sun, 10 Nov 2019 22:39:15 +0000 (22:39 +0000)]
mp.c, util.c: Use `Py_ssize_t' for lengths.

Missed some from the earlier pass.

4 years agomp.c: Fix crash converting elliptic curve point-at-infinity to integer.
Mark Wooding [Sun, 10 Nov 2019 13:23:49 +0000 (13:23 +0000)]
mp.c: Fix crash converting elliptic curve point-at-infinity to integer.

4 years agopgen.c, rand.c: Check correct variable when rejecting delete operations.
Mark Wooding [Thu, 14 Nov 2019 18:55:41 +0000 (18:55 +0000)]
pgen.c, rand.c: Check correct variable when rejecting delete operations.

4 years agorand.c (BBSPriv.generate): Release the event handler afterwards.
Mark Wooding [Thu, 14 Nov 2019 18:53:56 +0000 (18:53 +0000)]
rand.c (BBSPriv.generate): Release the event handler afterwards.

4 years agomp.c: Return the result of `GFN' transformations as `GF'.
Mark Wooding [Wed, 13 Nov 2019 02:54:55 +0000 (02:54 +0000)]
mp.c: Return the result of `GFN' transformations as `GF'.

And not `MP', which is simply wrong.

4 years agomp.c: Don't leak the field polynomial.
Mark Wooding [Wed, 13 Nov 2019 02:54:29 +0000 (02:54 +0000)]
mp.c: Don't leak the field polynomial.

4 years agomp.c: Release the `GFN' object through channels on error.
Mark Wooding [Wed, 13 Nov 2019 02:50:55 +0000 (02:50 +0000)]
mp.c: Release the `GFN' object through channels on error.

If the given element turns out not to actually generate a normal basis
then we have to give up constructing the `GFN' object and raise an
exception.  In turns out that debug versions of Python get really
unhappy if you try to free objects which still have nonzero reference
counts, so:

  * use `Py_DECREF' to free the object on error; and

  * mark the object (by leaving `p' null) so that we don't actually
    free the conversion matrices if they're weren't set up.

4 years agomp.c: Check that CRT moduli are pairwise coprime.
Mark Wooding [Sun, 10 Nov 2019 22:46:35 +0000 (22:46 +0000)]
mp.c: Check that CRT moduli are pairwise coprime.

4 years agomp.c: Arrange to free `xx' on exit.
Mark Wooding [Sun, 10 Nov 2019 22:41:19 +0000 (22:41 +0000)]
mp.c: Arrange to free `xx' on exit.

4 years agomp.c: Check that CRT moduli are actually positive.
Mark Wooding [Sun, 10 Nov 2019 22:55:11 +0000 (22:55 +0000)]
mp.c: Check that CRT moduli are actually positive.

4 years agofield.c: Convert external-format field element to hex/octal.
Mark Wooding [Wed, 23 Oct 2019 22:18:00 +0000 (23:18 +0100)]
field.c: Convert external-format field element to hex/octal.

Rather than going through the effort of calculating the external
representation of the field element and then returning the internal
version.

4 years agofield.c: Return the binary-field polynomial as, err, a polynomial.
Mark Wooding [Wed, 23 Oct 2019 09:39:23 +0000 (10:39 +0100)]
field.c: Return the binary-field polynomial as, err, a polynomial.

Sharing the extraction code with the prime-field case means it gets
returned as an integer.

4 years agorand.c: Add missing return-value mnemonic in docstring.
Mark Wooding [Fri, 22 Nov 2019 18:30:37 +0000 (18:30 +0000)]
rand.c: Add missing return-value mnemonic in docstring.

4 years ago*.c: Consistently show keyword arguments as optional in docstrings.
Mark Wooding [Wed, 9 Oct 2019 10:45:45 +0000 (11:45 +0100)]
*.c: Consistently show keyword arguments as optional in docstrings.

4 years agopgen.c: Add missing `EV' arg in `PrimeGenEventHandler' method docstrings.
Mark Wooding [Fri, 22 Nov 2019 18:33:33 +0000 (18:33 +0000)]
pgen.c: Add missing `EV' arg in `PrimeGenEventHandler' method docstrings.

4 years agomp.c: Fix Jacobi symbol notation in docstring.
Mark Wooding [Fri, 22 Nov 2019 18:57:22 +0000 (18:57 +0000)]
mp.c: Fix Jacobi symbol notation in docstring.

4 years agomp.c: Describe `MP' and `GF' conversion semantics.
Mark Wooding [Fri, 22 Nov 2019 18:56:34 +0000 (18:56 +0000)]
mp.c: Describe `MP' and `GF' conversion semantics.

4 years agomp.c: Spell `MP' and `GF' in the correct case in docstrings.
Mark Wooding [Fri, 22 Nov 2019 18:55:46 +0000 (18:55 +0000)]
mp.c: Spell `MP' and `GF' in the correct case in docstrings.

4 years agogroup.c: Fix capitalization of `ECPt' in docstring.
Mark Wooding [Fri, 22 Nov 2019 17:23:15 +0000 (17:23 +0000)]
group.c: Fix capitalization of `ECPt' in docstring.

4 years agoec.c: Add missing optional argument to docstring.
Mark Wooding [Fri, 22 Nov 2019 17:22:27 +0000 (17:22 +0000)]
ec.c: Add missing optional argument to docstring.

4 years agobytestring.c (bytestring_pyrepeat): Don't divide by zero.
Mark Wooding [Fri, 11 Oct 2019 08:53:00 +0000 (09:53 +0100)]
bytestring.c (bytestring_pyrepeat): Don't divide by zero.

4 years agofield.c: Fix misleading docstrings.
Mark Wooding [Fri, 18 Oct 2019 21:37:00 +0000 (22:37 +0100)]
field.c: Fix misleading docstrings.

It seems that the `value' and `_value' properties have always been able
to return `GF' for binary field elements.

4 years agobuffer.c: Fix docstrings.
Mark Wooding [Fri, 11 Oct 2019 10:06:05 +0000 (11:06 +0100)]
buffer.c: Fix docstrings.

4 years agoutil.c: Fix docstrings for generic-map iterator classes.
Mark Wooding [Sat, 19 Oct 2019 19:33:28 +0000 (20:33 +0100)]
util.c: Fix docstrings for generic-map iterator classes.

4 years agogroup.c: Fix docstring keyword for `G.checkgroup'.
Mark Wooding [Sat, 19 Oct 2019 19:32:51 +0000 (20:32 +0100)]
group.c: Fix docstring keyword for `G.checkgroup'.

4 years agoec.c (ecpt_pyrichcompare): Fix point comparisons.
Mark Wooding [Tue, 15 Oct 2019 11:09:44 +0000 (12:09 +0100)]
ec.c (ecpt_pyrichcompare): Fix point comparisons.

Previously we'd just reject comparisons of points with different curves.
Instead, support comparing curveless points with curvy ones by just
comparing the points coordinatewise.

Unfortunately, to make equality be transitive, this means permitting
comparisons between points on different curves, which is unpleasant.

4 years agoec.c (ecpt_pyhash): Fix hashing.
Mark Wooding [Tue, 15 Oct 2019 11:02:59 +0000 (12:02 +0100)]
ec.c (ecpt_pyhash): Fix hashing.

Previously, hashing a curveless point would just crash, which is
surprisingly bad form.  Replace this mess with a simpler thing which
just converts the point to external form and hashes the coordinates.

4 years agofield.c, mp.c: Hash `GF' and `FE' objects the same as `MP'.
Mark Wooding [Tue, 15 Oct 2019 10:48:39 +0000 (11:48 +0100)]
field.c, mp.c: Hash `GF' and `FE' objects the same as `MP'.

They can be compared for equality, and so they must hash the same way.

4 years agomp.c: Factor out and export `mphash'.
Mark Wooding [Tue, 15 Oct 2019 10:48:12 +0000 (11:48 +0100)]
mp.c: Factor out and export `mphash'.

4 years agoec.c (ec2osp, os2ecp): Collect flags correctly.
Mark Wooding [Sat, 12 Oct 2019 12:44:54 +0000 (13:44 +0100)]
ec.c (ec2osp, os2ecp): Collect flags correctly.

Previously `ec2osp' collected an `int', which probably wasn't completely
terrible, and `os2ecp' collected a float, which probably was.

4 years agoec.c: Fix reported function name in `ec2osp'.
Mark Wooding [Fri, 11 Oct 2019 09:00:46 +0000 (10:00 +0100)]
ec.c: Fix reported function name in `ec2osp'.

4 years agoec.c: Fix keyword-argument list for `os2ecp'.
Mark Wooding [Fri, 11 Oct 2019 09:00:19 +0000 (10:00 +0100)]
ec.c: Fix keyword-argument list for `os2ecp'.

4 years agoec.c (eccurve_pyrichcompare): Check that second operand has correct type.
Mark Wooding [Fri, 18 Oct 2019 21:15:46 +0000 (22:15 +0100)]
ec.c (eccurve_pyrichcompare): Check that second operand has correct type.

A segfault waiting to happen, which has been lurking since the
beginning.

4 years agoec.c (ecpt_pymul): Don't leak the scalar value.
Mark Wooding [Fri, 18 Oct 2019 20:57:12 +0000 (21:57 +0100)]
ec.c (ecpt_pymul): Don't leak the scalar value.

4 years agoec.c: Don't drop through into an error case.
Mark Wooding [Fri, 18 Oct 2019 20:17:37 +0000 (21:17 +0100)]
ec.c: Don't drop through into an error case.

4 years agoec.c: Fix three-argument point construction.
Mark Wooding [Fri, 18 Oct 2019 20:16:24 +0000 (21:16 +0100)]
ec.c: Fix three-argument point construction.

This has been wrong literally forever.

4 years agobuffer.c: Don't advertise `WBUF.putecpt' as a keyword method.
Mark Wooding [Sat, 19 Oct 2019 19:25:39 +0000 (20:25 +0100)]
buffer.c: Don't advertise `WBUF.putecpt' as a keyword method.

4 years agocatacomb/__init__.py (BaseRat, MP, GF): Add missing true-division methods.
Mark Wooding [Sat, 19 Oct 2019 19:23:46 +0000 (20:23 +0100)]
catacomb/__init__.py (BaseRat, MP, GF): Add missing true-division methods.

Since these all produce exact (rational) results, they satisfy the true-
division requirements.

4 years agocatacomb/__init__.py (BaseRat): Add missing reverse-multiplication method.
Mark Wooding [Sat, 19 Oct 2019 19:21:02 +0000 (20:21 +0100)]
catacomb/__init__.py (BaseRat): Add missing reverse-multiplication method.

4 years agocatacomb/__init__.py (BaseRat): Make comparisons actually work.
Mark Wooding [Sun, 20 Oct 2019 01:27:53 +0000 (02:27 +0100)]
catacomb/__init__.py (BaseRat): Make comparisons actually work.

This was broken in 83c77564338b3e410eb2ca2db3d35173dd6666cc.