pyke
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 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: 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 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 ago(Pruned history of `catacomb-python' begins here.)
Mark Wooding [Fri, 10 Apr 2020 22:02:06 +0000 (23:02 +0100)]
(Pruned history of `catacomb-python' begins here.)

The code which is now the `Pyke' library used to be part of the Catacomb
Python bindings.  Beginning here is a pruned version of that history,
limited to the files which actually contributed to the `Pyke' codebase.
It was constructed from the original history, starting at revision
10e6f88a407ce04807b6ad76a81be553f8d7abaa, by running

git filter-branch --prune-empty --index-filter '
git ls-files -s | {
  mode=old
  keep=
  while read m h s f; do
    case $mode,$f in
      old,util.c | old,catacomb.c | old,catacomb-python.h)
keep="$keep $m,$h,$f" ;;
      old,pyke/*)
keep="$m,$h,${f#*/}" mode=new ;;
      new,pyke/*)
keep="$keep $m,$h,${f#*/}" ;;
    esac
    git update-index --force-remove $f
  done
  for i in $keep; do
    git update-index --add --cacheinfo $i
  done
}
' pyke-prehistory.head -- pyke/ util.c catacomb.c catacomb-python.h

and the tucking this empty commit beneath the head which actually
introduces the `pyke/' directory.  (This subterfuge is, unfortunately,
necessary for `git subtree' to construct the right history.)

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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 agoutil.c: Use Python's machinery for handling 64-bit integers.
Mark Wooding [Sat, 19 Oct 2019 19:02:08 +0000 (20:02 +0100)]
util.c: Use Python's machinery for handling 64-bit integers.

Where available.

4 years agoutil.c: Augment `convu64' to collect its argument via `kludge64'.
Mark Wooding [Sat, 19 Oct 2019 18:59:59 +0000 (19:59 +0100)]
util.c: Augment `convu64' to collect its argument via `kludge64'.

Otherwise integers too large for `unsigned long' get rejected with an
error, even though they ought to be acceptable as a `uint64'.

4 years agoDeploy the new <ctype.h> and `foocmp' macros from mLib.
Mark Wooding [Fri, 4 Oct 2019 14:40:28 +0000 (15:40 +0100)]
Deploy the new <ctype.h> and `foocmp' macros from mLib.

4 years agoSet ELF visibility to keep all of our external symbols to ourselves.
Mark Wooding [Tue, 1 Oct 2019 10:40:41 +0000 (11:40 +0100)]
Set ELF visibility to keep all of our external symbols to ourselves.

4 years agoalgorithms.c, etc.: Support the new AEAD abstraction.
Mark Wooding [Fri, 9 Nov 2018 15:35:14 +0000 (15:35 +0000)]
algorithms.c, etc.: Support the new AEAD abstraction.

The new machinery means we can reimplement `secret_box' and
`secret_unbox' using Catacomb's `..._naclbox' AE scheme.

5 years agoalgorithms.c, knock-on: Eliminate `f_freeme' flags.
Mark Wooding [Fri, 9 Nov 2018 12:22:16 +0000 (12:22 +0000)]
algorithms.c, knock-on: Eliminate `f_freeme' flags.

These were being carefully set and checked on ciphers, hashes, and MACs,
for no good reason because the flag was always set.  Abolish it.

The flag still exists for `grand' objects because they get injected into
Python through the `pgen' event-handling machinery, and Python mustn't
destroy them just because it loses its reference.  (It also mustn't try
to hang onto them, so there's a longstanding bug in there.)

5 years agobytestring.c: Implement indexing, slicing, concatenation and repeating.
Mark Wooding [Fri, 9 Nov 2018 12:28:16 +0000 (12:28 +0000)]
bytestring.c: Implement indexing, slicing, concatenation and repeating.

Now these return bytestring objects, rather than Python strings.

5 years agoConsistently make keyword-lists be static and read-only.
Mark Wooding [Fri, 9 Nov 2018 12:16:59 +0000 (12:16 +0000)]
Consistently make keyword-lists be static and read-only.

We had an exciting mix of static and automatic storage durations, and
none were marked as `const'.  Python isn't `const'-correct, so we have
to cast away the `const'-ness: introduce a new macro `KWLIST' to do
this.

