chiark / gitweb /
catacomb/pwsafe.py: Add a backend based on SQLite.
[catacomb-python] / algorithms.c
index be953b0757893906cb3aa01c4f2864b4d41a6c5e..16d426d0f8a5b0f3e7a6bf33edc35def295e2dde 100644 (file)
@@ -1,13 +1,11 @@
 /* -*-c-*-
- *
- * $Id$
  *
  * Symmetric cryptography
  *
  * (c) 2004 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of the Python interface to Catacomb.
  *
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * Catacomb/Python is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with Catacomb/Python; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -47,7 +45,7 @@ PyObject *keysz_pywrap(const octet *k)
     } break;
     case KSZ_RANGE: {
       keyszrange_pyobj *o =
-        PyObject_New(keyszrange_pyobj, keyszrange_pytype);
+       PyObject_New(keyszrange_pyobj, keyszrange_pytype);
       o->dfl = k[1];
       o->min = k[2];
       o->max = k[3];
@@ -57,7 +55,7 @@ PyObject *keysz_pywrap(const octet *k)
     } break;
     case KSZ_SET: {
       keyszset_pyobj *o =
-        PyObject_New(keyszset_pyobj, keyszset_pytype);
+       PyObject_New(keyszset_pyobj, keyszset_pytype);
       int i, n;
       o->dfl = k[1];
       for (i = 0; k[i + 1]; i++) ;
@@ -145,7 +143,7 @@ static PyObject *keyszset_pynew(PyTypeObject *ty,
     if (xx < 0) VALERR("key size cannot be negative");
     PyList_Append(l, x);
     Py_DECREF(x);
-    x = 0;    
+    x = 0;
   }
   Py_DECREF(set);
   if ((set = PySequence_Tuple(l)) == 0) goto end;
@@ -439,7 +437,7 @@ PyObject *gcipher_pywrap(PyObject *cobj, gcipher *c, unsigned f)
   g = PyObject_NEW(gcipher_pyobj, (PyTypeObject *)cobj);
   g->c = c;
   g->f = f;
-  return ((PyObject *)g);  
+  return ((PyObject *)g);
 }
 
 static PyObject *gcipher_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
@@ -455,23 +453,23 @@ static PyObject *gcipher_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
                         GC_INIT(GCCIPHER_CC(ty), k, sz),
                         f_freeme));
 end:
-  return (0);  
+  return (0);
 }
 
 PyObject *gccipher_pywrap(gccipher *cc)
 {
   gccipher_pyobj *g = newtype(gccipher_pytype, 0, cc->name);
   g->cc = cc;
-  g->ty.type.tp_basicsize = sizeof(gcipher_pyobj);
-  g->ty.type.tp_base = gcipher_pytype;
+  g->ty.ht_type.tp_basicsize = sizeof(gcipher_pyobj);
+  g->ty.ht_type.tp_base = gcipher_pytype;
   Py_INCREF(gcipher_pytype);
-  g->ty.type.tp_flags = (Py_TPFLAGS_DEFAULT |
-                        Py_TPFLAGS_BASETYPE |
-                        Py_TPFLAGS_HEAPTYPE);
-  g->ty.type.tp_alloc = PyType_GenericAlloc;
-  g->ty.type.tp_free = 0;
-  g->ty.type.tp_new = gcipher_pynew;
-  PyType_Ready(&g->ty.type);
+  g->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT |
+                           Py_TPFLAGS_BASETYPE |
+                           Py_TPFLAGS_HEAPTYPE);
+  g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
+  g->ty.ht_type.tp_free = 0;
+  g->ty.ht_type.tp_new = gcipher_pynew;
+  PyType_Ready(&g->ty.ht_type);
   return ((PyObject *)g);
 }
 
@@ -699,23 +697,23 @@ static PyObject *ghash_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
     goto end;
   return (ghash_pywrap((PyObject *)ty, GH_INIT(GCHASH_CH(ty)), f_freeme));
 end:
-  return (0);  
+  return (0);
 }
 
 PyObject *gchash_pywrap(gchash *ch)
 {
   gchash_pyobj *g = newtype(gchash_pytype, 0, ch->name);
   g->ch = ch;
-  g->ty.type.tp_basicsize = sizeof(ghash_pyobj);
-  g->ty.type.tp_base = ghash_pytype;
+  g->ty.ht_type.tp_basicsize = sizeof(ghash_pyobj);
+  g->ty.ht_type.tp_base = ghash_pytype;
   Py_INCREF(ghash_pytype);
-  g->ty.type.tp_flags = (Py_TPFLAGS_DEFAULT |
-                        Py_TPFLAGS_BASETYPE |
-                        Py_TPFLAGS_HEAPTYPE);
-  g->ty.type.tp_alloc = PyType_GenericAlloc;
-  g->ty.type.tp_free = 0;
-  g->ty.type.tp_new = ghash_pynew;
-  PyType_Ready(&g->ty.type);
+  g->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT |
+                           Py_TPFLAGS_BASETYPE |
+                           Py_TPFLAGS_HEAPTYPE);
+  g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
+  g->ty.ht_type.tp_free = 0;
+  g->ty.ht_type.tp_new = ghash_pynew;
+  PyType_Ready(&g->ty.ht_type);
   return ((PyObject *)g);
 }
 
@@ -727,7 +725,7 @@ PyObject *ghash_pywrap(PyObject *cobj, ghash *h, unsigned f)
   g = PyObject_NEW(ghash_pyobj, (PyTypeObject *)cobj);
   g->h = h;
   g->f = f;
-  return ((PyObject *)g);  
+  return ((PyObject *)g);
 }
 
 static void ghash_pydealloc(PyObject *me)
@@ -941,7 +939,7 @@ static PyObject *gmac_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
                      GM_KEY(GCMAC_CM(ty), k, sz),
                      f_freeme));
 end:
-  return (0);  
+  return (0);
 }
 
 static PyObject *gmhash_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
@@ -961,16 +959,16 @@ PyObject *gcmac_pywrap(gcmac *cm)
 {
   gcmac_pyobj *g = newtype(gcmac_pytype, 0, cm->name);
   g->cm = cm;
-  g->ty.type.tp_basicsize = sizeof(gmac_pyobj);
-  g->ty.type.tp_base = gmac_pytype;
+  g->ty.ht_type.tp_basicsize = sizeof(gmac_pyobj);
+  g->ty.ht_type.tp_base = gmac_pytype;
   Py_INCREF(gmac_pytype);
-  g->ty.type.tp_flags = (Py_TPFLAGS_DEFAULT |
-                   Py_TPFLAGS_BASETYPE |
-                   Py_TPFLAGS_HEAPTYPE);
-  g->ty.type.tp_alloc = PyType_GenericAlloc;
-  g->ty.type.tp_free = 0;
-  g->ty.type.tp_new = gmac_pynew;
-  PyType_Ready(&g->ty.type);
+  g->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT |
+                           Py_TPFLAGS_BASETYPE |
+                           Py_TPFLAGS_HEAPTYPE);
+  g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
+  g->ty.ht_type.tp_free = 0;
+  g->ty.ht_type.tp_new = gmac_pynew;
+  PyType_Ready(&g->ty.ht_type);
   return ((PyObject *)g);
 }
 
@@ -980,20 +978,20 @@ PyObject *gmac_pywrap(PyObject *cobj, gmac *m, unsigned f)
   if (!cobj) cobj = gcmac_pywrap((/*unconst*/ gcmac *)GM_CLASS(m));
   else Py_INCREF(cobj);
   g = newtype((PyTypeObject *)cobj, 0, 0);
