catacomb.c, util.c: Export `modname' and set it in main entry point.
[pyke] / catacomb-python.h
CommitLineData
b6a86d2e 1/* -*-c-*-
2 *
b6a86d2e 3 * Definitions for Catacomb bindings
4 *
5 * (c) 2004 Straylight/Edgeware
6 */
7
0b1eafbf 8/*----- Licensing notice --------------------------------------------------*
b6a86d2e 9 *
10 * This file is part of the Python interface to Catacomb.
11 *
12 * Catacomb/Python is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
0b1eafbf 16 *
b6a86d2e 17 * Catacomb/Python is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
0b1eafbf 21 *
b6a86d2e 22 * You should have received a copy of the GNU General Public License
23 * along with Catacomb/Python; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26
27#ifndef CATACOMB_PYTHON_H
28#define CATACOMB_PYTHON_H
29
30#ifdef __cplusplus
31 extern "C" {
32#endif
33
34/*----- Header files ------------------------------------------------------*/
35
ad84d8c2
MW
36#define PY_SSIZE_T_CLEAN
37
b6a86d2e 38#include <Python.h>
39#include <longintrepr.h>
40#include <structmember.h>
41
42#include <mLib/darray.h>
43#include <mLib/dstr.h>
44#include <mLib/macros.h>
73a712fa 45#include <mLib/quis.h>
b06387d2 46#include <mLib/unihash.h>
b6a86d2e 47
48#include <catacomb/buf.h>
54ecf9dd 49#include <catacomb/ct.h>
b6a86d2e 50
51#include <catacomb/grand.h>
52#include <catacomb/rand.h>
53#include <catacomb/noise.h>
54#include <catacomb/bbs.h>
55#include <catacomb/mprand.h>
56#include <catacomb/lcrand.h>
57#include <catacomb/fibrand.h>
58#include <catacomb/dsarand.h>
59#include <catacomb/sslprf.h>
60#include <catacomb/tlsprf.h>
62058916 61#include <catacomb/blkc.h>
b6a86d2e 62
63#include <catacomb/gcipher.h>
54ae5879 64#include <catacomb/gaead.h>
b6a86d2e 65#include <catacomb/ghash.h>
66#include <catacomb/gmac.h>
67#include <catacomb/md5.h>
68#include <catacomb/md5-hmac.h>
2ad160b1 69#include <catacomb/poly1305.h>
b6a86d2e 70#include <catacomb/sha.h>
71#include <catacomb/sha-mgf.h>
72#include <catacomb/sha-hmac.h>
f85a7079 73#include <catacomb/keccak1600.h>
b75462e8 74#include <catacomb/sha3.h>
b6a86d2e 75
76#include <catacomb/mp.h>
77#include <catacomb/mpint.h>
78#include <catacomb/mpmul.h>
79#include <catacomb/mpcrt.h>
80#include <catacomb/mpmont.h>
81#include <catacomb/mpbarrett.h>
82#include <catacomb/mpreduce.h>
9c034c56 83#include <catacomb/mp-fibonacci.h>
b6a86d2e 84
85#include <catacomb/pgen.h>
86#include <catacomb/pfilt.h>
87#include <catacomb/strongprime.h>
88#include <catacomb/limlee.h>
89#include <catacomb/dh.h>
90#include <catacomb/ptab.h>
91#include <catacomb/bintab.h>
92#include <catacomb/dsa.h>
d223dc6b 93#include <catacomb/x25519.h>
51f4de84 94#include <catacomb/x448.h>
70ed69c4 95#include <catacomb/ed25519.h>
aa53a95f 96#include <catacomb/ed448.h>
b6a86d2e 97
98#include <catacomb/gf.h>
99#include <catacomb/gfreduce.h>
100#include <catacomb/gfn.h>
101
102#include <catacomb/field.h>
103#include <catacomb/field-guts.h>
104
105#include <catacomb/ec.h>
106#include <catacomb/ec-raw.h>
107#include <catacomb/ectab.h>
108
109#include <catacomb/group.h>
110#include <catacomb/group-guts.h>
111
112#include <catacomb/gdsa.h>
113#include <catacomb/gkcdsa.h>
114#include <catacomb/rsa.h>
115
116#include <catacomb/key.h>
117#include <catacomb/passphrase.h>
118#include <catacomb/pixie.h>
119
73a712fa 120#include <catacomb/share.h>
121#include <catacomb/gfshare.h>
122
26a7f37a
MW
123/*----- Other preliminaries -----------------------------------------------*/
124
125#define GOBBLE_SEMI extern int notexist
126#if defined(__GNUC__) && defined(__ELF__)
127# define PRIVATE_SYMBOLS _Pragma("GCC visibility push(hidden)") GOBBLE_SEMI
128# define PUBLIC_SYMBOLS _Pragma("GCC visibility pop") GOBBLE_SEMI
129# define EXPORT __attribute__((__visibility__("default")))
130#else
131# define PRIVATE_SYMBOLS GOBBLE_SEMI
132# define PUBLIC_SYMBOLS GOBBLE_SEMI
133# define EXPORT
134#endif
135
136PRIVATE_SYMBOLS;
137
b6a86d2e 138/*----- Utility macros ----------------------------------------------------*/
139
140#define RETURN_OBJ(obj) do { Py_INCREF(obj); return (obj); } while (0)
141#define RETURN_NONE RETURN_OBJ(Py_None)
142#define RETURN_NOTIMPL RETURN_OBJ(Py_NotImplemented)
143#define RETURN_TRUE RETURN_OBJ(Py_True)
144#define RETURN_FALSE RETURN_OBJ(Py_False)
145#define RETURN_ME RETURN_OBJ(me)
146
147#define EXCERR(exc, str) do { \
148 PyErr_SetString(exc, str); \
149 goto end; \
150} while (0)
151#define VALERR(str) EXCERR(PyExc_ValueError, str)
c6b05f1f 152#define OVFERR(str) EXCERR(PyExc_OverflowError, str)
b6a86d2e 153#define TYERR(str) EXCERR(PyExc_TypeError, str)
ca473903 154#define IXERR(str) EXCERR(PyExc_IndexError, str)
b6a86d2e 155#define ZDIVERR(str) EXCERR(PyExc_ZeroDivisionError, str)
b6a86d2e 156#define SYSERR(str) EXCERR(PyExc_SystemError, str)
68ec53f3 157#define NIERR(str) EXCERR(PyExc_NotImplementedError, str)
73a712fa 158#define INDEXERR(idx) do { \
159 PyErr_SetObject(PyExc_KeyError, idx); \
160 goto end; \
161} while (0)
b6a86d2e 162#define OSERR(name) do { \
163 PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); \
164 goto end; \
165} while (0)
87aa2e3c 166#define PGENERR(exc) do { pgenerr(exc); goto end; } while (0)
b6a86d2e 167
168#define CONVFUNC(ty, cty, ext) \
169 int conv##ty(PyObject *o, void *p) \
170 { \
171 if (!PyObject_TypeCheck(o, ty##_pytype)) \
172 TYERR("wanted a " #ty); \
173 *(cty *)p = ext(o); \
174 return (1); \
175 end: \
176 return (0); \
177 }
178
179#define root_pytype 0
180#define type_pytype &PyType_Type
017d5f65 181#define INITTYPE_META(ty, base, meta) do { \
b6a86d2e 182 ty##_pytype_skel.tp_base = base##_pytype; \
017d5f65 183 ty##_pytype = inittype(&ty##_pytype_skel, meta##_pytype); \
b6a86d2e 184} while (0)
017d5f65 185#define INITTYPE(ty, base) INITTYPE_META(ty, base, type)
b6a86d2e 186
87aa2e3c 187extern PyObject *home_module;
c6a36308 188extern PyObject *modname;
87aa2e3c
MW
189
190#define INSERT(name, ob) do { \
b6a86d2e 191 PyObject *_o = (PyObject *)(ob); \
0b1eafbf 192 Py_INCREF(_o); \
b6a86d2e 193 PyModule_AddObject(mod, name, _o); \
194} while (0)
195
73a712fa 196#define INSEXC(name, var, base, meth) \
197 INSERT(name, var = mkexc(mod, base, name, meth))
198
b6a86d2e 199#define METH(func, doc) \
200 { #func, METHNAME(func), METH_VARARGS, doc },
201#define KWMETH(func, doc) \
202 { #func, (PyCFunction)METHNAME(func), \
203 METH_VARARGS | METH_KEYWORDS, doc },
204
205#define GET(func, doc) \
206 { #func, GETSETNAME(get, func), 0, doc },
207#define GETSET(func, doc) \
208 { #func, GETSETNAME(get, func), GETSETNAME(set, func), doc },
209
210#define MEMBER(name, ty, f, doc) \
211 { #name, ty, offsetof(MEMBERSTRUCT, name), f, doc },
212
73a712fa 213#define MODULES(_) \
dfe0a897 214 _(util) \
73a712fa 215 _(bytestring) _(buffer) \
216 _(rand) _(algorithms) _(pubkey) _(pgen) \
217 _(mp) _(field) _(ec) _(group) \
dfe0a897 218 _(passphrase) _(share) _(key)
b6a86d2e 219#define DOMODINIT(m) m##_pyinit();
220#define DOMODINSERT(m) m##_pyinsert(mod);
221#define INIT_MODULES do { MODULES(DOMODINIT) } while (0)
222#define INSERT_MODULES do { MODULES(DOMODINSERT) } while (0)
223
224#define DO(m) \
225 extern void m##_pyinit(void); \
226 extern void m##_pyinsert(PyObject *);
227MODULES(DO)
228#undef DO
229
ba45a729 230#define FREEOBJ(obj) \
231 (((PyObject *)(obj))->ob_type->tp_free((PyObject *)(obj)))
232
68ec53f3
MW
233#define GEN(func, base) \
234 static PyObject *func(void) \
235 { \
236 PyObject *d = PyDict_New(); \
237 PyObject *o; \
238 int i; \
239 \
240 for (i = 0; g##base##tab[i]; i++) { \
241 o = gc##base##_pywrap((/*unconst*/ gc##base *)g##base##tab[i]); \
242 PyDict_SetItemString(d, \
243 (/*unconst*/ char *)g##base##tab[i]->name, \
244 o); \
245 Py_DECREF(o); \
246 } \
247 return (d); \
248 }
249
0fed227d
MW
250#define KWLIST (/*unconst*/ char **)kwlist
251
2ec562f1
MW
252struct nameval { const char *name; unsigned f; unsigned long value; };
253#define CF_SIGNED 1u
68ec53f3
MW
254extern void setconstants(PyObject *, const struct nameval *);
255
256extern PyObject *mexp_common(PyObject *, PyObject *, size_t,
257 PyObject *(*id)(PyObject *),
258 int (*fill)(void *, PyObject *,
259 PyObject *, PyObject *),
260 PyObject *(*exp)(PyObject *, void *, int),
261 void (*drop)(void *));
262
263extern int convulong(PyObject *, void *);
264#define DECL_CONVU_(n) extern int convu##n(PyObject *, void *);
265DOUINTSZ(DECL_CONVU_)
266extern int convmpw(PyObject *, void *);
267extern int convuint(PyObject *, void *);
1b6734b6 268extern int convk64(PyObject *, void *);
68ec53f3
MW
269extern int convszt(PyObject *, void *);
270extern int convbool(PyObject *, void *);
271extern PyObject *abstract_pynew(PyTypeObject *, PyObject *, PyObject *);
272extern PyObject *getbool(int);
1e082a86 273extern PyObject *getulong(unsigned long);
1b6734b6 274extern PyObject *getk64(kludge64);
68ec53f3
MW
275extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *);
276
87aa2e3c
MW
277struct excinfo { PyObject *ty, *val, *tb; };
278#define EXCINFO_INIT { 0, 0, 0 }
279
d2421f3c 280extern PyObject *mkexc(PyObject *, PyObject *, const char *, PyMethodDef *);
87aa2e3c
MW
281#define INIT_EXCINFO(exc) do { \
282 struct excinfo *_exc = (exc); _exc->ty = _exc->val = _exc->tb = 0; \
283} while (0)
284#define RELEASE_EXCINFO(exc) do { \
285 struct excinfo *_exc = (exc); \
286 Py_XDECREF(_exc->ty); _exc->ty = 0; \
287 Py_XDECREF(_exc->val); _exc->val = 0; \
288 Py_XDECREF(_exc->tb); _exc->tb = 0; \
289} while (0)
290#define STASH_EXCINFO(exc) do { \
291 struct excinfo *_exc = (exc); \
292 PyErr_Fetch(&_exc->ty, &_exc->val, &_exc->tb); \
293 PyErr_NormalizeException(&_exc->ty, &_exc->val, &_exc->tb); \
294} while (0)
295#define RESTORE_EXCINFO(exc) do { \
296 struct excinfo *_exc = (exc); \
297 PyErr_Restore(_exc->ty, _exc->val, _exc->tb); \
298 _exc->ty = _exc->val = _exc->tb = 0; \
299} while (0)
300extern void report_lost_exception(struct excinfo *, const char *, ...);
301extern void report_lost_exception_v(struct excinfo *, const char *, va_list);
302extern void stash_exception(struct excinfo *, const char *, ...);
303extern void restore_exception(struct excinfo *, const char *, ...);
304
0156e402 305extern void typeready(PyTypeObject *);
017d5f65 306extern PyTypeObject *inittype(PyTypeObject *, PyTypeObject *);
68ec53f3
MW
307extern void addmethods(const PyMethodDef *);
308extern PyMethodDef *donemethods(void);
309
310/*----- Mapping methods ---------------------------------------------------*/
311
312#define GMAP_METH(func, doc) { #func, gmapmeth_##func, METH_VARARGS, doc },
313#define GMAP_KWMETH(func, doc) \
314 { #func, (PyCFunction)gmapmeth_##func, METH_VARARGS|METH_KEYWORDS, doc },
315#define GMAP_METHDECL(func, doc) \
316 extern PyObject *gmapmeth_##func(PyObject *, PyObject *);
317#define GMAP_KWMETHDECL(func, doc) \
318 extern PyObject *gmapmeth_##func(PyObject *, PyObject *, PyObject *);
319
2a509510 320#define GMAP_DOROMETHODS(METH, KWMETH) \
68ec53f3
MW
321 METH (has_key, "D.has_key(KEY) -> BOOL") \
322 METH (keys, "D.keys() -> LIST") \
323 METH (values, "D.values() -> LIST") \
324 METH (items, "D.items() -> LIST") \
325 METH (iterkeys, "D.iterkeys() -> ITER") \
326 METH (itervalues, "D.itervalues() -> ITER") \
0b1eafbf 327 METH (iteritems, "D.iteritems() -> ITER") \
68ec53f3 328 KWMETH(get, "D.get(KEY, [default = None]) -> VALUE") \
2a509510
MW
329
330#define GMAP_DOMETHODS(METH, KWMETH) \
331 GMAP_DOROMETHODS(METH, KWMETH) \
332 METH (clear, "D.clear()") \
68ec53f3
MW
333 KWMETH(setdefault, "D.setdefault(K, [default = None]) -> VALUE") \
334 KWMETH(pop, "D.pop(KEY, [default = <error>]) -> VALUE") \
335 METH (popitem, "D.popitem() -> (KEY, VALUE)") \
336 METH (update, "D.update(MAP)")
337
338GMAP_DOMETHODS(GMAP_METHDECL, GMAP_KWMETHDECL)
2a509510 339#define GMAP_ROMETHODS GMAP_DOROMETHODS(GMAP_METH, GMAP_KWMETH)
68ec53f3 340#define GMAP_METHODS GMAP_DOMETHODS(GMAP_METH, GMAP_KWMETH)
9d73ed80 341extern Py_ssize_t gmap_pysize(PyObject *);
68ec53f3
MW
342extern PySequenceMethods gmap_pysequence;
343extern PyMethodDef gmap_pymethods[];
344
b6a86d2e 345/*----- Bytestrings -------------------------------------------------------*/
346
b6a86d2e 347PyObject *bytestring_pywrap(const void *, size_t);
348PyObject *bytestring_pywrapbuf(buf *);
349
350/*----- Multiprecision arithmetic -----------------------------------------*/
351
352typedef struct mp_pyobj {
353 PyObject_HEAD
354 mp *x;
355} mp_pyobj;
356
357extern PyTypeObject *mp_pytype;
358extern PyTypeObject *gf_pytype;
359#define MP_X(o) (((mp_pyobj *)(o))->x)
360#define MP_PYCHECK(o) PyObject_TypeCheck((o), mp_pytype)
361#define GF_PYCHECK(o) PyObject_TypeCheck((o), gf_pytype)
362
8d57d6ea
MW
363extern mp *mp_frompylong(PyObject *);
364extern PyObject *mp_topylong(mp *);
b6a86d2e 365extern mp *tomp(PyObject *);
366extern mp *getmp(PyObject *);
367extern int convmp(PyObject *, void *);
368extern mp *getgf(PyObject *);
369extern int convgf(PyObject *, void *);
370extern PyObject *mp_pywrap(mp *);
371extern PyObject *gf_pywrap(mp *);
917dbf4b 372extern long mphash(mp *);
b6a86d2e 373extern mp *mp_frompyobject(PyObject *, int);
374extern PyObject *mp_topystring(mp *, int,
375 const char *, const char *, const char *);
41e8ab3d 376extern int mp_tolong_checked(mp *, long *, int);
b6a86d2e 377
378/*----- Abstract fields ---------------------------------------------------*/
379
380typedef struct field_pyobj {
f0526039 381 PyHeapTypeObject ty;
b6a86d2e 382 field *f;
383} field_pyobj;
384
b6a86d2e 385extern PyTypeObject *field_pytype;
386extern PyTypeObject *primefield_pytype;
387extern PyTypeObject *niceprimefield_pytype;
388extern PyTypeObject *binfield_pytype;
389extern PyTypeObject *binpolyfield_pytype;
390extern PyTypeObject *binnormfield_pytype;
391#define FIELD_PYCHECK(o) PyObject_TypeCheck((o), field_pytype)
392#define FIELD_F(o) (((field_pyobj *)(o))->f)
393extern PyObject *field_pywrap(field *);
394extern field *field_copy(field *);
395
8eeb5aee
MW
396typedef struct fe_pyobj {
397 PyObject_HEAD
398 field *f;
399 mp *x;
400} fe_pyobj;
401
402extern PyTypeObject *fe_pytype;
403#define FE_PYCHECK(o) PyObject_TypeCheck((o), fe_pytype)
404#define FE_F(o) (((fe_pyobj *)(o))->f)
405#define FE_FOBJ(o) ((PyObject *)(o)->ob_type)
406#define FE_X(o) (((fe_pyobj *)(o))->x)
407extern PyObject *fe_pywrap(PyObject *, mp *);
408
b6a86d2e 409/*----- Elliptic curves ---------------------------------------------------*/
410
8eeb5aee
MW
411typedef struct eccurve_pyobj {
412 PyHeapTypeObject ty;
413 ec_curve *c;
414 PyObject *fobj;
415} eccurve_pyobj;
416
417extern PyTypeObject *eccurve_pytype;
418extern PyTypeObject *ecprimecurve_pytype;
419extern PyTypeObject *ecprimeprojcurve_pytype;
420extern PyTypeObject *ecbincurve_pytype;
421extern PyTypeObject *ecbinprojcurve_pytype;
422#define ECCURVE_PYCHECK(o) PyObject_TypeCheck((o), eccurve_pytype)
423#define ECCURVE_C(o) (((eccurve_pyobj *)(o))->c)
424#define ECCURVE_FOBJ(o) (((eccurve_pyobj *)(o))->fobj)
425extern PyObject *eccurve_pywrap(PyObject *, ec_curve *);
426extern ec_curve *eccurve_copy(ec_curve *);
427
b6a86d2e 428typedef struct ecpt_pyobj {
429 PyObject_HEAD
430 ec_curve *c;
431 ec p;
432} ecpt_pyobj;
433
434extern PyTypeObject *ecpt_pytype, *ecptcurve_pytype;
435#define ECPT_PYCHECK(o) PyObject_TypeCheck((o), ecpt_pytype)
436#define ECPTCURVE_PYCHECK(o) PyObject_TypeCheck((o), ecptcurve_pytype)
437#define ECPT_C(o) (((ecpt_pyobj *)(o))->c)
438#define ECPT_COBJ(o) ((PyObject *)(o)->ob_type)
439#define ECPT_FOBJ(o) ECCURVE_FOBJ(ECPT_COBJ((o)))
440#define ECPT_P(o) (&((ecpt_pyobj *)(o))->p)
441extern PyObject *ecpt_pywrap(PyObject *, ec *);
442extern PyObject *ecpt_pywrapout(void *, ec *);
443extern int toecpt(ec_curve *, ec *, PyObject *);
444extern int getecpt(ec_curve *, ec *, PyObject *);
445extern void getecptout(ec *, PyObject *);
73a712fa 446extern int convecpt(PyObject *, void *);
b6a86d2e 447
b6a86d2e 448typedef struct ecinfo_pyobj {
449 PyObject_HEAD
450 ec_info ei;
451 PyObject *cobj;
452} ecinfo_pyobj;
0b1eafbf 453
b6a86d2e 454extern PyTypeObject *ecinfo_pytype;
455#define ECINFO_PYCHECK(o) PyObject_TypeCheck((o), ecinfo_pytype)
456#define ECINFO_EI(o) (&((ecinfo_pyobj *)(o))->ei)
457#define ECINFO_COBJ(o) (((ecinfo_pyobj *)(o))->cobj)
458extern void ecinfo_copy(ec_info *, const ec_info *);
459extern PyObject *ecinfo_pywrap(ec_info *);
460
461/*----- Cyclic groups -----------------------------------------------------*/
462
b6a86d2e 463typedef struct ge_pyobj {
464 PyObject_HEAD
465 ge *x;
466 group *g;
467} ge_pyobj;
468
469extern PyTypeObject *ge_pytype;
470#define GE_PYCHECK(o) PyObject_TypeCheck((o), ge_pytype)
471#define GE_X(o) (((ge_pyobj *)(o))->x)
472#define GE_G(o) (((ge_pyobj *)(o))->g)
473#define GE_GOBJ(o) ((PyObject *)(group_pyobj *)(o)->ob_type)
474extern PyObject *ge_pywrap(PyObject *, ge *);
475
476typedef struct group_pyobj {
f0526039 477 PyHeapTypeObject ty;
b6a86d2e 478 group *g;
479} group_pyobj;
480
481extern PyTypeObject *group_pytype;
b6a86d2e 482#define GROUP_G(o) (((group_pyobj *)(o))->g)
483extern PyObject *group_pywrap(group *);
484extern group *group_copy(group *);
485
486/*----- Random number generators ------------------------------------------*/
487
488#define f_freeme 1u
489
490typedef struct grand_pyobj {
491 PyObject_HEAD
492 unsigned f;
493 grand *r;
494} grand_pyobj;
495
8eeb5aee 496extern PyTypeObject *grand_pytype;
b6a86d2e 497extern PyObject *rand_pyobj;
498#define GRAND_PYCHECK(o) PyObject_TypeCheck((o), grand_pytype)
499#define GRAND_F(o) (((grand_pyobj *)(o))->f)
500#define GRAND_R(o) (((grand_pyobj *)(o))->r)
501extern PyObject *grand_pywrap(grand *, unsigned);
502extern int convgrand(PyObject *, void *);
503
b6a86d2e 504/*----- Symmetric cryptography --------------------------------------------*/
505
8eeb5aee 506extern PyObject *keysz_pywrap(const octet *);
b6a86d2e 507
b6a86d2e 508extern int convgccipher(PyObject *, void *);
8eeb5aee 509extern PyObject *gccipher_pywrap(gccipher *);
54ae5879 510
b6a86d2e 511typedef struct gchash_pyobj {
f0526039 512 PyHeapTypeObject ty;
b6a86d2e 513 gchash *ch;
514} gchash_pyobj;
515
516extern PyTypeObject *gchash_pytype;
8eeb5aee 517extern PyObject *sha_pyobj, *has160_pyobj;
b6a86d2e 518#define GCHASH_PYCHECK(o) PyObject_TypeCheck((o), gchash_pytype)
519#define GCHASH_CH(o) (((gchash_pyobj *)(o))->ch)
5a5e08d9 520extern PyObject *ghash_pywrap(PyObject *, ghash *);
8eeb5aee 521extern int convgchash(PyObject *, void *);
b6a86d2e 522extern int convghash(PyObject *, void *);
b6a86d2e 523
b6a86d2e 524extern int convgcmac(PyObject *, void *);
525
b6a86d2e 526/*----- Key generation ----------------------------------------------------*/
0b1eafbf 527
b6a86d2e 528typedef struct pfilt_pyobj {
529 PyObject_HEAD
530 pfilt f;
531 int st;
532} pfilt_pyobj;
533
534extern PyTypeObject *pfilt_pytype;
535#define PFILT_PYCHECK(o) PyObject_TypeCheck(o, pfilt_pytype)
536#define PFILT_F(o) (&((pfilt_pyobj *)(o))->f)
537#define PFILT_ST(o) (((pfilt_pyobj *)(o))->st)
538
539typedef struct { pgen_proc *proc; void *ctx; } pgev;
540#define PGEV_HEAD PyObject_HEAD pgev pg;
541
542typedef struct pgev_pyobj {
543 PGEV_HEAD
544} pgev_pyobj;
545
546extern PyTypeObject *pgev_pytype;
547#define PGEV_PYCHECK(o) PyObject_TypeCheck(o, pgev_pytype)
548#define PGEV_PG(o) (&((pgev_pyobj *)(o))->pg)
549
87aa2e3c
MW
550typedef struct pypgev {
551 pgev ev;
552 PyObject *obj;
553 struct excinfo *exc;
554} pypgev;
555
b6a86d2e 556extern int convpgev(PyObject *, void *);
87aa2e3c
MW
557extern void droppgev(pypgev *);
558extern void pgenerr(struct excinfo *exc);
b6a86d2e 559
b6a86d2e 560/*----- That's all, folks -------------------------------------------------*/
561
562#ifdef __cplusplus
563 }
564#endif
565
566#endif