*.c: Declare `PY_SSIZE_T_CLEAN'.
[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>
49
50#include <catacomb/grand.h>
51#include <catacomb/rand.h>
52#include <catacomb/noise.h>
53#include <catacomb/bbs.h>
54#include <catacomb/mprand.h>
55#include <catacomb/lcrand.h>
56#include <catacomb/fibrand.h>
57#include <catacomb/dsarand.h>
58#include <catacomb/sslprf.h>
59#include <catacomb/tlsprf.h>
62058916 60#include <catacomb/blkc.h>
b6a86d2e 61
62#include <catacomb/gcipher.h>
63#include <catacomb/ghash.h>
64#include <catacomb/gmac.h>
65#include <catacomb/md5.h>
66#include <catacomb/md5-hmac.h>
2ad160b1 67#include <catacomb/poly1305.h>
b6a86d2e 68#include <catacomb/sha.h>
69#include <catacomb/sha-mgf.h>
70#include <catacomb/sha-hmac.h>
71
72#include <catacomb/mp.h>
73#include <catacomb/mpint.h>
74#include <catacomb/mpmul.h>
75#include <catacomb/mpcrt.h>
76#include <catacomb/mpmont.h>
77#include <catacomb/mpbarrett.h>
78#include <catacomb/mpreduce.h>
9c034c56 79#include <catacomb/mp-fibonacci.h>
b6a86d2e 80
81#include <catacomb/pgen.h>
82#include <catacomb/pfilt.h>
83#include <catacomb/strongprime.h>
84#include <catacomb/limlee.h>
85#include <catacomb/dh.h>
86#include <catacomb/ptab.h>
87#include <catacomb/bintab.h>
88#include <catacomb/dsa.h>
89
90#include <catacomb/gf.h>
91#include <catacomb/gfreduce.h>
92#include <catacomb/gfn.h>
93
94#include <catacomb/field.h>
95#include <catacomb/field-guts.h>
96
97#include <catacomb/ec.h>
98#include <catacomb/ec-raw.h>
99#include <catacomb/ectab.h>
100
101#include <catacomb/group.h>
102#include <catacomb/group-guts.h>
103
104#include <catacomb/gdsa.h>
105#include <catacomb/gkcdsa.h>
106#include <catacomb/rsa.h>
107
108#include <catacomb/key.h>
109#include <catacomb/passphrase.h>
110#include <catacomb/pixie.h>
111
73a712fa 112#include <catacomb/share.h>
113#include <catacomb/gfshare.h>
114
b6a86d2e 115/*----- Utility macros ----------------------------------------------------*/
116
117#define RETURN_OBJ(obj) do { Py_INCREF(obj); return (obj); } while (0)
118#define RETURN_NONE RETURN_OBJ(Py_None)
119#define RETURN_NOTIMPL RETURN_OBJ(Py_NotImplemented)
120#define RETURN_TRUE RETURN_OBJ(Py_True)
121#define RETURN_FALSE RETURN_OBJ(Py_False)
122#define RETURN_ME RETURN_OBJ(me)
123
124#define EXCERR(exc, str) do { \
125 PyErr_SetString(exc, str); \
126 goto end; \
127} while (0)
128#define VALERR(str) EXCERR(PyExc_ValueError, str)
129#define TYERR(str) EXCERR(PyExc_TypeError, str)
130#define ZDIVERR(str) EXCERR(PyExc_ZeroDivisionError, str)
b6a86d2e 131#define SYSERR(str) EXCERR(PyExc_SystemError, str)
68ec53f3 132#define NIERR(str) EXCERR(PyExc_NotImplementedError, str)
73a712fa 133#define INDEXERR(idx) do { \
134 PyErr_SetObject(PyExc_KeyError, idx); \
135 goto end; \
136} while (0)
b6a86d2e 137#define OSERR(name) do { \
138 PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); \
139 goto end; \
140} while (0)
141#define PGENERR do { pgenerr(); goto end; } while (0)
142
143#define CONVFUNC(ty, cty, ext) \
144 int conv##ty(PyObject *o, void *p) \
145 { \
146 if (!PyObject_TypeCheck(o, ty##_pytype)) \
147 TYERR("wanted a " #ty); \
148 *(cty *)p = ext(o); \
149 return (1); \
150 end: \
151 return (0); \
152 }
153
d4a9e7e7
MW
154#if PY_VERSION_HEX < 0x02050000 /* Compatibility hack */
155# define ht_name name
156# define ht_type type
157#endif
158
b6a86d2e 159#define root_pytype 0
160#define type_pytype &PyType_Type
017d5f65 161#define INITTYPE_META(ty, base, meta) do { \
b6a86d2e 162 ty##_pytype_skel.tp_base = base##_pytype; \
017d5f65 163 ty##_pytype = inittype(&ty##_pytype_skel, meta##_pytype); \
b6a86d2e 164} while (0)
017d5f65 165#define INITTYPE(ty, base) INITTYPE_META(ty, base, type)
b6a86d2e 166
167#define INSERT(name, ob) do { \
168 PyObject *_o = (PyObject *)(ob); \
0b1eafbf 169 Py_INCREF(_o); \
b6a86d2e 170 PyModule_AddObject(mod, name, _o); \
171} while (0)
172
73a712fa 173#define INSEXC(name, var, base, meth) \
174 INSERT(name, var = mkexc(mod, base, name, meth))
175
b6a86d2e 176#define METH(func, doc) \
177 { #func, METHNAME(func), METH_VARARGS, doc },
178#define KWMETH(func, doc) \
179 { #func, (PyCFunction)METHNAME(func), \
180 METH_VARARGS | METH_KEYWORDS, doc },
181
182#define GET(func, doc) \
183 { #func, GETSETNAME(get, func), 0, doc },
184#define GETSET(func, doc) \
185 { #func, GETSETNAME(get, func), GETSETNAME(set, func), doc },
186
187#define MEMBER(name, ty, f, doc) \
188 { #name, ty, offsetof(MEMBERSTRUCT, name), f, doc },
189
73a712fa 190#define MODULES(_) \
dfe0a897 191 _(util) \
73a712fa 192 _(bytestring) _(buffer) \
193 _(rand) _(algorithms) _(pubkey) _(pgen) \
194 _(mp) _(field) _(ec) _(group) \
dfe0a897 195 _(passphrase) _(share) _(key)
b6a86d2e 196#define DOMODINIT(m) m##_pyinit();
197#define DOMODINSERT(m) m##_pyinsert(mod);
198#define INIT_MODULES do { MODULES(DOMODINIT) } while (0)
199#define INSERT_MODULES do { MODULES(DOMODINSERT) } while (0)
200
201#define DO(m) \
202 extern void m##_pyinit(void); \
203 extern void m##_pyinsert(PyObject *);
204MODULES(DO)
205#undef DO
206
ba45a729 207#define FREEOBJ(obj) \
208 (((PyObject *)(obj))->ob_type->tp_free((PyObject *)(obj)))
209
68ec53f3
MW
210#define GEN(func, base) \
211 static PyObject *func(void) \
212 { \
213 PyObject *d = PyDict_New(); \
214 PyObject *o; \
215 int i; \
216 \
217 for (i = 0; g##base##tab[i]; i++) { \
218 o = gc##base##_pywrap((/*unconst*/ gc##base *)g##base##tab[i]); \
219 PyDict_SetItemString(d, \
220 (/*unconst*/ char *)g##base##tab[i]->name, \
221 o); \
222 Py_DECREF(o); \
223 } \
224 return (d); \
225 }
226
227struct nameval { const char *name; unsigned long value; };
228extern void setconstants(PyObject *, const struct nameval *);
229
230extern PyObject *mexp_common(PyObject *, PyObject *, size_t,
231 PyObject *(*id)(PyObject *),
232 int (*fill)(void *, PyObject *,
233 PyObject *, PyObject *),
234 PyObject *(*exp)(PyObject *, void *, int),
235 void (*drop)(void *));
236
237extern int convulong(PyObject *, void *);
238#define DECL_CONVU_(n) extern int convu##n(PyObject *, void *);
239DOUINTSZ(DECL_CONVU_)
240extern int convmpw(PyObject *, void *);
241extern int convuint(PyObject *, void *);
1b6734b6 242extern int convk64(PyObject *, void *);
68ec53f3
MW
243extern int convszt(PyObject *, void *);
244extern int convbool(PyObject *, void *);
245extern PyObject *abstract_pynew(PyTypeObject *, PyObject *, PyObject *);
246extern PyObject *getbool(int);
1e082a86 247extern PyObject *getulong(unsigned long);
1b6734b6 248extern PyObject *getk64(kludge64);
68ec53f3
MW
249extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *);
250
d2421f3c 251extern PyObject *mkexc(PyObject *, PyObject *, const char *, PyMethodDef *);
0156e402 252extern void typeready(PyTypeObject *);
017d5f65 253extern PyTypeObject *inittype(PyTypeObject *, PyTypeObject *);
68ec53f3
MW
254extern void addmethods(const PyMethodDef *);
255extern PyMethodDef *donemethods(void);
256
257/*----- Mapping methods ---------------------------------------------------*/
258
259#define GMAP_METH(func, doc) { #func, gmapmeth_##func, METH_VARARGS, doc },
260#define GMAP_KWMETH(func, doc) \
261 { #func, (PyCFunction)gmapmeth_##func, METH_VARARGS|METH_KEYWORDS, doc },
262#define GMAP_METHDECL(func, doc) \
263 extern PyObject *gmapmeth_##func(PyObject *, PyObject *);
264#define GMAP_KWMETHDECL(func, doc) \
265 extern PyObject *gmapmeth_##func(PyObject *, PyObject *, PyObject *);
266
2a509510 267#define GMAP_DOROMETHODS(METH, KWMETH) \
68ec53f3
MW
268 METH (has_key, "D.has_key(KEY) -> BOOL") \
269 METH (keys, "D.keys() -> LIST") \
270 METH (values, "D.values() -> LIST") \
271 METH (items, "D.items() -> LIST") \
272 METH (iterkeys, "D.iterkeys() -> ITER") \
273 METH (itervalues, "D.itervalues() -> ITER") \
0b1eafbf 274 METH (iteritems, "D.iteritems() -> ITER") \
68ec53f3 275 KWMETH(get, "D.get(KEY, [default = None]) -> VALUE") \
2a509510
MW
276
277#define GMAP_DOMETHODS(METH, KWMETH) \
278 GMAP_DOROMETHODS(METH, KWMETH) \
279 METH (clear, "D.clear()") \
68ec53f3
MW
280 KWMETH(setdefault, "D.setdefault(K, [default = None]) -> VALUE") \
281 KWMETH(pop, "D.pop(KEY, [default = <error>]) -> VALUE") \
282 METH (popitem, "D.popitem() -> (KEY, VALUE)") \
283 METH (update, "D.update(MAP)")
284
285GMAP_DOMETHODS(GMAP_METHDECL, GMAP_KWMETHDECL)
2a509510 286#define GMAP_ROMETHODS GMAP_DOROMETHODS(GMAP_METH, GMAP_KWMETH)
68ec53f3 287#define GMAP_METHODS GMAP_DOMETHODS(GMAP_METH, GMAP_KWMETH)
9d73ed80 288extern Py_ssize_t gmap_pysize(PyObject *);
68ec53f3
MW
289extern PySequenceMethods gmap_pysequence;
290extern PyMethodDef gmap_pymethods[];
291
b6a86d2e 292/*----- Bytestrings -------------------------------------------------------*/
293
294PyTypeObject *bytestring_pyobj;
295PyObject *bytestring_pywrap(const void *, size_t);
296PyObject *bytestring_pywrapbuf(buf *);
297
298/*----- Multiprecision arithmetic -----------------------------------------*/
299
300typedef struct mp_pyobj {
301 PyObject_HEAD
302 mp *x;
303} mp_pyobj;
304
305extern PyTypeObject *mp_pytype;
306extern PyTypeObject *gf_pytype;
307#define MP_X(o) (((mp_pyobj *)(o))->x)
308#define MP_PYCHECK(o) PyObject_TypeCheck((o), mp_pytype)
309#define GF_PYCHECK(o) PyObject_TypeCheck((o), gf_pytype)
310
8d57d6ea
MW
311extern mp *mp_frompylong(PyObject *);
312extern PyObject *mp_topylong(mp *);
b6a86d2e 313extern mp *tomp(PyObject *);
314extern mp *getmp(PyObject *);
315extern int convmp(PyObject *, void *);
316extern mp *getgf(PyObject *);
317extern int convgf(PyObject *, void *);
318extern PyObject *mp_pywrap(mp *);
319extern PyObject *gf_pywrap(mp *);
320extern mp *mp_frompyobject(PyObject *, int);
321extern PyObject *mp_topystring(mp *, int,
322 const char *, const char *, const char *);
323extern int mp_tolong_checked(mp *, long *);
324
325/*----- Abstract fields ---------------------------------------------------*/
326
327typedef struct field_pyobj {
f0526039 328 PyHeapTypeObject ty;
b6a86d2e 329 field *f;
330} field_pyobj;
331
332extern PyTypeObject *fe_pytype;
333#define FE_PYCHECK(o) PyObject_TypeCheck((o), fe_pytype)
334#define FE_F(o) (((fe_pyobj *)(o))->f)
335#define FE_FOBJ(o) ((PyObject *)(o)->ob_type)
336#define FE_X(o) (((fe_pyobj *)(o))->x)
337extern PyObject *fe_pywrap(PyObject *, mp *);
338extern mp *getfe(field *, PyObject *);
339
340typedef struct fe_pyobj {
341 PyObject_HEAD
342 field *f;
b6a86d2e 343 mp *x;
344} fe_pyobj;
0b1eafbf 345
b6a86d2e 346extern PyTypeObject *field_pytype;
347extern PyTypeObject *primefield_pytype;
348extern PyTypeObject *niceprimefield_pytype;
349extern PyTypeObject *binfield_pytype;
350extern PyTypeObject *binpolyfield_pytype;
351extern PyTypeObject *binnormfield_pytype;
352#define FIELD_PYCHECK(o) PyObject_TypeCheck((o), field_pytype)
353#define FIELD_F(o) (((field_pyobj *)(o))->f)
354extern PyObject *field_pywrap(field *);
355extern field *field_copy(field *);
356
357/*----- Elliptic curves ---------------------------------------------------*/
358
359typedef struct ecpt_pyobj {
360 PyObject_HEAD
361 ec_curve *c;
362 ec p;
363} ecpt_pyobj;
364
365extern PyTypeObject *ecpt_pytype, *ecptcurve_pytype;
366#define ECPT_PYCHECK(o) PyObject_TypeCheck((o), ecpt_pytype)
367#define ECPTCURVE_PYCHECK(o) PyObject_TypeCheck((o), ecptcurve_pytype)
368#define ECPT_C(o) (((ecpt_pyobj *)(o))->c)
369#define ECPT_COBJ(o) ((PyObject *)(o)->ob_type)
370#define ECPT_FOBJ(o) ECCURVE_FOBJ(ECPT_COBJ((o)))
371#define ECPT_P(o) (&((ecpt_pyobj *)(o))->p)
372extern PyObject *ecpt_pywrap(PyObject *, ec *);
373extern PyObject *ecpt_pywrapout(void *, ec *);
374extern int toecpt(ec_curve *, ec *, PyObject *);
375extern int getecpt(ec_curve *, ec *, PyObject *);
376extern void getecptout(ec *, PyObject *);
73a712fa 377extern int convecpt(PyObject *, void *);
b6a86d2e 378
379typedef struct eccurve_pyobj {
f0526039 380 PyHeapTypeObject ty;
b6a86d2e 381 ec_curve *c;
382 PyObject *fobj;
383} eccurve_pyobj;
384
385extern PyTypeObject *eccurve_pytype;
386extern PyTypeObject *ecprimecurve_pytype;
387extern PyTypeObject *ecprimeprojcurve_pytype;
388extern PyTypeObject *ecbincurve_pytype;
389extern PyTypeObject *ecbinprojcurve_pytype;
390#define ECCURVE_PYCHECK(o) PyObject_TypeCheck((o), eccurve_pytype)
391#define ECCURVE_C(o) (((eccurve_pyobj *)(o))->c)
392#define ECCURVE_FOBJ(o) (((eccurve_pyobj *)(o))->fobj)
393extern PyObject *eccurve_pywrap(PyObject *, ec_curve *);
394extern ec_curve *eccurve_copy(ec_curve *);
395
396typedef struct ecinfo_pyobj {
397 PyObject_HEAD
398 ec_info ei;
399 PyObject *cobj;
400} ecinfo_pyobj;
0b1eafbf 401
b6a86d2e 402extern PyTypeObject *ecinfo_pytype;
403#define ECINFO_PYCHECK(o) PyObject_TypeCheck((o), ecinfo_pytype)
404#define ECINFO_EI(o) (&((ecinfo_pyobj *)(o))->ei)
405#define ECINFO_COBJ(o) (((ecinfo_pyobj *)(o))->cobj)
406extern void ecinfo_copy(ec_info *, const ec_info *);
407extern PyObject *ecinfo_pywrap(ec_info *);
408
409/*----- Cyclic groups -----------------------------------------------------*/
410
411typedef struct fginfo_pyobj {
412 PyObject_HEAD
413 gprime_param dp;
414} fginfo_pyobj;
415
416PyTypeObject *fginfo_pytype, *dhinfo_pytype, *bindhinfo_pytype;
417#define FGINFO_DP(fg) (&((fginfo_pyobj *)(fg))->dp)
418PyObject *fginfo_pywrap(gprime_param *, PyTypeObject *);
419
420typedef struct ge_pyobj {
421 PyObject_HEAD
422 ge *x;
423 group *g;
424} ge_pyobj;
425
426extern PyTypeObject *ge_pytype;
427#define GE_PYCHECK(o) PyObject_TypeCheck((o), ge_pytype)
428#define GE_X(o) (((ge_pyobj *)(o))->x)
429#define GE_G(o) (((ge_pyobj *)(o))->g)
430#define GE_GOBJ(o) ((PyObject *)(group_pyobj *)(o)->ob_type)
431extern PyObject *ge_pywrap(PyObject *, ge *);
432
433typedef struct group_pyobj {
f0526039 434 PyHeapTypeObject ty;
b6a86d2e 435 group *g;
436} group_pyobj;
437
438extern PyTypeObject *group_pytype;
439extern PyTypeObject *primegroup_pytype, *bingroup_pytype, *ecgroup_pytype;
440#define GROUP_G(o) (((group_pyobj *)(o))->g)
441extern PyObject *group_pywrap(group *);
442extern group *group_copy(group *);
443
444/*----- Random number generators ------------------------------------------*/
445
446#define f_freeme 1u
447
448typedef struct grand_pyobj {
449 PyObject_HEAD
450 unsigned f;
451 grand *r;
452} grand_pyobj;
453
454extern PyTypeObject *grand_pytype, *truerand_pytype;
455extern PyTypeObject *lcrand_pytype,* fibrand_pytype;
456extern PyTypeObject *dsarand_pytype, *bbs_pytype;
457extern PyObject *rand_pyobj;
458#define GRAND_PYCHECK(o) PyObject_TypeCheck((o), grand_pytype)
459#define GRAND_F(o) (((grand_pyobj *)(o))->f)
460#define GRAND_R(o) (((grand_pyobj *)(o))->r)
461extern PyObject *grand_pywrap(grand *, unsigned);
462extern int convgrand(PyObject *, void *);
463
464/*----- Key sizes ---------------------------------------------------------*/
465
466typedef struct keysz_pyobj {
467 PyObject_HEAD
468 int dfl;
469} keysz_pyobj;
470
471typedef struct keyszrange_pyobj {
472 PyObject_HEAD
473 int dfl;
474 int min, max, mod;
475} keyszrange_pyobj;
476
477typedef struct keyszset_pyobj {
478 PyObject_HEAD
479 int dfl;
480 PyObject *set;
481} keyszset_pyobj;
482
483#define KEYSZ_PYCHECK(o) PyObject_TypeCheck((o), keysz_pytype)
484extern PyObject *keysz_pywrap(const octet *);
485
486/*----- Symmetric cryptography --------------------------------------------*/
487
488typedef struct gccipher_pyobj {
f0526039 489 PyHeapTypeObject ty;
b6a86d2e 490 gccipher *cc;
491} gccipher_pyobj;
492
493extern PyTypeObject *gccipher_pytype;
494#define GCCIPHER_PYCHECK(o) PyObject_TypeCheck((o), gccipher_pytype)
495#define GCCIPHER_CC(o) (((gccipher_pyobj *)(o))->cc)
496#define GCCIPHER_F(o) (((gccipher_pyobj *)(o))->f)
497extern PyObject *gccipher_pywrap(gccipher *);
498extern int convgccipher(PyObject *, void *);
499extern int convgcipher(PyObject *, void *);
500
501typedef struct gcipher_pyobj {
502 PyObject_HEAD
503 unsigned f;
504 gcipher *c;
505} gcipher_pyobj;
506
507extern PyTypeObject *gcipher_pytype;
508#define GCIPHER_PYCHECK(o) PyObject_TypeCheck((o), gcipher_pytype)
509#define GCIPHER_C(o) (((gcipher_pyobj *)(o))->c)
510#define GCIPHER_F(o) (((gcipher_pyobj *)(o))->f)
511extern PyObject *gcipher_pywrap(PyObject *, gcipher *, unsigned);
512extern int convgcipher(PyObject *, void *);
513
514typedef struct gchash_pyobj {
f0526039 515 PyHeapTypeObject ty;
b6a86d2e 516 gchash *ch;
517} gchash_pyobj;
518
519extern PyTypeObject *gchash_pytype;
520#define GCHASH_PYCHECK(o) PyObject_TypeCheck((o), gchash_pytype)
521#define GCHASH_CH(o) (((gchash_pyobj *)(o))->ch)
522#define GCHASH_F(o) (((gchash_pyobj *)(o))->f)
523extern PyObject *gchash_pywrap(gchash *);
524extern int convgchash(PyObject *, void *);
525
526typedef struct ghash_pyobj {
527 PyObject_HEAD
528 unsigned f;
529 ghash *h;
530} ghash_pyobj;
531
532extern PyTypeObject *ghash_pytype, *gmhash_pytype;
533extern PyObject *sha_pyobj, *has160_pyobj;
534#define GHASH_PYCHECK(o) PyObject_TypeCheck((o), ghash_pytype)
535#define GHASH_H(o) (((ghash_pyobj *)(o))->h)
536#define GHASH_F(o) (((ghash_pyobj *)(o))->f)
537extern PyObject *ghash_pywrap(PyObject *, ghash *, unsigned);
538extern int convghash(PyObject *, void *);
539extern int convgmhash(PyObject *, void *);
540
541typedef struct gcmac_pyobj {
f0526039 542 PyHeapTypeObject ty;
b6a86d2e 543 gcmac *cm;
544} gcmac_pyobj;
545
546extern PyTypeObject *gcmac_pytype;
547#define GCMAC_PYCHECK(o) PyObject_TypeCheck((o), gcmac_pytype)
548#define GCMAC_CM(o) (((gcmac_pyobj *)(o))->cm)
549#define GCMAC_F(o) (((gcmac_pyobj *)(o))->f)
550extern PyObject *gcmac_pywrap(gcmac *);
551extern int convgcmac(PyObject *, void *);
552
553typedef struct gmac_pyobj {
f0526039 554 PyHeapTypeObject ty;
b6a86d2e 555 unsigned f;
556 gmac *m;
b6a86d2e 557} gmac_pyobj;
558
559extern PyTypeObject *gmac_pytype;
560#define GMAC_PYCHECK(o) PyObject_TypeCheck((o), gmac_pytype)
561#define GMAC_M(o) (((gmac_pyobj *)(o))->m)
b6a86d2e 562#define GMAC_F(o) (((gmac_pyobj *)(o))->f)
563extern PyObject *gmac_pywrap(PyObject *, gmac *, unsigned);
564extern int convgmac(PyObject *, void *);
565
b6a86d2e 566/*----- Key generation ----------------------------------------------------*/
0b1eafbf 567
b6a86d2e 568typedef struct pfilt_pyobj {
569 PyObject_HEAD
570 pfilt f;
571 int st;
572} pfilt_pyobj;
573
574extern PyTypeObject *pfilt_pytype;
575#define PFILT_PYCHECK(o) PyObject_TypeCheck(o, pfilt_pytype)
576#define PFILT_F(o) (&((pfilt_pyobj *)(o))->f)
577#define PFILT_ST(o) (((pfilt_pyobj *)(o))->st)
578
579typedef struct { pgen_proc *proc; void *ctx; } pgev;
580#define PGEV_HEAD PyObject_HEAD pgev pg;
581
582typedef struct pgev_pyobj {
583 PGEV_HEAD
584} pgev_pyobj;
585
586extern PyTypeObject *pgev_pytype;
587#define PGEV_PYCHECK(o) PyObject_TypeCheck(o, pgev_pytype)
588#define PGEV_PG(o) (&((pgev_pyobj *)(o))->pg)
589
590extern int convpgev(PyObject *, void *);
591extern void droppgev(pgev *);
592extern void pgenerr(void);
593
b6a86d2e 594/*----- That's all, folks -------------------------------------------------*/
595
596#ifdef __cplusplus
597 }
598#endif
599
600#endif