Merge branch '1.1.x'
authorMark Wooding <mdw@distorted.org.uk>
Sun, 14 May 2017 03:28:02 +0000 (04:28 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 14 May 2017 03:28:02 +0000 (04:28 +0100)
* 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)

catacomb-python.h
catacomb.c
util.c

index bed97d5..d7e2543 100644 (file)
 
 /*----- Header files ------------------------------------------------------*/
 
+#define PY_SSIZE_T_CLEAN
+
 #include <Python.h>
 #include <longintrepr.h>
 #include <structmember.h>
 
-#undef ULLONG_MAX
-#undef ULONG_LONG_MAX
-
 #include <mLib/darray.h>
 #include <mLib/dstr.h>
 #include <mLib/macros.h>
@@ -47,6 +46,7 @@
 #include <mLib/unihash.h>
 
 #include <catacomb/buf.h>
+#include <catacomb/ct.h>
 
 #include <catacomb/grand.h>
 #include <catacomb/rand.h>
@@ -65,6 +65,7 @@
 #include <catacomb/gmac.h>
 #include <catacomb/md5.h>
 #include <catacomb/md5-hmac.h>
+#include <catacomb/poly1305.h>
 #include <catacomb/sha.h>
 #include <catacomb/sha-mgf.h>
 #include <catacomb/sha-hmac.h>
@@ -86,6 +87,9 @@
 #include <catacomb/ptab.h>
 #include <catacomb/bintab.h>
 #include <catacomb/dsa.h>
+#include <catacomb/x25519.h>
+#include <catacomb/x448.h>
+#include <catacomb/ed25519.h>
 
 #include <catacomb/gf.h>
 #include <catacomb/gfreduce.h>
 
 #define root_pytype 0
 #define type_pytype &PyType_Type
-#define INITTYPE(ty, base) do {                                                \
+#define INITTYPE_META(ty, base, meta) do {                             \
   ty##_pytype_skel.tp_base = base##_pytype;                            \
-  ty##_pytype = inittype(&ty##_pytype_skel);                           \
+  ty##_pytype = inittype(&ty##_pytype_skel, meta##_pytype);            \
 } while (0)
+#define INITTYPE(ty, base) INITTYPE_META(ty, base, type)
 
 #define INSERT(name, ob) do {                                          \
   PyObject *_o = (PyObject *)(ob);                                     \
@@ -238,16 +243,18 @@ extern int convulong(PyObject *, void *);
 DOUINTSZ(DECL_CONVU_)
 extern int convmpw(PyObject *, void *);
 extern int convuint(PyObject *, void *);
+extern int convk64(PyObject *, void *);
 extern int convszt(PyObject *, void *);
 extern int convbool(PyObject *, void *);
 extern PyObject *abstract_pynew(PyTypeObject *, PyObject *, PyObject *);
 extern PyObject *getbool(int);
 extern PyObject *getulong(unsigned long);
+extern PyObject *getk64(kludge64);
 extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *);
 
 extern PyObject *mkexc(PyObject *, PyObject *, const char *, PyMethodDef *);
 extern void typeready(PyTypeObject *);
-extern PyTypeObject *inittype(PyTypeObject *);
+extern PyTypeObject *inittype(PyTypeObject *, PyTypeObject *);
 extern void addmethods(const PyMethodDef *);
 extern PyMethodDef *donemethods(void);
 
index 49d0f40..9c83c9d 100644 (file)
@@ -45,6 +45,9 @@ static const struct nameval consts[] = {
   C(KF_NONSECRET),
   C(KF_BURN), C(KF_OPT),
   C(EC_XONLY), C(EC_YBIT), C(EC_LSB), C(EC_CMPR), C(EC_EXPLY), C(EC_SORT),
+  C(X25519_KEYSZ), C(X25519_PUBSZ), C(X25519_OUTSZ),
+  C(X448_KEYSZ), C(X448_PUBSZ), C(X448_OUTSZ),
+  C(ED25519_KEYSZ), C(ED25519_PUBSZ), C(ED25519_SIGSZ),
 #define ENTRY(tag, val, str) C(KERR_##tag),
   KEY_ERRORS(ENTRY)
 #undef ENTRY
diff --git a/util.c b/util.c
index 8fab0bf..d4b7fb0 100644 (file)
--- a/util.c
+++ b/util.c
@@ -42,6 +42,29 @@ PyObject *getulong(unsigned long w)
     return (PyLong_FromUnsignedLong(w));
 }
 
+static PyObject *i32 = 0;
+static int init_i32(void)
+  { if (!i32 && (i32 = PyInt_FromLong(32)) == 0) return (-1); return (0); }
+
+PyObject *getk64(kludge64 u)
+{
+  PyObject *i = 0, *j = 0, *t;
+  PyObject *rc = 0;
+
+  if (init_i32()) goto end;
+  if ((i = PyLong_FromUnsignedLong(HI64(u))) == 0) goto end;
+  if ((t = PyNumber_InPlaceLshift(i, i32)) == 0) goto end;
+  Py_DECREF(i); i = t;
+  if ((j = PyLong_FromUnsignedLong(LO64(u))) == 0) goto end;
+  if ((t = PyNumber_InPlaceOr(i, j)) == 0) goto end;
+  Py_DECREF(i); i = t;
+  if ((rc = PyNumber_Int(i)) == 0) goto end;
+end:
+  if (i) Py_DECREF(i);
+  if (j) Py_DECREF(j);
+  return (rc);
+}
+
 PyObject *getbool(int b)
 {
   if (b) RETURN_TRUE;
@@ -104,6 +127,28 @@ end:
   return (0);
 }
 
+int convk64(PyObject *o, void *pp)
+{
+  PyObject *i = 0, *t;
+  int rc = 0;
+  uint32 lo, hi;
+
+  if (init_i32()) goto end;
+  if ((i = PyNumber_Int(o)) == 0) goto end;
+  lo = PyInt_AsUnsignedLongMask(i);
+  if ((t = PyNumber_InPlaceRshift(i, i32)) == 0) goto end;
+  Py_DECREF(i); i = t;
+  hi = PyInt_AsUnsignedLongMask(i);
+  if ((t = PyNumber_InPlaceRshift(i, i32)) == 0) goto end;
+  Py_DECREF(i); i = t;
+  if (PyObject_IsTrue(i)) VALERR("out of range");
+  SET64(*(kludge64 *)pp, hi, lo);
+  rc = 1;
+end:
+  if (i) Py_DECREF(i);
+  return (rc);
+}
+
 int convmpw(PyObject *o, void *pp)
 {
   unsigned long u;
@@ -182,9 +227,9 @@ void typeready(PyTypeObject *ty)
   PyDict_SetItemString(ty->tp_dict, "__module__", modname);
 }
 
-PyTypeObject *inittype(PyTypeObject *tyskel)
+PyTypeObject *inittype(PyTypeObject *tyskel, PyTypeObject *meta)
 {
-  PyTypeObject *ty = newtype(&PyType_Type, tyskel, 0);
+  PyTypeObject *ty = newtype(meta, tyskel, 0);
   ty->tp_flags |= Py_TPFLAGS_HEAPTYPE;
   typeready(ty);
   return (ty);
@@ -230,8 +275,8 @@ PyMethodDef *donemethods(void)
 
 /*----- Exceptions --------------------------------------------------------*/
 
-PyObject * mkexc(PyObject *mod, PyObject *base,
-                const char *name, PyMethodDef *mm)
+PyObject *mkexc(PyObject *mod, PyObject *base,
+               const char *name, PyMethodDef *mm)
 {
   PyObject *nameobj = 0;
   PyObject *dict = 0;