Also constify some other related tables, such as method names in
`pgev_python'.

5 years agocatacomb-python.h: Eliminate redundant declaration of `convgcipher'.
Mark Wooding [Fri, 9 Nov 2018 12:34:20 +0000 (12:34 +0000)]
catacomb-python.h: Eliminate redundant declaration of `convgcipher'.

There's another one a bit further down.

6 years agopubkey.c: Add support for Ed448 signatures, following RFC8032.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
pubkey.c: Add support for Ed448 signatures, following RFC8032.

6 years agopubkey.c: Support the `ed2559ctx' signature scheme from RFC8032.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
pubkey.c: Support the `ed2559ctx' signature scheme from RFC8032.

Main difference is the addition of a personalization string.

In the wrapper classes, forward unknown keyword arguments on to the
underlying implementation.

6 years agoAdd support for SHA3 and related algorithms.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
Add support for SHA3 and related algorithms.

This comes in three tranches.

  * There are the basic generic-interface algorithms for SHA3-*, SHAKE*,
    KMAC*, etc., which basically just turn up by themselves, and the
    RNGs based on SHAKE and KMAC which took a little more work.

  * There's a full implementation of the cSHAKE128 and cSHAKE256 XOFs as
    a new kind of object.

  * Based on this, there's a full KMAC implementation, with the fiddly
    bits in Python (but all the heavy lifting is done in C), with
    variable-length tag and everything.  Other constructions, e.g.,
    TupleHash, can easily be made in the same way.

Annoyingly, KMAC can't just be made from SHAKE by multiple inheritance
because Python gets confused about how it's supposed to construct the
objects, and, in particular, which `__new__' methods are OK to use.  It
seems that the relevant code is trying to use the `HEAPTYPE' flag as a
proxy for whether a type is implemented in C, which doesn't work for our
classes.  So there's a bunch of ugly delegation to do.

6 years agoalgorithms.c: Add basic support for Keccak[1600, n].
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
algorithms.c: Add basic support for Keccak[1600, n].

This takes the form of a simple object which encapsulates the
Keccak[1600, n] state and allows mix and extract operations (which
correspond to the I/O portions of absorb/squeeze and duplexing) and
step, which actually invokes the permutation to advance the state.

None of this keeps track of rate or capacity limits beyond the obvious
memory-safety checks, so you can really screw yourself if you're not
careful.

6 years agoutils.c: Raise exceptions from `convTHING' with null arguments.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
utils.c: Raise exceptions from `convTHING' with null arguments.

This can happen as a result of using `convTHING' in an attribute `set'
function, and the Python program trying to `del' the attribute.
Unfortunately, these conversion functions are already being used in this
context, and it leads to segfaults, e.g., from

  del C.Key(C.KeyFile('', C.KOPEN_WRITE | C.KOPEN_NOFILE), 0, 'k').exptime

Easy fix.

6 years agoMerge branch '1.1.x'
Mark Wooding [Sun, 14 May 2017 03:28:02 +0000 (04:28 +0100)]
Merge branch '1.1.x'

* 1.1.x:
  Release 1.1.2.
  catacomb/__init__.py: Fix up cipher etc. names better.
  algorithms.c: Support the new 16-bit key-size descriptors.
  group.c: Track Catacomb group internals change.
  utils.c: Raise exceptions from `convTHING' with null arguments.
  Return `long' objects when `int' is requested but the value won't fit.
  bytestring.c: Check for cached hash more carefully.
  rand.c: Careful range checking on `block' and `mp'.
  *.c: Fix docstrings for methods.
  Further fixing to use `Py_ssize_t' in place of int.

Conflicts:
debian/control (already wanted later catacomb-dev)
group.c (no need for compatibility with older Catacombs)

6 years agoutils.c: Raise exceptions from `convTHING' with null arguments.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
utils.c: Raise exceptions from `convTHING' with null arguments.

This can happen as a result of using `convTHING' in an attribute `set'
function, and the Python program trying to `del' the attribute.
Unfortunately, these conversion functions are already being used in this
context, and it leads to segfaults, e.g., from

  del C.Key(C.KeyFile('', C.KOPEN_WRITE | C.KOPEN_NOFILE), 0, 'k').exptime

Easy fix.

6 years agoReturn `long' objects when `int' is requested but the value won't fit.
Mark Wooding [Wed, 3 May 2017 11:48:27 +0000 (12:48 +0100)]
Return `long' objects when `int' is requested but the value won't fit.

