catacomb-python
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 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.

4 years agobuffer.c (wbmeth_putblkN): Check input block size.
Mark Wooding [Sat, 12 Oct 2019 20:07:05 +0000 (21:07 +0100)]
buffer.c (wbmeth_putblkN): Check input block size.

Otherwise the C code fails an assertion.

4 years agobuffer.c: Return 64-bit values, even if they're too big for `getulong'.
Mark Wooding [Fri, 11 Oct 2019 09:01:11 +0000 (10:01 +0100)]
buffer.c: Return 64-bit values, even if they're too big for `getulong'.

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 agokey.c, pgen.c: Add missing guards for `del' to property `set' functions.
Mark Wooding [Sat, 19 Oct 2019 17:19:07 +0000 (18:19 +0100)]
key.c, pgen.c: Add missing guards for `del' to property `set' functions.

4 years ago*.py: Use `str.replace' rather than `str.translate'.
Mark Wooding [Sat, 19 Oct 2019 16:10:41 +0000 (17:10 +0100)]
*.py: Use `str.replace' rather than `str.translate'.

It seems that the `None' argument to `str.translate' was a brief
experiment added in 2.6 which didn't survive into 3.0.

4 years agobuffer.c: Fix typoed variable name in `assert'.
Mark Wooding [Fri, 14 Jul 2017 22:13:56 +0000 (23:13 +0100)]
buffer.c: Fix typoed variable name in `assert'.

Evidently I've never actually compiled this code with the assertions
turned on before.

(cherry picked from commit a11849068dd55f5997365984cce759c0f2d7caeb)

5 years agoRelease 1.2.1.1. 1.2.1.1
Mark Wooding [Mon, 24 Dec 2018 15:21:16 +0000 (15:21 +0000)]
Release 1.2.1.1.

5 years agodebian/control: Build-depend on `python-all-dev', not explicit versions.
Mark Wooding [Wed, 16 Aug 2017 03:54:26 +0000 (04:54 +0100)]
debian/control: Build-depend on `python-all-dev', not explicit versions.

5 years agodebian/: Use `dh_python2' for packaging.
Mark Wooding [Wed, 16 Aug 2017 03:54:08 +0000 (04:54 +0100)]
debian/: Use `dh_python2' for packaging.

5 years agosetup.py: Fix the advertised package URL.
Mark Wooding [Fri, 28 Jul 2017 23:58:08 +0000 (00:58 +0100)]
setup.py: Fix the advertised package URL.

Unfortunately the old URL was terrible both because it was poorly chosen
and because it was broken long ago (if indeed it ever worked in the
first place).

6 years agoMerge remote-tracking branch 'origin/HEAD'
Mark Wooding [Fri, 7 Jul 2017 20:18:42 +0000 (21:18 +0100)]
Merge remote-tracking branch 'origin/HEAD'

* origin/HEAD:
  catacomb/pwsafe.py: Fix stupid error which breaks `delete'.

6 years agocatacomb/pwsafe.py: Fix stupid error which breaks `delete'.
Mark Wooding [Sat, 1 Jul 2017 09:43:44 +0000 (10:43 +0100)]
catacomb/pwsafe.py: Fix stupid error which breaks `delete'.

6 years agoRelease 1.2.1. 1.2.1
Mark Wooding [Fri, 16 Jun 2017 00:01:24 +0000 (01:01 +0100)]
Release 1.2.1.

6 years agopubkey.c (dsa_setup): Make sure `u' is None or an MP object.
Mark Wooding [Sun, 28 May 2017 18:03:08 +0000 (19:03 +0100)]
pubkey.c (dsa_setup): Make sure `u' is None or an MP object.

Don't just store the caller's object and hope for the best.

6 years agopubkey.c: Fix keyword-argument order for KCDSAPriv constructor.
Mark Wooding [Sun, 28 May 2017 18:03:08 +0000 (19:03 +0100)]
pubkey.c: Fix keyword-argument order for KCDSAPriv constructor.

6 years agoec.c: Fix embarrassing use-after-free in EC point hashing.
Mark Wooding [Sun, 28 May 2017 18:03:08 +0000 (19:03 +0100)]
ec.c: Fix embarrassing use-after-free in EC point hashing.

The hashed data is sometimes (unpredictably) mangled by freeing causing
hash mismatches, which is annoying.  Also, obviously incorrect.

7 years agoRelease 1.2.0. 1.2.0
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
Release 1.2.0.

7 years agopubkey.c: Allow RSA key generation with user-chosen public exponent.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
pubkey.c: Allow RSA key generation with user-chosen public exponent.

New feature in the underlying library.

7 years agomp.c: Add binding for `leastcongruent' function.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
mp.c: Add binding for `leastcongruent' function.

7 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.

7 years agocatacomb/__init__.py: Settle on SHAKE256 for X448 box-key generation.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
catacomb/__init__.py: Settle on SHAKE256 for X448 box-key generation.

This matches Ed448 hashing, which is probably a good thing.

7 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.

7 years agopubkey.c: Capture Ed25519 binding in a macro.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
pubkey.c: Capture Ed25519 binding in a macro.

Now we can add more EdDSA instances with similar shapes without too much
trouble.

Also, slightly sneakily, make EdDSA verification functions take keyword
arguments.

7 years agocatacomb/__init__.py: Add `beginhash', `endhash' to the EdDSA interface.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
catacomb/__init__.py: Add `beginhash', `endhash' to the EdDSA interface.

