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