Mostly, Python handles the error from the `int' conversion and falls
back to long, but there's something weird in iteration, where if you say

for i in ...:
  print '%d' % x

then the loop finishes and /then/ you get an exception for the overflow
from the failed conversion of x to an `int'.

Follow Python's actual behaviour: have `mp_tolong_checked' take an extra
argument indicating whether to throw an exception, and modify most of
the call sites to fall back to a conversion based on `mp_topylong'.

6 years agoFurther fixing to use `Py_ssize_t' in place of int.
Mark Wooding [Sun, 11 Sep 2016 23:14:16 +0000 (00:14 +0100)]
Further fixing to use `Py_ssize_t' in place of int.

This addresses the remaining compiler warnings when building for 64-bit
targets.

6 years agopubkey.c, catacomb/__init__.py: Add bindings for Hamburg's X448.
Mark Wooding [Wed, 26 Apr 2017 10:53:05 +0000 (11:53 +0100)]
pubkey.c, catacomb/__init__.py: Add bindings for Hamburg's X448.

6 years agopubkey.c, ...: Support Bernstein's `Ed25519' signature scheme.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
pubkey.c, ...: Support Bernstein's `Ed25519' signature scheme.

6 years agopubkey.c, ...: Support Bernstein's `X25519' key-agreement algorithm.
Mark Wooding [Wed, 12 Apr 2017 17:39:01 +0000 (18:39 +0100)]
pubkey.c, ...: Support Bernstein's `X25519' key-agreement algorithm.

6 years agoReturn `long' objects when `int' is requested but the value won't fit.
Mark Wooding [Wed, 3 May 2017 11:48:27 +0000 (12:48 +0100)]
Return `long' objects when `int' is requested but the value won't fit.

Mostly, Python handles the error from the `int' conversion and falls
back to long, but there's something weird in iteration, where if you say

for i in ...:
  print '%d' % x

then the loop finishes and /then/ you get an exception for the overflow
from the failed conversion of x to an `int'.

Follow Python's actual behaviour: have `mp_tolong_checked' take an extra
argument indicating whether to throw an exception, and modify most of
the call sites to fall back to a conversion based on `mp_topylong'.

7 years agobytestring.c, catacomb/__init__.py: Compare for equality in constant time.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
bytestring.c, catacomb/__init__.py: Compare for equality in constant time.

There's an explicit `ctstreq' function which just does what you wanted.
Also, `ByteString' objects now have a rich-compare method which always
compares for equality in constant time.  Ordering comparisons are
variable time still.

There's a little chicanery to retain the hash function from `str'.

Also add a simple `check' method to `GHash' and `Poly1305Hash' which
compares a hsah or MAC tag in constant time and returns a boolean
result.

7 years ago*.c: Declare `PY_SSIZE_T_CLEAN'.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
*.c: Declare `PY_SSIZE_T_CLEAN'.

Now we can process large strings on 64-bit targets.  Err, win?

7 years agoalgorithms.c: Add support for Poly1305.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
algorithms.c: Add support for Poly1305.

7 years agocatacomb-python.h, util.c: Support for declaring types with weird metatypes.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
catacomb-python.h, util.c: Support for declaring types with weird metatypes.

7 years agoutil.c: Add conversions between Python objects and `kludge64'.
Mark Wooding [Mon, 12 Sep 2016 21:27:23 +0000 (22:27 +0100)]
util.c: Add conversions between Python objects and `kludge64'.

