From: Mark Wooding Date: Sun, 14 May 2017 03:28:02 +0000 (+0100) Subject: Merge branch '1.1.x' X-Git-Tag: 1.2.0~21 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/catacomb-python/commitdiff_plain/457b4e971a2795898c83a53ae4c27d6a893690d1?hp=30eef666012c79fa5cef125e2f6595167b4ed326 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) --- diff --git a/algorithms.c b/algorithms.c index 5b4f14b..5703901 100644 --- a/algorithms.c +++ b/algorithms.c @@ -35,21 +35,31 @@ PyTypeObject *keysz_pytype; PyTypeObject *keyszany_pytype, *keyszrange_pytype, *keyszset_pytype; PyObject *sha_pyobj, *has160_pyobj; +#ifndef KSZ_OPMASK +# define KSZ_OPMASK 0x1f +#endif + +#ifndef KSZ_16BIT +# define KSZ_16BIT 0x20 +#endif + PyObject *keysz_pywrap(const octet *k) { - switch (k[0]) { + unsigned op = *k++; +#define ARG(i) (op&KSZ_16BIT ? LOAD16(k + 2*(i)) : k[i]) + switch (op&KSZ_OPMASK) { case KSZ_ANY: { keysz_pyobj *o = PyObject_New(keysz_pyobj, keyszany_pytype); - o->dfl = k[1]; + o->dfl = ARG(0); return ((PyObject *)o); } break; case KSZ_RANGE: { keyszrange_pyobj *o = PyObject_New(keyszrange_pyobj, keyszrange_pytype); - o->dfl = k[1]; - o->min = k[2]; - o->max = k[3]; - o->mod = k[4]; + o->dfl = ARG(0); + o->min = ARG(1); + o->max = ARG(2); + o->mod = ARG(3); if (!o->mod) o->mod = 1; return ((PyObject *)o); } break; @@ -57,16 +67,17 @@ PyObject *keysz_pywrap(const octet *k) keyszset_pyobj *o = PyObject_New(keyszset_pyobj, keyszset_pytype); int i, n; - o->dfl = k[1]; - for (i = 0; k[i + 1]; i++) ; + o->dfl = ARG(0); + for (i = 0; ARG(i); i++) ; n = i; o->set = PyTuple_New(n); for (i = 0; i < n; i++) - PyTuple_SET_ITEM(o->set, i, PyInt_FromLong(k[i + 1])); + PyTuple_SET_ITEM(o->set, i, PyInt_FromLong(ARG(i))); return ((PyObject *)o); } break; default: abort(); } +#undef ARG } static PyObject *keyszany_pynew(PyTypeObject *ty, diff --git a/catacomb/__init__.py b/catacomb/__init__.py index 6fc3725..785838e 100644 --- a/catacomb/__init__.py +++ b/catacomb/__init__.py @@ -34,6 +34,20 @@ from sys import argv as _argv ## For the benefit of the default keyreporter, we need the program na,e. _base._ego(_argv[0]) +## How to fix a name back into the right identifier. Alas, the rules are not +## consistent. +def _fixname(name): + + ## Hyphens consistently become underscores. + name = name.replace('-', '_') + + ## But slashes might become underscores or just vanish. + if name.startswith('salsa20'): name = name.translate(None, '/') + else: name = name.replace('/', '_') + + ## Done. + return name + ## Initialize the module. Drag in the static methods of the various ## classes; create names for the various known crypto algorithms. def _init(): @@ -56,9 +70,9 @@ def _init(): setattr(c, j[plen:], classmethod(b[j])) for i in [gcciphers, gchashes, gcmacs, gcprps]: for c in i.itervalues(): - d[c.name.replace('-', '_').translate(None, '/')] = c + d[_fixname(c.name)] = c for c in gccrands.itervalues(): - d[c.name.replace('-', '_').translate(None, '/') + 'rand'] = c + d[_fixname(c.name + 'rand')] = c _init() ## A handy function for our work: add the methods of a named class to an diff --git a/debian/changelog b/debian/changelog index c7895ba..7f5abd2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,18 @@ +catacomb-python (1.1.2) experimental; urgency=low + + * Further 64-bit compatibility improvements. + * Fixed docstrings for a number of native methods. + * Fix range checking for `GRand' methods. + * Fix crash when deleting natively implemented object attributes. + * Fix bug which assigned the wrong hash to bytestrings. + * Fix `__int__' methods to return `long' objects when necessary. + Without this, there are unnecessary failures and bizarrely timed + exceptions. + * A couple of patches to provide forward compatibility with upstream + library changes. + + -- Mark Wooding Sun, 14 May 2017 04:25:35 +0100 + catacomb-python (1.1.1) experimental; urgency=low * ByteString operators: fix crashes on 64-bit platforms resulting from diff --git a/util.c b/util.c index 58d2fe7..d4b7fb0 100644 --- a/util.c +++ b/util.c @@ -83,6 +83,7 @@ int convulong(PyObject *o, void *pp) unsigned long *p = pp; PyObject *t; + if (!o) VALERR("can't delete"); if (PyInt_Check(o)) { i = PyInt_AS_LONG(o); if (i < 0) VALERR("must be nonnegative"); @@ -176,8 +177,11 @@ end: int convbool(PyObject *o, void *pp) { + if (!o) VALERR("can't delete"); *(int *)pp = PyObject_IsTrue(o); return (1); +end: + return (0); } /*----- Type messing ------------------------------------------------------*/