This is consistent with the other DSA-ish classes.

7 years agocatacomb/__init__.py: Refactor the XDH and EdDSA classes.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
catacomb/__init__.py: Refactor the XDH and EdDSA classes.

  * Introduce `_BasePub' and `_BasePriv' underneath the existing
    classes, and move obvious common functionality like size checking
    and printing into them.  Push key-generation down here too.

  * Use `KeySZ' objects for key length checking rather than just the
    bare constants.  In particular, this means that `Ed25519Priv' isn't
    fussy about key sizes, preserving this feature of the underlying
    implementation.

  * Split the implementation of pretty-printing into more pieces.  In
    particular, now `_BasePriv' only needs to implement the printing of
    the private key rather than the whole lot.  (Plain `__repr__' is
    still duplicated, but the code is smaller and this is more
    tolerable.)

  * Rename `_Boxy...' to `_XDH...', since this appears to be the generic
    term I'm using for such things now.

7 years agopubkey.c: Factor out commonality between X25519 and X448.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
pubkey.c: Factor out commonality between X25519 and X448.

7 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.

7 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.

7 years agoalgorithms.py: Support SHA512/224 and SHA512/256.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
algorithms.py: Support SHA512/224 and SHA512/256.

7 years agoalgorithms.py: Cope better with algs with funny characters in their names.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
algorithms.py: Cope better with algs with funny characters in their names.

Defend against `/' in names when making include-file names, and defend
against `/' and `-' when forming identifier names.

7 years agorand.c, algorithms.py: Change how kinds of RNGs are distinguished.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
rand.c, algorithms.py: Change how kinds of RNGs are distinguished.

Rather than a set of flags, assign them numbers and use `switch'.  It
doesn't seem like the flags are helpfully marking out sets of RNGs, and
this approach scales better to handling more kinds.

7 years agobytestring.c, catacomb/__init__.py: Introduce and use `zero' method.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
bytestring.c, catacomb/__init__.py: Introduce and use `zero' method.

Seems like strings of zero bytes are especially useful.  Add a class
method to `ByteString' to generate them efficiently, and use it to make
the magic `Z128' constant.

7 years agocatacomb/__init__.py: Calculate `X25519_BASE' and `X448_BASE'.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
catacomb/__init__.py: Calculate `X25519_BASE' and `X448_BASE'.

Easier on the eyes and brain.

7 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.

7 years agobytestring.c: Use `arg' rather than `args' for argument tuples.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
bytestring.c: Use `arg' rather than `args' for argument tuples.

7 years agocatacomb/__init__.py: Rename stupidly named arguments.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
catacomb/__init__.py: Rename stupidly named arguments.

I don't know where I got `*kw' from.  Sorry.

7 years agocatacomb/__init__.py: Fix bungled `unbox' method of `_BoxyPriv'.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
catacomb/__init__.py: Fix bungled `unbox' method of `_BoxyPriv'.

7 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)

7 years agoRelease 1.1.2. 1.1.2
Mark Wooding [Sun, 14 May 2017 03:25:50 +0000 (04:25 +0100)]
Release 1.1.2.

7 years agocatacomb/__init__.py: Fix up cipher etc. names better.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
catacomb/__init__.py: Fix up cipher etc. names better.

Now `sha512/256', for example, will have the right name.

7 years agoalgorithms.c: Support the new 16-bit key-size descriptors.
Mark Wooding [Thu, 11 May 2017 09:42:15 +0000 (10:42 +0100)]
algorithms.c: Support the new 16-bit key-size descriptors.

7 years agogroup.c: Track Catacomb group internals change.
Mark Wooding [Thu, 20 Apr 2017 00:58:05 +0000 (01:58 +0100)]
group.c: Track Catacomb group internals change.

7 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.

7 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: Check for cached hash more carefully.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
bytestring.c: Check for cached hash more carefully.

The `CACHE_HASH' symbol has been missing for years because the feature
is always on nowadays.  Amazingly, I never noticed.

7 years agorand.c: Careful range checking on `block' and `mp'.
Mark Wooding [Mon, 12 Sep 2016 21:26:09 +0000 (22:26 +0100)]
rand.c: Careful range checking on `block' and `mp'.

  * For `mp', don't allow the `or' mask to be wider than the requested
    result.

  * For `range', insist that the limit is strictly positive, so that the
    output range is actually inhabited.

These parallel currently unreleased fixes to the underlying library,
which are required for things to work properly; so bump the dependency.

7 years ago*.c: Fix docstrings for methods.
Mark Wooding [Mon, 12 Sep 2016 21:23:38 +0000 (22:23 +0100)]
*.c: Fix docstrings for methods.

Mostly fixing method names andarguments broken by bad copy-and-paste
editing.

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.

7 years agoalgorithms.c: Check whether `setiv' and `bdry' are implemented before calling.
Mark Wooding [Sun, 7 May 2017 19:01:47 +0000 (20:01 +0100)]
algorithms.c: Check whether `setiv' and `bdry' are implemented before calling.

