catacomb-python.h: Give up on Python versions prior to 2.5.
[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
MW
187extern PyObject *home_module;
188
189#define INSERT(name, ob) do { \
b6a86d2e 190 PyObject *_o = (PyObject *)(ob); \
0b1eafbf 191 Py_INCREF(_o); \
b6a86d2e 192 PyModule_AddObject(mod, name, _o); \
193} while (0)
194
73a712fa 195#define INSEXC(name, var, base, meth) \
196 INSERT(name, var = mkexc(mod, base, name, meth))
197
b6a86d2e 198#define METH(func, doc) \
199 { #func, METHNAME(func), METH_VARARGS, doc },
200#define KWMETH(func, doc) \
201 { #func, (PyCFunction)METHNAME(func), \
202 METH_VARARGS | METH_KEYWORDS, doc },
203
204#define GET(func, doc) \
205 { #func, GETSETNAME(get, func), 0, doc },
206#define GETSET(func, doc) \
207 { #func, GETSETNAME(get, func), GETSETNAME(set, func), doc },
208
209#define MEMBER(name, ty, f, doc) \
210 { #name, ty, offsetof(MEMBERSTRUCT, name), f, doc },
211
73a712fa 212#define MODULES(_) \
dfe0a897 213 _(util) \
73a712fa 214 _(bytestring) _(buffer) \
215 _(rand) _(algorithms) _(pubkey) _(pgen) \
216 _(mp) _(field) _(ec) _(group) \
dfe0a897 217 _(passphrase) _(share) _(key)
b6a86d2e 218#define DOMODINIT(m) m##_pyinit();
219#define DOMODINSERT(m) m##_pyinsert(mod);
220#define INIT_MODULES do { MODULES(DOMODINIT) } while (0)
221#define INSERT_MODULES do { MODULES(DOMODINSERT) } while (0)
222
223#define DO(m) \
224 extern void m##_pyinit(void); \
225 extern void m##_pyinsert(PyObject *);
226MODULES(DO)
227#undef DO
228
ba45a729 229#define FREEOBJ(obj) \
230 (((PyObject *)(obj))->ob_type->tp_free((PyObject *)(obj)))
231
68ec53f3
MW
232#define GEN(func, base) \
233 static PyObject *func(void) \
234 { \
235 PyObject *d = PyDict_New(); \
236 PyObject *o; \
237 int i; \
238 \
239 for (i = 0; g##base##tab[i]; i++) { \
240 o = gc##base##_pywrap((/*unconst*/ gc##base *)g##base##tab[i]); \
241 PyDict_SetItemString(d, \
242 (/*unconst*/ char *)g##base##tab[i]->name, \
243 o); \
244 Py_DECREF(o); \
245 } \
246 return (d); \
247 }
248
0fed227d
MW
249#define KWLIST (/*unconst*/ char **)kwlist
250
2ec562f1
MW
251struct nameval { const char *name; unsigned f; unsigned long value; };
252#define CF_SIGNED 1u
68ec53f3
MW
253extern void setconstants(PyObject *, const struct nameval *);
254
255extern PyObject *mexp_common(PyObject *, PyObject *, size_t,
256 PyObject *(*id)(PyObject *),
257 int (*fill)(void *, PyObject *,
258 PyObject *, PyObject *),
259 PyObject *(*exp)(PyObject *, void *, int),
260 void (*drop)(void *));
261
262extern int convulong(PyObject *, void *);
263#define DECL_CONVU_(n) extern int convu##n(PyObject *, void *);
264DOUINTSZ(DECL_CONVU_)
265extern int convmpw(PyObject *, void *);
266extern int convuint(PyObject *, void *);
1b6734b6 267extern int convk64(PyObject *, void *);
68ec53f3
MW
268extern int convszt(PyObject *, void *);
269extern int convbool(PyObject *, void *);
270extern PyObject *abstract_pynew(PyTypeObject *, PyObject *, PyObject *);
271extern PyObject *getbool(int);
1e082a86 272extern PyObject *getulong(unsigned long);
1b6734b6 273extern PyObject *getk64(kludge64);
68ec53f3
MW
274extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *);
275
87aa2e3c
MW
276struct excinfo { PyObject *ty, *val, *tb; };
277#define EXCINFO_INIT { 0, 0, 0 }
278
d2421f3c 279extern PyObject *mkexc(PyObject *, PyObject *, const char *, PyMethodDef *);
87aa2e3c
MW
280#define INIT_EXCINFO(exc) do { \
281 struct excinfo *_exc = (exc); _exc->ty = _exc->val = _exc->tb = 0; \
282} while (0)
283#define RELEASE_EXCINFO(exc) do { \
284 struct excinfo *_exc = (exc); \
285 Py_XDECREF(_exc->ty); _exc->ty = 0; \
286 Py_XDECREF(_exc->val); _exc->val = 0; \
287 Py_XDECREF(_exc->tb); _exc->tb = 0; \
288} while (0)
289#define STASH_EXCINFO(exc) do { \
290 struct excinfo *_exc = (exc); \
291 PyErr_Fetch(&_exc->ty, &_exc->val, &_exc->tb); \
292 PyErr_NormalizeException(&_exc->ty, &_exc->val, &_exc->tb); \
293} while (0)
294#define RESTORE_EXCINFO(exc) do { \
295 struct excinfo *_exc = (exc); \
296 PyErr_Restore(_exc->ty, _exc->val, _exc->tb); \
297 _exc->ty = _exc->val = _exc->tb = 0; \
298} while (0)
299extern void report_lost_exception(struct excinfo *, const char *, ...);
300extern void report_lost_exception_v(struct excinfo *, const char *, va_list);
301extern void stash_exception(struct excinfo *, const char *, ...);
302extern void restore_exception(struct excinfo *, const char *, ...);
303
0156e402 304extern void typeready(PyTypeObject *);
017d5f65 305extern PyTypeObject *inittype(PyTypeObject *, PyTypeObject *);
68ec53f3
MW
306extern void addmethods(const PyMethodDef *);
307extern PyMethodDef *donemethods(void);
308
309/*----- Mapping methods ---------------------------------------------------*/
310
311#define GMAP_METH(func, doc) { #func, gmapmeth_##func, METH_VARARGS, doc },
312#define GMAP_KWMETH(func, doc) \
313 { #func, (PyCFunction)gmapmeth_##func, METH_VARARGS|METH_KEYWORDS, doc },
314#define GMAP_METHDECL(func, doc) \
315 extern PyObject *gmapmeth_##func(PyObject *, PyObject *);
316#define GMAP_KWMETHDECL(func, doc) \
317 extern PyObject *gmapmeth_##func(PyObject *, PyObject *, PyObject *);
318
2a509510 319#define GMAP_DOROMETHODS(METH, KWMETH) \
68ec53f3
MW
320 METH (has_key, "D.has_key(KEY) -> BOOL") \
321 METH (keys, "D.keys() -> LIST") \
322 METH (values, "D.values() -> LIST") \
323 METH (items, "D.items() -> LIST") \
324 METH (iterkeys, "D.iterkeys() -> ITER") \
325 METH (itervalues, "D.itervalues() -> ITER") \
0b1eafbf 326 METH (iteritems, "D.iteritems() -> ITER") \
68ec53f3 327 KWMETH(get, "D.get(KEY, [default = None]) -> VALUE") \
2a509510
MW
328
329#define GMAP_DOMETHODS(METH, KWMETH) \
330 GMAP_DOROMETHODS(METH, KWMETH) \
331 METH (clear, "D.clear()") \
68ec53f3
MW
332 KWMETH(setdefault, "D.setdefault(K, [default = None]) -> VALUE") \
333 KWMETH(pop, "D.pop(KEY, [default = <error>]) -> VALUE") \
334 METH (popitem, "D.popitem() -> (KEY, VALUE)") \
335 METH (update, "D.update(MAP)")
336
337GMAP_DOMETHODS(GMAP_METHDECL, GMAP_KWMETHDECL)
2a509510 338#define GMAP_ROMETHODS GMAP_DOROMETHODS(GMAP_METH, GMAP_KWMETH)
68ec53f3 339#define GMAP_METHODS GMAP_DOMETHODS(GMAP_METH, GMAP_KWMETH)
9d73ed80 340extern Py_ssize_t gmap_pysize(PyObject *);
68ec53f3
MW
341extern PySequenceMethods gmap_pysequence;
342extern PyMethodDef gmap_pymethods[];
343
b6a86d2e 344/*----- Bytestrings -------------------------------------------------------*/
345
b6a86d2e 346PyObject *bytestring_pywrap(const void *, size_t);
347PyObject *bytestring_pywrapbuf(buf *);
348
349/*----- Multiprecision arithmetic -----------------------------------------*/
350
351typedef struct mp_pyobj {
352 PyObject_HEAD
353 mp *x;
354} mp_pyobj;
355
356extern PyTypeObject *mp_pytype;
357extern PyTypeObject *gf_pytype;
358#define MP_X(o) (((mp_pyobj *)(o))->x)
359#define MP_PYCHECK(o) PyObject_TypeCheck((o), mp_pytype)
360#define GF_PYCHECK(o) PyObject_TypeCheck((o), gf_pytype)
361
8d57d6ea
MW
362extern mp *mp_frompylong(PyObject *);
363extern PyObject *mp_topylong(mp *);
b6a86d2e 364extern mp *tomp(PyObject *);
365extern mp *getmp(PyObject *);
366extern int convmp(PyObject *, void *);
367extern mp *getgf(PyObject *);
368extern int convgf(PyObject *, void *);
369extern PyObject *mp_pywrap(mp *);
370extern PyObject *gf_pywrap(mp *);
917dbf4b 371extern long mphash(mp *);
b6a86d2e 372extern mp *mp_frompyobject(PyObject *, int);
373extern PyObject *mp_topystring(mp *, int,
374 const char *, const char *, const char *);
41e8ab3d 375extern int mp_tolong_checked(mp *, long *, int);
b6a86d2e 376
377/*----- Abstract fields ---------------------------------------------------*/
378
379typedef struct field_pyobj {
f0526039 380 PyHeapTypeObject ty;
b6a86d2e 381 field *f;
382} field_pyobj;
383
b6a86d2e 384extern PyTypeObject *field_pytype;
385extern PyTypeObject *primefield_pytype;
386extern PyTypeObject *niceprimefield_pytype;
387extern PyTypeObject *binfield_pytype;
388extern PyTypeObject *binpolyfield_pytype;
389extern PyTypeObject *binnormfield_pytype;
390#define FIELD_PYCHECK(o) PyObject_TypeCheck((o), field_pytype)
391#define FIELD_F(o) (((field_pyobj *)(o))->f)
392extern PyObject *field_pywrap(field *);
393extern field *field_copy(field *);
394
8eeb5aee
MW
395typedef struct fe_pyobj {
396 PyObject_HEAD
397 field *f;
398 mp *x;
399} fe_pyobj;
400
401extern PyTypeObject *fe_pytype;
402#define FE_PYCHECK(o) PyObject_TypeCheck((o), fe_pytype)
403#define FE_F(o) (((fe_pyobj *)(o))->f)
404#define FE_FOBJ(o) ((PyObject *)(o)->ob_type)
405#define FE_X(o) (((fe_pyobj *)(o))->x)
406extern PyObject *fe_pywrap(PyObject *, mp *);
407
b6a86d2e 408/*----- Elliptic curves ---------------------------------------------------*/
409
8eeb5aee
MW
410typedef struct eccurve_pyobj {
411 PyHeapTypeObject ty;
412 ec_curve *c;
413 PyObject *fobj;
414} eccurve_pyobj;
415
416extern PyTypeObject *eccurve_pytype;
417extern PyTypeObject *ecprimecurve_pytype;
418extern PyTypeObject *ecprimeprojcurve_pytype;
419extern PyTypeObject *ecbincurve_pytype;
420extern PyTypeObject *ecbinprojcurve_pytype;
421#define ECCURVE_PYCHECK(o) PyObject_TypeCheck((o), eccurve_pytype)
422#define ECCURVE_C(o) (((eccurve_pyobj *)(o))->c)
423#define ECCURVE_FOBJ(o) (((eccurve_pyobj *)(o))->fobj)
424extern PyObject *eccurve_pywrap(PyObject *, ec_curve *);
425extern ec_curve *eccurve_copy(ec_curve *);
426
b6a86d2e 427typedef struct ecpt_pyobj {
428 PyObject_HEAD
429 ec_curve *c;
430 ec p;
431} ecpt_pyobj;
432
433extern PyTypeObject *ecpt_pytype, *ecptcurve_pytype;
434#define ECPT_PYCHECK(o) PyObject_TypeCheck((o), ecpt_pytype)
435#define ECPTCURVE_PYCHECK(o) PyObject_TypeCheck((o), ecptcurve_pytype)
436#define ECPT_C(o) (((ecpt_pyobj *)(o))->c)
437#define ECPT_COBJ(o) ((PyObject *)(o)->ob_type)
438#define ECPT_FOBJ(o) ECCURVE_FOBJ(ECPT_COBJ((o)))
439#define ECPT_P(o) (&((ecpt_pyobj *)(o))->p)
440extern PyObject *ecpt_pywrap(PyObject *, ec *);
441extern PyObject *ecpt_pywrapout(void *, ec *);
442extern int toecpt(ec_curve *, ec *, PyObject *);
443extern int getecpt(ec_curve *, ec *, PyObject *);
444extern void getecptout(ec *, PyObject *);
73a712fa 445extern int convecpt(PyObject *, void *);
b6a86d2e 446
b6a86d2e 447typedef struct ecinfo_pyobj {
448 PyObject_HEAD
449 ec_info ei;
450 PyObject *cobj;
451} ecinfo_pyobj;
0b1eafbf 452
b6a86d2e 453extern PyTypeObject *ecinfo_pytype;
454#define ECINFO_PYCHECK(o) PyObject_TypeCheck((o), ecinfo_pytype)
455#define ECINFO_EI(o) (&((ecinfo_pyobj *)(o))->ei)
456#define ECINFO_COBJ(o) (((ecinfo_pyobj *)(o))->cobj)
457extern void ecinfo_copy(ec_info *, const ec_info *);
458extern PyObject *ecinfo_pywrap(ec_info *);
459
460/*----- Cyclic groups -----------------------------------------------------*/
461
b6a86d2e 462typedef struct ge_pyobj {
463 PyObject_HEAD
464 ge *x;
465 group *g;
466} ge_pyobj;
467
468extern PyTypeObject *ge_pytype;
469#define GE_PYCHECK(o) PyObject_TypeCheck((o), ge_pytype)
470#define GE_X(o) (((ge_pyobj *)(o))->x)
471#define GE_G(o) (((ge_pyobj *)(o))->g)
472#define GE_GOBJ(o) ((PyObject *)(group_pyobj *)(o)->ob_type)
473extern PyObject *ge_pywrap(PyObject *, ge *);
474
475typedef struct group_pyobj {
f0526039 476 PyHeapTypeObject ty;
b6a86d2e 477 group *g;
478} group_pyobj;
479
480extern PyTypeObject *group_pytype;
b6a86d2e 481#define GROUP_G(o) (((group_pyobj *)(o))->g)
482extern PyObject *group_pywrap(group *);
483extern group *group_copy(group *);
484
485/*----- Random number generators ------------------------------------------*/
486
487#define f_freeme 1u
488
489typedef struct grand_pyobj {
490 PyObject_HEAD
491 unsigned f;
492 grand *r;
493} grand_pyobj;
494
8eeb5aee 495extern PyTypeObject *grand_pytype;
b6a86d2e 496extern PyObject *rand_pyobj;
497#define GRAND_PYCHECK(o) PyObject_TypeCheck((o), grand_pytype)
498#define GRAND_F(o) (((grand_pyobj *)(o))->f)
499#define GRAND_R(o) (((grand_pyobj *)(o))->r)
500extern PyObject *grand_pywrap(grand *, unsigned);
501extern int convgrand(PyObject *, void *);
502
b6a86d2e 503/*----- Symmetric cryptography --------------------------------------------*/
504
8eeb5aee 505extern PyObject *keysz_pywrap(const octet *);
b6a86d2e 506
b6a86d2e 507extern int convgccipher(PyObject *, void *);
8eeb5aee 508extern PyObject *gccipher_pywrap(gccipher *);
54ae5879 509
b6a86d2e 510typedef struct gchash_pyobj {
f0526039 511 PyHeapTypeObject ty;
b6a86d2e 512 gchash *ch;
513} gchash_pyobj;
514
515extern PyTypeObject *gchash_pytype;
8eeb5aee 516extern PyObject *sha_pyobj, *has160_pyobj;
b6a86d2e 517#define GCHASH_PYCHECK(o) PyObject_TypeCheck((o), gchash_pytype)
518#define GCHASH_CH(o) (((gchash_pyobj *)(o))->ch)
5a5e08d9 519extern PyObject *ghash_pywrap(PyObject *, ghash *);
8eeb5aee 520extern int convgchash(PyObject *, void *);
b6a86d2e 521extern int convghash(PyObject *, void *);
b6a86d2e 522
b6a86d2e 523extern int convgcmac(PyObject *, void *);
524
b6a86d2e 525/*----- Key generation ----------------------------------------------------*/
0b1eafbf 526
b6a86d2e 527typedef struct pfilt_pyobj {
528 PyObject_HEAD
529 pfilt f;
530 int st;
531} pfilt_pyobj;
532
533extern PyTypeObject *pfilt_pytype;
534#define PFILT_PYCHECK(o) PyObject_TypeCheck(o, pfilt_pytype)
535#define PFILT_F(o) (&((pfilt_pyobj *)(o))->f)
536#define PFILT_ST(o) (((pfilt_pyobj *)(o))->st)
537
538typedef struct { pgen_proc *proc; void *ctx; } pgev;
539#define PGEV_HEAD PyObject_HEAD pgev pg;
540
541typedef struct pgev_pyobj {
542 PGEV_HEAD
543} pgev_pyobj;
544
545extern PyTypeObject *pgev_pytype;
546#define PGEV_PYCHECK(o) PyObject_TypeCheck(o, pgev_pytype)
547#define PGEV_PG(o) (&((pgev_pyobj *)(o))->pg)
548
87aa2e3c
MW
549typedef struct pypgev {
550 pgev ev;
551 PyObject *obj;
552 struct excinfo *exc;
553} pypgev;
554
b6a86d2e 555extern int convpgev(PyObject *, void *);
87aa2e3c
MW
556extern void droppgev(pypgev *);
557extern void pgenerr(struct excinfo *exc);
b6a86d2e 558
b6a86d2e 559/*----- That's all, folks -------------------------------------------------*/
560
561#ifdef __cplusplus
562 }
563#endif
564
565#endif