(Pruned history of `catacomb-python' begins here.)
[pyke] / catacomb-python.h
index 368c7bb..5c5611e 100644 (file)
@@ -1,13 +1,11 @@
 /* -*-c-*-
  *
- * $Id$
- *
  * Definitions for Catacomb bindings
  *
  * (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.
 
 /*----- Header files ------------------------------------------------------*/
 
+#define PY_SSIZE_T_CLEAN
+
 #include <Python.h>
 #include <longintrepr.h>
 #include <structmember.h>
 
-#include <mLib/darray.h>
 #include <mLib/dstr.h>
 #include <mLib/macros.h>
+#include <mLib/quis.h>
+#include <mLib/unihash.h>
 
 #include <catacomb/buf.h>
+#include <catacomb/ct.h>
 
 #include <catacomb/grand.h>
 #include <catacomb/rand.h>
 #include <catacomb/dsarand.h>
 #include <catacomb/sslprf.h>
 #include <catacomb/tlsprf.h>
+#include <catacomb/blkc.h>
 
 #include <catacomb/gcipher.h>
+#include <catacomb/gaead.h>
 #include <catacomb/ghash.h>
 #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>
+#include <catacomb/keccak1600.h>
+#include <catacomb/sha3.h>
 
 #include <catacomb/mp.h>
 #include <catacomb/mpint.h>
@@ -72,6 +79,7 @@
 #include <catacomb/mpmont.h>
 #include <catacomb/mpbarrett.h>
 #include <catacomb/mpreduce.h>
+#include <catacomb/mp-fibonacci.h>
 
 #include <catacomb/pgen.h>
 #include <catacomb/pfilt.h>
 #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/ed448.h>
 
 #include <catacomb/gf.h>
 #include <catacomb/gfreduce.h>
 #include <catacomb/passphrase.h>
 #include <catacomb/pixie.h>
 
+#include <catacomb/share.h>
+#include <catacomb/gfshare.h>
+
+/*----- Other preliminaries -----------------------------------------------*/
+
+#define GOBBLE_SEMI extern int notexist
+#if defined(__GNUC__) && defined(__ELF__)
+#  define PRIVATE_SYMBOLS _Pragma("GCC visibility push(hidden)") GOBBLE_SEMI
+#  define PUBLIC_SYMBOLS _Pragma("GCC visibility pop") GOBBLE_SEMI
+#  define EXPORT __attribute__((__visibility__("default")))
+#else
+#  define PRIVATE_SYMBOLS GOBBLE_SEMI
+#  define PUBLIC_SYMBOLS GOBBLE_SEMI
+#  define EXPORT
+#endif
+
+PRIVATE_SYMBOLS;
+
 /*----- Utility macros ----------------------------------------------------*/
 
 #define RETURN_OBJ(obj) do { Py_INCREF(obj); return (obj); } while (0)
   goto end;                                                            \
 } while (0)
 #define VALERR(str) EXCERR(PyExc_ValueError, str)
+#define OVFERR(str) EXCERR(PyExc_OverflowError, str)
 #define TYERR(str) EXCERR(PyExc_TypeError, str)
+#define IXERR(str) EXCERR(PyExc_IndexError, str)
 #define ZDIVERR(str) EXCERR(PyExc_ZeroDivisionError, str)
-#define SYNERR(str) EXCERR(PyExc_SyntaxError, str)
 #define SYSERR(str) EXCERR(PyExc_SystemError, str)
+#define NIERR(str) EXCERR(PyExc_NotImplementedError, str)
+#define INDEXERR(idx) do {                                             \
+  PyErr_SetObject(PyExc_KeyError, idx);                                        \
+  goto end;                                                            \
+} while (0)
 #define OSERR(name) do {                                               \
   PyErr_SetFromErrnoWithFilename(PyExc_OSError, name);                 \
   goto end;                                                            \
 } while (0)
-#define PGENERR do { pgenerr(); goto end; } while (0)
+#define PGENERR(exc) do { pgenerr(exc); goto end; } while (0)
 
 #define CONVFUNC(ty, cty, ext)                                         \
   int conv##ty(PyObject *o, void *p)                                   \
 
 #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)
+
+extern PyObject *home_module;
+extern PyObject *modname;
 
-#define INSERT(name, ob) do {                                          \
+#define INSERT(name, ob) do {  \
   PyObject *_o = (PyObject *)(ob);                                     \
-  Py_INCREF(_o);                                                       \
+  Py_INCREF(_o);                                                       \
   PyModule_AddObject(mod, name, _o);                                   \
 } while (0)
 
+#define INSEXC(name, var, base, meth)                                  \
+  INSERT(name, var = mkexc(mod, base, name, meth))
+
 #define METH(func, doc)                                                        \
   { #func, METHNAME(func), METH_VARARGS, doc },
 #define KWMETH(func, doc)                                              \
 #define MEMBER(name, ty, f, doc)                                       \
   { #name, ty, offsetof(MEMBERSTRUCT, name), f, doc },
 
-#define MODULES(DO)                                                    \
-  DO(bytestring)                                                       \
-  DO(rand) DO(algorithms) DO(pubkey) DO(pgen)                          \
-  DO(mp) DO(field) DO(ec) DO(group)                                    \
-  DO(passphrase)
+#define MODULES(_)                                                     \
+  _(util)                                                              \
+  _(bytestring) _(buffer)                                              \
+  _(rand) _(algorithms) _(pubkey) _(pgen)                              \
+  _(mp) _(field) _(ec) _(group)                                                \
+  _(passphrase) _(share) _(key)
 #define DOMODINIT(m) m##_pyinit();
 #define DOMODINSERT(m) m##_pyinsert(mod);
 #define INIT_MODULES do { MODULES(DOMODINIT) } while (0)
 #define INSERT_MODULES do { MODULES(DOMODINSERT) } while (0)
-
-#define DO(m)                                                          \
+#define DECLARE_MODINIT(m)                                             \
   extern void m##_pyinit(void);                                                \
   extern void m##_pyinsert(PyObject *);
-MODULES(DO)
-#undef DO
+
+MODULES(DECLARE_MODINIT)
 
 #define FREEOBJ(obj)                                                   \
   (((PyObject *)(obj))->ob_type->tp_free((PyObject *)(obj)))
 
+#define GEN(func, base)                                                        \
+  static PyObject *func(void)                                          \
+  {                                                                    \
+    PyObject *d = PyDict_New();                                                \
+    PyObject *o;                                                       \
+    int i;                                                             \
+                                                                       \
+    for (i = 0; g##base##tab[i]; i++) {                                        \
+      o = gc##base##_pywrap((/*unconst*/ gc##base *)g##base##tab[i]);  \
+      PyDict_SetItemString(d,                                          \
+                          (/*unconst*/ char *)g##base##tab[i]->name,   \
+                          o);                                          \
+      Py_DECREF(o);                                                    \
+    }                                                                  \
+    return (d);                                                                \
+  }
+
+#define KWLIST (/*unconst*/ char **)kwlist
+
+struct nameval { const char *name; unsigned f; unsigned long value; };
+#define CF_SIGNED 1u
+extern void setconstants(PyObject *, const struct nameval *);
+
+extern PyObject *mexp_common(PyObject *, PyObject *, size_t,
+                            PyObject *(*id)(PyObject *),
+                            int (*fill)(void *, PyObject *,
+                                        PyObject *, PyObject *),
+                            PyObject *(*exp)(PyObject *, void *, int),
+                            void (*drop)(void *));
+
+extern int convulong(PyObject *, void *);
+#define DECL_CONVU_(n) extern int convu##n(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 *);
+
+struct excinfo { PyObject *ty, *val, *tb; };
+#define EXCINFO_INIT { 0, 0, 0 }
+
+extern PyObject *mkexc(PyObject *, PyObject *, const char *, PyMethodDef *);
+#define INIT_EXCINFO(exc) do {                                         \
+  struct excinfo *_exc = (exc); _exc->ty = _exc->val = _exc->tb = 0;   \
+} while (0)
+#define RELEASE_EXCINFO(exc) do {                                      \
+  struct excinfo *_exc = (exc);                                                \
+  Py_XDECREF(_exc->ty);         _exc->ty  = 0;                                 \
+  Py_XDECREF(_exc->val); _exc->val = 0;                                        \
+  Py_XDECREF(_exc->tb);         _exc->tb  = 0;                                 \
+} while (0)
+#define STASH_EXCINFO(exc) do {                                                \
+  struct excinfo *_exc = (exc);                                                \
+  PyErr_Fetch(&_exc->ty, &_exc->val, &_exc->tb);                       \
+  PyErr_NormalizeException(&_exc->ty, &_exc->val, &_exc->tb);          \
+} while (0)
+#define RESTORE_EXCINFO(exc) do {                                      \
+  struct excinfo *_exc = (exc);                                                \
+  PyErr_Restore(_exc->ty, _exc->val, _exc->tb);                                \
+  _exc->ty = _exc->val = _exc->tb = 0;                                 \
+} while (0)
+extern void report_lost_exception(struct excinfo *, const char *, ...);
+extern void report_lost_exception_v(struct excinfo *, const char *, va_list);
+extern void stash_exception(struct excinfo *, const char *, ...);
+extern void restore_exception(struct excinfo *, const char *, ...);
+
+extern void typeready(PyTypeObject *);
+extern PyTypeObject *inittype(PyTypeObject *, PyTypeObject *);
+extern void addmethods(const PyMethodDef *);
+extern PyMethodDef *donemethods(void);
+
+/*----- Mapping methods ---------------------------------------------------*/
+
+#define GMAP_METH(func, doc) { #func, gmapmeth_##func, METH_VARARGS, doc },
+#define GMAP_KWMETH(func, doc)                                         \
+  { #func, (PyCFunction)gmapmeth_##func, METH_VARARGS|METH_KEYWORDS, doc },
+#define GMAP_METHDECL(func, doc)                                       \
+  extern PyObject *gmapmeth_##func(PyObject *, PyObject *);
+#define GMAP_KWMETHDECL(func, doc)                                     \
+  extern PyObject *gmapmeth_##func(PyObject *, PyObject *, PyObject *);
+
+#define GMAP_DOROMETHODS(METH, KWMETH)                                 \
+  METH (has_key,       "D.has_key(KEY) -> BOOL")                       \
+  METH (keys,          "D.keys() -> LIST")                             \
+  METH (values,        "D.values() -> LIST")                           \
+  METH (items,         "D.items() -> LIST")                            \
+  METH (iterkeys,      "D.iterkeys() -> ITER")                         \
+  METH (itervalues,    "D.itervalues() -> ITER")                       \
+  METH (iteritems,     "D.iteritems() -> ITER")                        \
+  KWMETH(get,          "D.get(KEY, [default = None]) -> VALUE")
+
+#define GMAP_DOMETHODS(METH, KWMETH)                                   \
+  GMAP_DOROMETHODS(METH, KWMETH)                                       \
+  METH (clear,         "D.clear()")                                    \
+  KWMETH(setdefault,   "D.setdefault(K, [default = None]) -> VALUE")   \
+  KWMETH(pop,          "D.pop(KEY, [default = <error>]) -> VALUE")     \
+  METH (popitem,       "D.popitem() -> (KEY, VALUE)")                  \
+  METH (update,        "D.update(MAP)")
+
+GMAP_DOMETHODS(GMAP_METHDECL, GMAP_KWMETHDECL)
+#define GMAP_ROMETHODS GMAP_DOROMETHODS(GMAP_METH, GMAP_KWMETH)
+#define GMAP_METHODS GMAP_DOMETHODS(GMAP_METH, GMAP_KWMETH)
+extern Py_ssize_t gmap_pysize(PyObject *);
+extern PySequenceMethods gmap_pysequence;
+extern PyMethodDef gmap_pymethods[];
+
 /*----- Bytestrings -------------------------------------------------------*/
 
-PyTypeObject *bytestring_pyobj;
 PyObject *bytestring_pywrap(const void *, size_t);
 PyObject *bytestring_pywrapbuf(buf *);
 
@@ -204,8 +358,8 @@ extern PyTypeObject *gf_pytype;
 #define MP_PYCHECK(o) PyObject_TypeCheck((o), mp_pytype)
 #define GF_PYCHECK(o) PyObject_TypeCheck((o), gf_pytype)
 
-extern mp *mp_frompylong(PyLongObject *);
-extern PyLongObject *mp_topylong(mp *);
+extern mp *mp_frompylong(PyObject *);
+extern PyObject *mp_topylong(mp *);
 extern mp *tomp(PyObject *);
 extern mp *getmp(PyObject *);
 extern int convmp(PyObject *, void *);
@@ -213,33 +367,19 @@ extern mp *getgf(PyObject *);
 extern int convgf(PyObject *, void *);
 extern PyObject *mp_pywrap(mp *);
 extern PyObject *gf_pywrap(mp *);
+extern long mphash(mp *);
 extern mp *mp_frompyobject(PyObject *, int);
 extern PyObject *mp_topystring(mp *, int,
                               const char *, const char *, const char *);
-extern int mp_tolong_checked(mp *, long *);
+extern int mp_tolong_checked(mp *, long *, int);
 
 /*----- Abstract fields ---------------------------------------------------*/
 
 typedef struct field_pyobj {
-  PyTypeObject ty;
+  PyHeapTypeObject ty;
   field *f;
 } field_pyobj;
 
-extern PyTypeObject *fe_pytype;
-#define FE_PYCHECK(o) PyObject_TypeCheck((o), fe_pytype)
-#define FE_F(o) (((fe_pyobj *)(o))->f)
-#define FE_FOBJ(o) ((PyObject *)(o)->ob_type)
-#define FE_X(o) (((fe_pyobj *)(o))->x)
-extern PyObject *fe_pywrap(PyObject *, mp *);
-extern mp *getfe(field *, PyObject *);
-
-typedef struct fe_pyobj {
-  PyObject_HEAD
-  field *f;
-  PyObject *fobj; /* to keep it alive */
-  mp *x;
-} fe_pyobj;
-      
 extern PyTypeObject *field_pytype;
 extern PyTypeObject *primefield_pytype;
 extern PyTypeObject *niceprimefield_pytype;
@@ -251,8 +391,38 @@ extern PyTypeObject *binnormfield_pytype;
 extern PyObject *field_pywrap(field *);
 extern field *field_copy(field *);
 
+typedef struct fe_pyobj {
+  PyObject_HEAD
+  field *f;
+  mp *x;
+} fe_pyobj;
+
+extern PyTypeObject *fe_pytype;
+#define FE_PYCHECK(o) PyObject_TypeCheck((o), fe_pytype)
+#define FE_F(o) (((fe_pyobj *)(o))->f)
+#define FE_FOBJ(o) ((PyObject *)(o)->ob_type)
+#define FE_X(o) (((fe_pyobj *)(o))->x)
+extern PyObject *fe_pywrap(PyObject *, mp *);
+
 /*----- Elliptic curves ---------------------------------------------------*/
 
+typedef struct eccurve_pyobj {
+  PyHeapTypeObject ty;
+  ec_curve *c;
+  PyObject *fobj;
+} eccurve_pyobj;
+
+extern PyTypeObject *eccurve_pytype;
+extern PyTypeObject *ecprimecurve_pytype;
+extern PyTypeObject *ecprimeprojcurve_pytype;
+extern PyTypeObject *ecbincurve_pytype;
+extern PyTypeObject *ecbinprojcurve_pytype;
+#define ECCURVE_PYCHECK(o) PyObject_TypeCheck((o), eccurve_pytype)
+#define ECCURVE_C(o) (((eccurve_pyobj *)(o))->c)
+#define ECCURVE_FOBJ(o) (((eccurve_pyobj *)(o))->fobj)
+extern PyObject *eccurve_pywrap(PyObject *, ec_curve *);
+extern ec_curve *eccurve_copy(ec_curve *);
+
 typedef struct ecpt_pyobj {
   PyObject_HEAD
   ec_curve *c;
@@ -271,31 +441,14 @@ extern PyObject *ecpt_pywrapout(void *, ec *);
 extern int toecpt(ec_curve *, ec *, PyObject *);
 extern int getecpt(ec_curve *, ec *, PyObject *);
 extern void getecptout(ec *, PyObject *);
-extern int convec(PyObject *, void *);
-
-typedef struct eccurve_pyobj {
-  PyTypeObject ty;
-  ec_curve *c;
-  PyObject *fobj;
-} eccurve_pyobj;
-
-extern PyTypeObject *eccurve_pytype;
-extern PyTypeObject *ecprimecurve_pytype;
-extern PyTypeObject *ecprimeprojcurve_pytype;
-extern PyTypeObject *ecbincurve_pytype;
-extern PyTypeObject *ecbinprojcurve_pytype;
-#define ECCURVE_PYCHECK(o) PyObject_TypeCheck((o), eccurve_pytype)
-#define ECCURVE_C(o) (((eccurve_pyobj *)(o))->c)
-#define ECCURVE_FOBJ(o) (((eccurve_pyobj *)(o))->fobj)
-extern PyObject *eccurve_pywrap(PyObject *, ec_curve *);
-extern ec_curve *eccurve_copy(ec_curve *);
+extern int convecpt(PyObject *, void *);
 
 typedef struct ecinfo_pyobj {
   PyObject_HEAD
   ec_info ei;
   PyObject *cobj;
 } ecinfo_pyobj;
-      
+
 extern PyTypeObject *ecinfo_pytype;
 #define ECINFO_PYCHECK(o) PyObject_TypeCheck((o), ecinfo_pytype)
 #define ECINFO_EI(o) (&((ecinfo_pyobj *)(o))->ei)
@@ -305,15 +458,6 @@ extern PyObject *ecinfo_pywrap(ec_info *);
 
 /*----- Cyclic groups -----------------------------------------------------*/
 
-typedef struct fginfo_pyobj {
-  PyObject_HEAD
-  gprime_param dp;
-} fginfo_pyobj;
-
-PyTypeObject *fginfo_pytype, *dhinfo_pytype, *bindhinfo_pytype;
-#define FGINFO_DP(fg) (&((fginfo_pyobj *)(fg))->dp)
-PyObject *fginfo_pywrap(gprime_param *, PyTypeObject *);
-
 typedef struct ge_pyobj {
   PyObject_HEAD
   ge *x;
@@ -328,12 +472,11 @@ extern PyTypeObject *ge_pytype;
 extern PyObject *ge_pywrap(PyObject *, ge *);
 
 typedef struct group_pyobj {
-  PyTypeObject ty;
+  PyHeapTypeObject ty;
   group *g;
 } group_pyobj;
 
 extern PyTypeObject *group_pytype;
-extern PyTypeObject *primegroup_pytype, *bingroup_pytype, *ecgroup_pytype;
 #define GROUP_G(o) (((group_pyobj *)(o))->g)
 extern PyObject *group_pywrap(group *);
 extern group *group_copy(group *);
@@ -348,9 +491,7 @@ typedef struct grand_pyobj {
   grand *r;
 } grand_pyobj;
 
-extern PyTypeObject *grand_pytype, *truerand_pytype;
-extern PyTypeObject *lcrand_pytype,* fibrand_pytype;
-extern PyTypeObject *dsarand_pytype, *bbs_pytype;
+extern PyTypeObject *grand_pytype;
 extern PyObject *rand_pyobj;
 #define GRAND_PYCHECK(o) PyObject_TypeCheck((o), grand_pytype)
 #define GRAND_F(o) (((grand_pyobj *)(o))->f)
@@ -358,114 +499,30 @@ extern PyObject *rand_pyobj;
 extern PyObject *grand_pywrap(grand *, unsigned);
 extern int convgrand(PyObject *, void *);
 
-/*----- Key sizes ---------------------------------------------------------*/
-
-typedef struct keysz_pyobj {
-  PyObject_HEAD
-  int dfl;
-} keysz_pyobj;
-
-typedef struct keyszrange_pyobj {
-  PyObject_HEAD
-  int dfl;
-  int min, max, mod;
-} keyszrange_pyobj;
-
-typedef struct keyszset_pyobj {
-  PyObject_HEAD
-  int dfl;
-  PyObject *set;
-} keyszset_pyobj;
-
-#define KEYSZ_PYCHECK(o) PyObject_TypeCheck((o), keysz_pytype)
-extern PyObject *keysz_pywrap(const octet *);
-
 /*----- Symmetric cryptography --------------------------------------------*/
 
-typedef struct gccipher_pyobj {
-  PyTypeObject ty;
-  gccipher *cc;
-} gccipher_pyobj;
+extern PyObject *keysz_pywrap(const octet *);
 
-extern PyTypeObject *gccipher_pytype;
-#define GCCIPHER_PYCHECK(o) PyObject_TypeCheck((o), gccipher_pytype)
-#define GCCIPHER_CC(o) (((gccipher_pyobj *)(o))->cc)
-#define GCCIPHER_F(o) (((gccipher_pyobj *)(o))->f)
-extern PyObject *gccipher_pywrap(gccipher *);
 extern int convgccipher(PyObject *, void *);
-extern int convgcipher(PyObject *, void *);
-
-typedef struct gcipher_pyobj {
-  PyObject_HEAD
-  unsigned f;
-  gcipher *c;
-} gcipher_pyobj;
-
-extern PyTypeObject *gcipher_pytype;
-#define GCIPHER_PYCHECK(o) PyObject_TypeCheck((o), gcipher_pytype)
-#define GCIPHER_C(o) (((gcipher_pyobj *)(o))->c)
-#define GCIPHER_F(o) (((gcipher_pyobj *)(o))->f)
-extern PyObject *gcipher_pywrap(PyObject *, gcipher *, unsigned);
-extern int convgcipher(PyObject *, void *);
+extern PyObject *gccipher_pywrap(gccipher *);
 
 typedef struct gchash_pyobj {
-  PyTypeObject ty;
+  PyHeapTypeObject ty;
   gchash *ch;
 } gchash_pyobj;
 
 extern PyTypeObject *gchash_pytype;
+extern PyObject *sha_pyobj, *has160_pyobj;
 #define GCHASH_PYCHECK(o) PyObject_TypeCheck((o), gchash_pytype)
 #define GCHASH_CH(o) (((gchash_pyobj *)(o))->ch)
-#define GCHASH_F(o) (((gchash_pyobj *)(o))->f)
-extern PyObject *gchash_pywrap(gchash *);
+extern PyObject *ghash_pywrap(PyObject *, ghash *);
 extern int convgchash(PyObject *, void *);
-
-typedef struct ghash_pyobj {
-  PyObject_HEAD
-  unsigned f;
-  ghash *h;
-} ghash_pyobj;
-
-extern PyTypeObject *ghash_pytype, *gmhash_pytype;
-extern PyObject *sha_pyobj, *has160_pyobj;
-#define GHASH_PYCHECK(o) PyObject_TypeCheck((o), ghash_pytype)
-#define GHASH_H(o) (((ghash_pyobj *)(o))->h)
-#define GHASH_F(o) (((ghash_pyobj *)(o))->f)
-extern PyObject *ghash_pywrap(PyObject *, ghash *, unsigned);
 extern int convghash(PyObject *, void *);
-extern int convgmhash(PyObject *, void *);
-
-typedef struct gcmac_pyobj {
-  PyTypeObject ty;
-  gcmac *cm;
-} gcmac_pyobj;
-
-extern PyTypeObject *gcmac_pytype;
-#define GCMAC_PYCHECK(o) PyObject_TypeCheck((o), gcmac_pytype)
-#define GCMAC_CM(o) (((gcmac_pyobj *)(o))->cm)
-#define GCMAC_F(o) (((gcmac_pyobj *)(o))->f)
-extern PyObject *gcmac_pywrap(gcmac *);
-extern int convgcmac(PyObject *, void *);
 
-typedef struct gmac_pyobj {
-  PyTypeObject ty;
-  unsigned f;
-  gmac *m;
-  PyObject *nameobj;
-} gmac_pyobj;
-
-extern PyTypeObject *gmac_pytype;
-#define GMAC_PYCHECK(o) PyObject_TypeCheck((o), gmac_pytype)
-#define GMAC_M(o) (((gmac_pyobj *)(o))->m)
-#define GMAC_NAMEOBJ(o) (((gmac_pyobj *)(o))->nameobj)
-#define GMAC_F(o) (((gmac_pyobj *)(o))->f)
-extern PyObject *gmac_pywrap(PyObject *, gmac *, unsigned);
-extern int convgmac(PyObject *, void *);
-
-/*----- Public key crypto -------------------------------------------------*/
+extern int convgcmac(PyObject *, void *);
 
 /*----- Key generation ----------------------------------------------------*/
-    
+
 typedef struct pfilt_pyobj {
   PyObject_HEAD
   pfilt f;
@@ -488,31 +545,15 @@ extern PyTypeObject *pgev_pytype;
 #define PGEV_PYCHECK(o) PyObject_TypeCheck(o, pgev_pytype)
 #define PGEV_PG(o) (&((pgev_pyobj *)(o))->pg)
 
-extern int convpgev(PyObject *, void *);
-extern void droppgev(pgev *);
-extern void pgenerr(void);
-
-/*----- Core utility functions --------------------------------------------*/
-
-extern PyObject *mexp_common(PyObject *, PyObject *, size_t,
-                            PyObject *(*id)(PyObject *),
-                            int (*fill)(void *, PyObject *,
-                                        PyObject *, PyObject *),
-                            PyObject *(*exp)(PyObject *, void *, int),
-                            void (*drop)(void *));
+typedef struct pypgev {
+  pgev ev;
+  PyObject *obj;
+  struct excinfo *exc;
+} pypgev;
 
-extern int convulong(PyObject *, void *);
-extern int convu32(PyObject *, void *);
-extern int convmpw(PyObject *, void *);
-extern int convuint(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 *getu32(uint32);
-extern void *newtype(PyTypeObject *, const PyTypeObject *);
-extern PyTypeObject *inittype(PyTypeObject *);
-extern void addmethods(const PyMethodDef *);
+extern int convpgev(PyObject *, void *);
+extern void droppgev(pypgev *);
+extern void pgenerr(struct excinfo *exc);
 
 /*----- That's all, folks -------------------------------------------------*/