7 years agocatacomb-python.h: Don't inhibit 64-bit type detection any more.
Mark Wooding [Mon, 12 Sep 2016 21:26:53 +0000 (22:26 +0100)]
catacomb-python.h: Don't inhibit 64-bit type detection any more.

We'll be using `kludge64', and the definition must properly match up
with the library.

7 years agoutil.c: Zap spurious whitespace.
Mark Wooding [Mon, 12 Sep 2016 21:23:58 +0000 (22:23 +0100)]
util.c: Zap spurious whitespace.

7 years agoFurther fixing to use `Py_ssize_t' in place of int.
Mark Wooding [Sun, 11 Sep 2016 23:14:16 +0000 (00:14 +0100)]
Further fixing to use `Py_ssize_t' in place of int.

This addresses the remaining compiler warnings when building for 64-bit
targets.

8 years agocatacomb.c, ec.c: Bindings for the new EC2OSP/OS2ECP functions.
Mark Wooding [Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)]
catacomb.c, ec.c: Bindings for the new EC2OSP/OS2ECP functions.

8 years agoUse ValueError instead of SyntaxError throughout.
Mark Wooding [Fri, 29 May 2015 08:34:09 +0000 (09:34 +0100)]
Use ValueError instead of SyntaxError throughout.

SyntaxError has a much more specific meaning, and some software, such as
`ipython', expect it to carry lots of other detailed information.

So abolish the `SYNERR' macro, and use `VALERR' instead consistently.  I
wish I had an excuse for this blunder, but I don't.

8 years agoFix the missing-module-names bug properly.
Mark Wooding [Tue, 26 May 2015 15:02:01 +0000 (16:02 +0100)]
Fix the missing-module-names bug properly.

Introduce a wrapper `typeready' around `PyType_Ready' which sets the
module name, and call it everywhere it's needed.

8 years agocatacomb-python.h: Promote `util' to the head of the list.
Mark Wooding [Tue, 26 May 2015 15:00:32 +0000 (16:00 +0100)]
catacomb-python.h: Promote `util' to the head of the list.

If anything needs to prepare for other modules, it's common utilities.

8 years agocatacomb-python.h: Formatting fix.
Mark Wooding [Tue, 26 May 2015 15:00:52 +0000 (16:00 +0100)]
catacomb-python.h: Formatting fix.

9 years agocatacomb.c: Handle Python's randomize hashing parameters properly.
Mark Wooding [Fri, 10 Apr 2015 14:19:25 +0000 (15:19 +0100)]
catacomb.c: Handle Python's randomize hashing parameters properly.

9 years agoProper hashing for comparable object types.
Mark Wooding [Fri, 10 Apr 2015 14:19:25 +0000 (15:19 +0100)]
Proper hashing for comparable object types.

Some of the existing object hash algorithms have changed, but I think
we'll live with that.

9 years agoStamp the module name onto types properly.
Mark Wooding [Fri, 10 Apr 2015 14:19:25 +0000 (15:19 +0100)]
Stamp the module name onto types properly.