-  g->ty.name = PyString_FromFormat("%s(keyed)", m->ops->c->name);
-  g->ty.type.tp_name = PyString_AS_STRING(g->ty.name);
-  g->ty.type.tp_base = gmhash_pytype;
+  g->ty.ht_name = PyString_FromFormat("%s(keyed)", m->ops->c->name);
+  g->ty.ht_type.tp_name = PyString_AS_STRING(g->ty.ht_name);
+  g->ty.ht_type.tp_base = gmhash_pytype;
   Py_INCREF(gmac_pytype);
-  g->ty.type.tp_flags = (Py_TPFLAGS_DEFAULT |
-                        Py_TPFLAGS_BASETYPE |
-                        Py_TPFLAGS_HEAPTYPE);
-  g->ty.type.tp_alloc = PyType_GenericAlloc;
-  g->ty.type.tp_free = 0;
-  g->ty.type.tp_new = gmhash_pynew;
-  PyType_Ready(&g->ty.type);
+  g->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT |
+                           Py_TPFLAGS_BASETYPE |
+                           Py_TPFLAGS_HEAPTYPE);
+  g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
+  g->ty.ht_type.tp_free = 0;
+  g->ty.ht_type.tp_new = gmhash_pynew;
+  PyType_Ready(&g->ty.ht_type);
   g->m = m;
   g->f = f;
-  return ((PyObject *)g);  
+  return ((PyObject *)g);
 }
 
 static void gmac_pydealloc(PyObject *me)
@@ -1203,7 +1201,7 @@ static const struct prpinfo *const gprptab[] = {
 #define PRP_ENTRY(PRE, pre) &pre##_prpinfo,
   PRPS(PRP_ENTRY)
   0
-};    
+};
 
 typedef struct gcprp_pyobj {
   PyHeapTypeObject ty;
@@ -1240,7 +1238,7 @@ static PyObject *gprp_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
   Py_INCREF(me);
   return (me);
 end:
-  return (0);  
+  return (0);
 }
 
 static void gprp_pydealloc(PyObject *me)
@@ -1250,16 +1248,16 @@ static PyObject *gcprp_pywrap(const prpinfo *prp)
 {
   gcprp_pyobj *g = newtype(gcprp_pytype, 0, prp->name);
   g->prp = prp;
-  g->ty.type.tp_basicsize = sizeof(gprp_pyobj) + prp->ctxsz;
-  g->ty.type.tp_base = gprp_pytype;
+  g->ty.ht_type.tp_basicsize = sizeof(gprp_pyobj) + prp->ctxsz;
+  g->ty.ht_type.tp_base = gprp_pytype;
   Py_INCREF(gprp_pytype);
-  g->ty.type.tp_flags = (Py_TPFLAGS_DEFAULT |
-                        Py_TPFLAGS_BASETYPE |
-                        Py_TPFLAGS_HEAPTYPE);
-  g->ty.type.tp_alloc = PyType_GenericAlloc;
-  g->ty.type.tp_free = 0;
-  g->ty.type.tp_new = gprp_pynew;
-  PyType_Ready(&g->ty.type);
+  g->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT |
+                           Py_TPFLAGS_BASETYPE |
+                           Py_TPFLAGS_HEAPTYPE);
+  g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
+  g->ty.ht_type.tp_free = 0;
+  g->ty.ht_type.tp_new = gprp_pynew;
+  PyType_Ready(&g->ty.ht_type);
   return ((PyObject *)g);
 }