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