Oops, easy segfault.

7 years agocatacomb/__init__.py: Add printing for more key types.
Mark Wooding [Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)]
catacomb/__init__.py: Add printing for more key types.

Now that we have secret suppression, it's not an attractive nuisance to
print key material for public keys like RSA, DSA, KCDSA, and XDH.  So do
that.

Digging key material out of symmetric crypto objects is really hard, so
we don't try to do that.

7 years agocatacomb/__init__.py: Don't print secret bits of keys by default.
Mark Wooding [Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)]
catacomb/__init__.py: Don't print secret bits of keys by default.

Introduce a `PRINT_SECRETS' flag which can easily be twiddled (e.g., in
IPython) to control whether obvious secrets are printed literally or
censored (the default).  This is intended to make accidental leakage a
bit less likely, rather than as a security feature.

7 years agocatacomb/__init__.py: Add `_clsname' for printing class names.
Mark Wooding [Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)]
catacomb/__init__.py: Add `_clsname' for printing class names.

Replace both the ugly `type(me).__name__' rune, and literal class names.

7 years agocatacomb/__init__.py: Abstract out common printing for `KeyData' subclasses.
Mark Wooding [Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)]
catacomb/__init__.py: Abstract out common printing for `KeyData' subclasses.

Introduce `_guts' to return the thing that each subclass encapsulates.
`KeyDataStructured' is a special snowflake which I'm willing to handle
separately.

7 years agopubkey.c: Change the arguments to {DSA,KCDSA}{Pub,Priv}.
Mark Wooding [Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)]
pubkey.c: Change the arguments to {DSA,KCDSA}{Pub,Priv}.

  * Don't allow a private-key `u' argument to `*Pub'.

  * Have the private key argument `u' precede the public key `p' to
    `*Priv'.

  * Make the public key optional to `*Priv', and compute it correctly if
    not provided.

This is an incompatible change, but I've resolved not to care.  The old
interface was obviously crazy.

7 years agocatacomb/__init__.py: Print group elements properly.
Mark Wooding [Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)]
catacomb/__init__.py: Print group elements properly.

Slightly grim: add a method to group objects to export their elements as
some useful type, and then call that from the element print function.

7 years agocatacomb/__init__.py: Print groups properly.
Mark Wooding [Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)]
catacomb/__init__.py: Print groups properly.

7 years agocatacomb/__init__.py: Add printing for points on known curves.
Mark Wooding [Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)]
catacomb/__init__.py: Add printing for points on known curves.

Now the coordinates print correctly as field elements.

7 years agogroup.c: Make element `toec()' method return point on correct curve.
Mark Wooding [Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)]
group.c: Make element `toec()' method return point on correct curve.

Rather than a generic point.  Now it will print correctly.

7 years agocatacomb/__init__.py: Abstract out common pretty-printing patterns.
Mark Wooding [Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)]
catacomb/__init__.py: Abstract out common pretty-printing patterns.

Don't hardwire indentation levels from header lengths; don't hardwire
type names; hide away the ugly `type(me).__name__' rune.

7 years agocatacomb/__init__.py: Support IPython's pretty-printer.
Mark Wooding [Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)]
catacomb/__init__.py: Support IPython's pretty-printer.

Add `_repr_pretty_' methods to many types to improve presentation.
Also, sneakily add a bunch of printing methods to the key-management
classes.

7 years agocatacomb/__init__.py: Support `len' on `_groupmap' objects.
Mark Wooding [Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)]
catacomb/__init__.py: Support `len' on `_groupmap' objects.

7 years agocatacomb/__init__.py: Use `%#x' rather than `hex' now.
Mark Wooding [Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)]
catacomb/__init__.py: Use `%#x' rather than `hex' now.

The reason `%x' used not to work is the recently-fixed bug whereby
conversions to `int' raised exceptions rather than returning `long'.

7 years agoMerge branches 'mdw/latin-ietf' and 'mdw/curve25519'
Mark Wooding [Wed, 3 May 2017 12:02:54 +0000 (13:02 +0100)]
Merge branches 'mdw/latin-ietf' and 'mdw/curve25519'

* mdw/latin-ietf:
  algorithms.py: Support the IETF versions of ChaCha etc. with 96-bit nonce.

* mdw/curve25519:
  pubkey.c, catacomb/__init__.py: Add bindings for Hamburg's X448.
  pubkey.c, ...: Support Bernstein's `Ed25519' signature scheme.
  pubkey.c, ...: Support Bernstein's `X25519' key-agreement algorithm.

7 years agoalgorithms.py: Support the IETF versions of ChaCha etc. with 96-bit nonce.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
algorithms.py: Support the IETF versions of ChaCha etc. with 96-bit nonce.