Our types are `dynamic', because the Python code adds extra methods to
them.  Apparently the correct thing to do in such cases is to put the
raw type name in the `tp_name' slot, and stuff the module name into
`tp_dict' by hand.

9 years agomp.c: Binding for `mp_fibonacci'.
Mark Wooding [Fri, 27 Feb 2015 14:40:26 +0000 (14:40 +0000)]
mp.c: Binding for `mp_fibonacci'.

10 years agoFix a few minor warnings.
Mark Wooding [Sun, 23 Jun 2013 08:04:24 +0000 (09:04 +0100)]
Fix a few minor warnings.

10 years agoOverhaul formatting.
Mark Wooding [Sun, 16 Jun 2013 14:22:38 +0000 (15:22 +0100)]
Overhaul formatting.

Expunge CVS droppings and use newer comment stylings.

16 years agoutil: Actually initialize the utilities properly.
Mark Wooding [Fri, 4 Apr 2008 23:55:18 +0000 (00:55 +0100)]
util: Actually initialize the utilities properly.

Failure to do this cases segfaults when we actually come to do things
like iteration.

17 years agoGeneral: Fix lots of whitespace issues.
Mark Wooding [Sat, 17 Feb 2007 12:18:00 +0000 (12:18 +0000)]
General: Fix lots of whitespace issues.

17 years agoGeneral: Update for Python 2.5.
Mark Wooding [Wed, 25 Oct 2006 18:36:19 +0000 (19:36 +0100)]
General: Update for Python 2.5.

  * This renamed the members of heap types. so there's a compatibility
    macro now.

  * Debian has moved on to Python 2.4 as its standard version, so track
    that.

  * Also provide Python 2.5 packages now that we can.

18 years agogetulong: Compare with LONG_MAX to decide what Python type to use.
Mark Wooding [Wed, 22 Mar 2006 12:58:45 +0000 (12:58 +0000)]
getulong: Compare with LONG_MAX to decide what Python type to use.

This may reduce the number of bignums created on 64-bit machines.

18 years agoRemove the various `getuNN' functions and replace them with getulong().
Mark Wooding [Tue, 7 Mar 2006 14:25:03 +0000 (14:25 +0000)]
Remove the various `getuNN' functions and replace them with getulong().

They weren't doing any real good anyway, and the implementation was
randomly buggy.

18 years agoutil: Report ValuError (not TypeError) for failed integer conversions.
Mark Wooding [Tue, 7 Mar 2006 14:12:42 +0000 (14:12 +0000)]
util: Report ValuError (not TypeError) for failed integer conversions.

18 years agomappings: Separate mapping methods into read-only and read-write.
Mark Wooding [Mon, 6 Mar 2006 16:56:41 +0000 (16:56 +0000)]
mappings: Separate mapping methods into read-only and read-write.

18 years agoBug squashing.
Mark Wooding [Sat, 28 Jan 2006 19:03:25 +0000 (19:03 +0000)]
Bug squashing.

  * Fix setting functions to check for null value (interpreted as property
    deletion) and raise an exception or do something else useful.

  * Fix conversion of read buffer to string so it returns the remainder
    rather than the whole thing.

  * Make conversions between MP and Python long work on PyObjects rather
    than PyLongObjects, to eliminate pointless type casts.

  * Fix primefield constructor argument parsing so that it doesn't crash!

  * Fix radix checking in MP conversions to exclude +/-1, and 0 for output.
    This turns into a little function now.

  * Do argument checking on Jacobi function.

18 years agoReorganization: split out utilities; mapping methods
Mark Wooding [Sat, 28 Jan 2006 18:46:07 +0000 (18:46 +0000)]
Reorganization: split out utilities; mapping methods

  * Move non-project-specific Python utilities into a separate file.  They
    might conceivably find their way into a new project some day.

  * Implement the standard mapping methods generically (i.e., in terms of
    basic Python mapping operations).

  * Use the mapping methods for the various key-object-related mappings.

  * Start fixing setter functions for null values.

18 years agoalgorithms: Add PRPs as objects in their own right.
Mark Wooding [Sat, 28 Jan 2006 18:07:53 +0000 (18:07 +0000)]
algorithms: Add PRPs as objects in their own right.

18 years agoCheckin, Debianized and more or less complete.
mdw [Mon, 26 Sep 2005 12:58:11 +0000 (12:58 +0000)]
Checkin, Debianized and more or less complete.

19 years agoMore fixing for modern Pythons. No longer works with 2.2. Sorry.
mdw [Fri, 29 Apr 2005 13:11:19 +0000 (13:11 +0000)]
More fixing for modern Pythons.  No longer works with 2.2.  Sorry.

19 years agoFixing for Python 2.3 and later.
mdw [Wed, 27 Apr 2005 23:40:07 +0000 (23:40 +0000)]
Fixing for Python 2.3 and later.

19 years agoVarious minor fixings.
mdw [Sun, 10 Apr 2005 23:38:11 +0000 (23:38 +0000)]
Various minor fixings.

19 years agoInitial check-in of catacomb-python.
mdw [Sun, 10 Apr 2005 18:03:11 +0000 (18:03 +0000)]
Initial check-in of catacomb-python.