3 * Definitions for Catacomb bindings
5 * (c) 2004 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the Python interface to Catacomb.
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.
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.
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.
27 #ifndef CATACOMB_PYTHON_H
28 #define CATACOMB_PYTHON_H
34 /*----- Header files ------------------------------------------------------*/
36 #define PY_SSIZE_T_CLEAN
39 #include <longintrepr.h>
40 #include <structmember.h>
42 #include <mLib/darray.h>
43 #include <mLib/dstr.h>
44 #include <mLib/macros.h>
45 #include <mLib/quis.h>
46 #include <mLib/unihash.h>
48 #include <catacomb/buf.h>
49 #include <catacomb/ct.h>
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>
61 #include <catacomb/blkc.h>
63 #include <catacomb/gcipher.h>
64 #include <catacomb/gaead.h>
65 #include <catacomb/ghash.h>
66 #include <catacomb/gmac.h>
67 #include <catacomb/md5.h>
68 #include <catacomb/md5-hmac.h>
69 #include <catacomb/poly1305.h>
70 #include <catacomb/sha.h>
71 #include <catacomb/sha-mgf.h>
72 #include <catacomb/sha-hmac.h>
73 #include <catacomb/keccak1600.h>
74 #include <catacomb/sha3.h>
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>
83 #include <catacomb/mp-fibonacci.h>
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>
93 #include <catacomb/x25519.h>
94 #include <catacomb/x448.h>
95 #include <catacomb/ed25519.h>
96 #include <catacomb/ed448.h>
98 #include <catacomb/gf.h>
99 #include <catacomb/gfreduce.h>
100 #include <catacomb/gfn.h>
102 #include <catacomb/field.h>
103 #include <catacomb/field-guts.h>
105 #include <catacomb/ec.h>
106 #include <catacomb/ec-raw.h>
107 #include <catacomb/ectab.h>
109 #include <catacomb/group.h>
110 #include <catacomb/group-guts.h>
112 #include <catacomb/gdsa.h>
113 #include <catacomb/gkcdsa.h>
114 #include <catacomb/rsa.h>
116 #include <catacomb/key.h>
117 #include <catacomb/passphrase.h>
118 #include <catacomb/pixie.h>
120 #include <catacomb/share.h>
121 #include <catacomb/gfshare.h>
123 /*----- Utility macros ----------------------------------------------------*/
125 #define RETURN_OBJ(obj) do { Py_INCREF(obj); return (obj); } while (0)
126 #define RETURN_NONE RETURN_OBJ(Py_None)
127 #define RETURN_NOTIMPL RETURN_OBJ(Py_NotImplemented)
128 #define RETURN_TRUE RETURN_OBJ(Py_True)
129 #define RETURN_FALSE RETURN_OBJ(Py_False)
130 #define RETURN_ME RETURN_OBJ(me)
132 #define EXCERR(exc, str) do { \
133 PyErr_SetString(exc, str); \
136 #define VALERR(str) EXCERR(PyExc_ValueError, str)
137 #define OVFERR(str) EXCERR(PyExc_OverflowError, str)
138 #define TYERR(str) EXCERR(PyExc_TypeError, str)
139 #define IXERR(str) EXCERR(PyExc_IndexError, str)
140 #define ZDIVERR(str) EXCERR(PyExc_ZeroDivisionError, str)
141 #define SYSERR(str) EXCERR(PyExc_SystemError, str)
142 #define NIERR(str) EXCERR(PyExc_NotImplementedError, str)
143 #define INDEXERR(idx) do { \
144 PyErr_SetObject(PyExc_KeyError, idx); \
147 #define OSERR(name) do { \
148 PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); \
151 #define PGENERR(exc) do { pgenerr(exc); goto end; } while (0)
153 #define CONVFUNC(ty, cty, ext) \
154 int conv##ty(PyObject *o, void *p) \
156 if (!PyObject_TypeCheck(o, ty##_pytype)) \
157 TYERR("wanted a " #ty); \
158 *(cty *)p = ext(o); \
164 #if PY_VERSION_HEX < 0x02050000 /* Compatibility hack */
165 # define ht_name name
166 # define ht_type type
169 #define root_pytype 0
170 #define type_pytype &PyType_Type
171 #define INITTYPE_META(ty, base, meta) do { \
172 ty##_pytype_skel.tp_base = base##_pytype; \
173 ty##_pytype = inittype(&ty##_pytype_skel, meta##_pytype); \
175 #define INITTYPE(ty, base) INITTYPE_META(ty, base, type)
177 extern PyObject *home_module;
179 #define INSERT(name, ob) do { \
180 PyObject *_o = (PyObject *)(ob); \
182 PyModule_AddObject(mod, name, _o); \
185 #define INSEXC(name, var, base, meth) \
186 INSERT(name, var = mkexc(mod, base, name, meth))
188 #define METH(func, doc) \
189 { #func, METHNAME(func), METH_VARARGS, doc },
190 #define KWMETH(func, doc) \
191 { #func, (PyCFunction)METHNAME(func), \
192 METH_VARARGS | METH_KEYWORDS, doc },
194 #define GET(func, doc) \
195 { #func, GETSETNAME(get, func), 0, doc },
196 #define GETSET(func, doc) \
197 { #func, GETSETNAME(get, func), GETSETNAME(set, func), doc },
199 #define MEMBER(name, ty, f, doc) \
200 { #name, ty, offsetof(MEMBERSTRUCT, name), f, doc },
204 _(bytestring) _(buffer) \
205 _(rand) _(algorithms) _(pubkey) _(pgen) \
206 _(mp) _(field) _(ec) _(group) \
207 _(passphrase) _(share) _(key)
208 #define DOMODINIT(m) m##_pyinit();
209 #define DOMODINSERT(m) m##_pyinsert(mod);
210 #define INIT_MODULES do { MODULES(DOMODINIT) } while (0)
211 #define INSERT_MODULES do { MODULES(DOMODINSERT) } while (0)
214 extern void m##_pyinit(void); \
215 extern void m##_pyinsert(PyObject *);
219 #define FREEOBJ(obj) \
220 (((PyObject *)(obj))->ob_type->tp_free((PyObject *)(obj)))
222 #define GEN(func, base) \
223 static PyObject *func(void) \
225 PyObject *d = PyDict_New(); \
229 for (i = 0; g##base##tab[i]; i++) { \
230 o = gc##base##_pywrap((/*unconst*/ gc##base *)g##base##tab[i]); \
231 PyDict_SetItemString(d, \
232 (/*unconst*/ char *)g##base##tab[i]->name, \
239 #define KWLIST (/*unconst*/ char **)kwlist
241 struct nameval { const char *name; unsigned f; unsigned long value; };
243 extern void setconstants(PyObject *, const struct nameval *);
245 extern PyObject *mexp_common(PyObject *, PyObject *, size_t,
246 PyObject *(*id)(PyObject *),
247 int (*fill)(void *, PyObject *,
248 PyObject *, PyObject *),
249 PyObject *(*exp)(PyObject *, void *, int),
250 void (*drop)(void *));
252 extern int convulong(PyObject *, void *);
253 #define DECL_CONVU_(n) extern int convu##n(PyObject *, void *);
254 DOUINTSZ(DECL_CONVU_)
255 extern int convmpw(PyObject *, void *);
256 extern int convuint(PyObject *, void *);
257 extern int convk64(PyObject *, void *);
258 extern int convszt(PyObject *, void *);
259 extern int convbool(PyObject *, void *);
260 extern PyObject *abstract_pynew(PyTypeObject *, PyObject *, PyObject *);
261 extern PyObject *getbool(int);
262 extern PyObject *getulong(unsigned long);
263 extern PyObject *getk64(kludge64);
264 extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *);
266 struct excinfo { PyObject *ty, *val, *tb; };
267 #define EXCINFO_INIT { 0, 0, 0 }
269 extern PyObject *mkexc(PyObject *, PyObject *, const char *, PyMethodDef *);
270 #define INIT_EXCINFO(exc) do { \
271 struct excinfo *_exc = (exc); _exc->ty = _exc->val = _exc->tb = 0; \
273 #define RELEASE_EXCINFO(exc) do { \
274 struct excinfo *_exc = (exc); \
275 Py_XDECREF(_exc->ty); _exc->ty = 0; \
276 Py_XDECREF(_exc->val); _exc->val = 0; \
277 Py_XDECREF(_exc->tb); _exc->tb = 0; \
279 #define STASH_EXCINFO(exc) do { \
280 struct excinfo *_exc = (exc); \
281 PyErr_Fetch(&_exc->ty, &_exc->val, &_exc->tb); \
282 PyErr_NormalizeException(&_exc->ty, &_exc->val, &_exc->tb); \
284 #define RESTORE_EXCINFO(exc) do { \
285 struct excinfo *_exc = (exc); \
286 PyErr_Restore(_exc->ty, _exc->val, _exc->tb); \
287 _exc->ty = _exc->val = _exc->tb = 0; \
289 extern void report_lost_exception(struct excinfo *, const char *, ...);
290 extern void report_lost_exception_v(struct excinfo *, const char *, va_list);
291 extern void stash_exception(struct excinfo *, const char *, ...);
292 extern void restore_exception(struct excinfo *, const char *, ...);
294 extern void typeready(PyTypeObject *);
295 extern PyTypeObject *inittype(PyTypeObject *, PyTypeObject *);
296 extern void addmethods(const PyMethodDef *);
297 extern PyMethodDef *donemethods(void);
299 /*----- Mapping methods ---------------------------------------------------*/
301 #define GMAP_METH(func, doc) { #func, gmapmeth_##func, METH_VARARGS, doc },
302 #define GMAP_KWMETH(func, doc) \
303 { #func, (PyCFunction)gmapmeth_##func, METH_VARARGS|METH_KEYWORDS, doc },
304 #define GMAP_METHDECL(func, doc) \
305 extern PyObject *gmapmeth_##func(PyObject *, PyObject *);
306 #define GMAP_KWMETHDECL(func, doc) \
307 extern PyObject *gmapmeth_##func(PyObject *, PyObject *, PyObject *);
309 #define GMAP_DOROMETHODS(METH, KWMETH) \
310 METH (has_key, "D.has_key(KEY) -> BOOL") \
311 METH (keys, "D.keys() -> LIST") \
312 METH (values, "D.values() -> LIST") \
313 METH (items, "D.items() -> LIST") \
314 METH (iterkeys, "D.iterkeys() -> ITER") \
315 METH (itervalues, "D.itervalues() -> ITER") \
316 METH (iteritems, "D.iteritems() -> ITER") \
317 KWMETH(get, "D.get(KEY, [default = None]) -> VALUE") \
319 #define GMAP_DOMETHODS(METH, KWMETH) \
320 GMAP_DOROMETHODS(METH, KWMETH) \
321 METH (clear, "D.clear()") \
322 KWMETH(setdefault, "D.setdefault(K, [default = None]) -> VALUE") \
323 KWMETH(pop, "D.pop(KEY, [default = <error>]) -> VALUE") \
324 METH (popitem, "D.popitem() -> (KEY, VALUE)") \
325 METH (update, "D.update(MAP)")
327 GMAP_DOMETHODS(GMAP_METHDECL, GMAP_KWMETHDECL)
328 #define GMAP_ROMETHODS GMAP_DOROMETHODS(GMAP_METH, GMAP_KWMETH)
329 #define GMAP_METHODS GMAP_DOMETHODS(GMAP_METH, GMAP_KWMETH)
330 extern Py_ssize_t gmap_pysize(PyObject *);
331 extern PySequenceMethods gmap_pysequence;
332 extern PyMethodDef gmap_pymethods[];
334 /*----- Bytestrings -------------------------------------------------------*/
336 PyTypeObject *bytestring_pyobj;
337 PyObject *bytestring_pywrap(const void *, size_t);
338 PyObject *bytestring_pywrapbuf(buf *);
340 /*----- Multiprecision arithmetic -----------------------------------------*/
342 typedef struct mp_pyobj {
347 extern PyTypeObject *mp_pytype;
348 extern PyTypeObject *gf_pytype;
349 #define MP_X(o) (((mp_pyobj *)(o))->x)
350 #define MP_PYCHECK(o) PyObject_TypeCheck((o), mp_pytype)
351 #define GF_PYCHECK(o) PyObject_TypeCheck((o), gf_pytype)
353 extern mp *mp_frompylong(PyObject *);
354 extern PyObject *mp_topylong(mp *);
355 extern mp *tomp(PyObject *);
356 extern mp *getmp(PyObject *);
357 extern int convmp(PyObject *, void *);
358 extern mp *getgf(PyObject *);
359 extern int convgf(PyObject *, void *);
360 extern PyObject *mp_pywrap(mp *);
361 extern PyObject *gf_pywrap(mp *);
362 extern long mphash(mp *);
363 extern mp *mp_frompyobject(PyObject *, int);
364 extern PyObject *mp_topystring(mp *, int,
365 const char *, const char *, const char *);
366 extern int mp_tolong_checked(mp *, long *, int);
368 /*----- Abstract fields ---------------------------------------------------*/
370 typedef struct field_pyobj {
375 extern PyTypeObject *fe_pytype;
376 #define FE_PYCHECK(o) PyObject_TypeCheck((o), fe_pytype)
377 #define FE_F(o) (((fe_pyobj *)(o))->f)
378 #define FE_FOBJ(o) ((PyObject *)(o)->ob_type)
379 #define FE_X(o) (((fe_pyobj *)(o))->x)
380 extern PyObject *fe_pywrap(PyObject *, mp *);
382 typedef struct fe_pyobj {
388 extern PyTypeObject *field_pytype;
389 extern PyTypeObject *primefield_pytype;
390 extern PyTypeObject *niceprimefield_pytype;
391 extern PyTypeObject *binfield_pytype;
392 extern PyTypeObject *binpolyfield_pytype;
393 extern PyTypeObject *binnormfield_pytype;
394 #define FIELD_PYCHECK(o) PyObject_TypeCheck((o), field_pytype)
395 #define FIELD_F(o) (((field_pyobj *)(o))->f)
396 extern PyObject *field_pywrap(field *);
397 extern field *field_copy(field *);
399 /*----- Elliptic curves ---------------------------------------------------*/
401 typedef struct ecpt_pyobj {
407 extern PyTypeObject *ecpt_pytype, *ecptcurve_pytype;
408 #define ECPT_PYCHECK(o) PyObject_TypeCheck((o), ecpt_pytype)
409 #define ECPTCURVE_PYCHECK(o) PyObject_TypeCheck((o), ecptcurve_pytype)
410 #define ECPT_C(o) (((ecpt_pyobj *)(o))->c)
411 #define ECPT_COBJ(o) ((PyObject *)(o)->ob_type)
412 #define ECPT_FOBJ(o) ECCURVE_FOBJ(ECPT_COBJ((o)))
413 #define ECPT_P(o) (&((ecpt_pyobj *)(o))->p)
414 extern PyObject *ecpt_pywrap(PyObject *, ec *);
415 extern PyObject *ecpt_pywrapout(void *, ec *);
416 extern int toecpt(ec_curve *, ec *, PyObject *);
417 extern int getecpt(ec_curve *, ec *, PyObject *);
418 extern void getecptout(ec *, PyObject *);
419 extern int convecpt(PyObject *, void *);
421 typedef struct eccurve_pyobj {
427 extern PyTypeObject *eccurve_pytype;
428 extern PyTypeObject *ecprimecurve_pytype;
429 extern PyTypeObject *ecprimeprojcurve_pytype;
430 extern PyTypeObject *ecbincurve_pytype;
431 extern PyTypeObject *ecbinprojcurve_pytype;
432 #define ECCURVE_PYCHECK(o) PyObject_TypeCheck((o), eccurve_pytype)
433 #define ECCURVE_C(o) (((eccurve_pyobj *)(o))->c)
434 #define ECCURVE_FOBJ(o) (((eccurve_pyobj *)(o))->fobj)
435 extern PyObject *eccurve_pywrap(PyObject *, ec_curve *);
436 extern ec_curve *eccurve_copy(ec_curve *);
438 typedef struct ecinfo_pyobj {
444 extern PyTypeObject *ecinfo_pytype;
445 #define ECINFO_PYCHECK(o) PyObject_TypeCheck((o), ecinfo_pytype)
446 #define ECINFO_EI(o) (&((ecinfo_pyobj *)(o))->ei)
447 #define ECINFO_COBJ(o) (((ecinfo_pyobj *)(o))->cobj)
448 extern void ecinfo_copy(ec_info *, const ec_info *);
449 extern PyObject *ecinfo_pywrap(ec_info *);
451 /*----- Cyclic groups -----------------------------------------------------*/
453 typedef struct fginfo_pyobj {
458 PyTypeObject *fginfo_pytype, *dhinfo_pytype, *bindhinfo_pytype;
459 #define FGINFO_DP(fg) (&((fginfo_pyobj *)(fg))->dp)
460 PyObject *fginfo_pywrap(gprime_param *, PyTypeObject *);
462 typedef struct ge_pyobj {
468 extern 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)
473 extern PyObject *ge_pywrap(PyObject *, ge *);
475 typedef struct group_pyobj {
480 extern PyTypeObject *group_pytype;
481 extern PyTypeObject *primegroup_pytype, *bingroup_pytype, *ecgroup_pytype;
482 #define GROUP_G(o) (((group_pyobj *)(o))->g)
483 extern PyObject *group_pywrap(group *);
484 extern group *group_copy(group *);
486 /*----- Random number generators ------------------------------------------*/
490 typedef struct grand_pyobj {
496 extern PyTypeObject *grand_pytype, *truerand_pytype;
497 extern PyTypeObject *lcrand_pytype,* fibrand_pytype;
498 extern PyTypeObject *dsarand_pytype, *bbs_pytype;
499 extern PyObject *rand_pyobj;
500 #define GRAND_PYCHECK(o) PyObject_TypeCheck((o), grand_pytype)
501 #define GRAND_F(o) (((grand_pyobj *)(o))->f)
502 #define GRAND_R(o) (((grand_pyobj *)(o))->r)
503 extern PyObject *grand_pywrap(grand *, unsigned);
504 extern int convgrand(PyObject *, void *);
506 /*----- Key sizes ---------------------------------------------------------*/
508 typedef struct keysz_pyobj {
513 typedef struct keyszrange_pyobj {
519 typedef struct keyszset_pyobj {
525 #define KEYSZ_PYCHECK(o) PyObject_TypeCheck((o), keysz_pytype)
526 extern PyObject *keysz_pywrap(const octet *);
528 /*----- Symmetric cryptography --------------------------------------------*/
530 typedef struct gccipher_pyobj {
535 extern PyTypeObject *gccipher_pytype;
536 #define GCCIPHER_PYCHECK(o) PyObject_TypeCheck((o), gccipher_pytype)
537 #define GCCIPHER_CC(o) (((gccipher_pyobj *)(o))->cc)
538 extern PyObject *gccipher_pywrap(gccipher *);
539 extern int convgccipher(PyObject *, void *);
541 typedef struct gcipher_pyobj {
546 extern PyTypeObject *gcipher_pytype;
547 #define GCIPHER_PYCHECK(o) PyObject_TypeCheck((o), gcipher_pytype)
548 #define GCIPHER_C(o) (((gcipher_pyobj *)(o))->c)
549 extern PyObject *gcipher_pywrap(PyObject *, gcipher *);
550 extern int convgcipher(PyObject *, void *);
552 typedef struct gcaead_pyobj {
555 struct gcaeadaad_pyobj *aad;
556 struct gcaeadenc_pyobj *enc;
557 struct gcaeaddec_pyobj *dec;
560 extern PyTypeObject *gcaead_pytype;
561 #define GCAEAD_PYCHECK(o) PyObject_TypeCheck((o), gcaead_pytype)
562 #define GCAEAD_AEC(o) (((gcaead_pyobj *)(o))->aec)
563 #define GCAEAD_AAD(o) (((gcaead_pyobj *)(o))->aad)
564 #define GCAEAD_ENC(o) (((gcaead_pyobj *)(o))->enc)
565 #define GCAEAD_DEC(o) (((gcaead_pyobj *)(o))->dec)
566 extern PyObject *gcaead_pywrap(gcaead *);
567 extern int convgcaead(PyObject *, void *);
569 typedef struct gaeadkey_pyobj {
574 extern PyTypeObject *gaeadkey_pytype;
575 #define GAEADKEY_PYCHECK(o) PyObject_TypeCheck((o), gaeadkey_pytype)
576 #define GAEADKEY_K(o) (((gaeadkey_pyobj *)(o))->k)
577 extern PyObject *gaeadkey_pywrap(PyObject *, gaead_key *);
578 extern int convgaeadkey(PyObject *, void *);
580 typedef struct gcaeadaad_pyobj {
584 #define GCAEADAAD_KEY(o) (((gcaeadaad_pyobj *)(o))->key)
585 extern PyTypeObject *gcaeadaad_pytype;
587 typedef struct gaeadaad_pyobj {
591 #define AEADF_DEAD 32768u
595 extern PyTypeObject *gaeadaad_pytype;
596 #define GAEADAAD_PYCHECK(o) PyObject_TypeCheck((o), gaeadaad_pytype)
597 #define GAEADAAD_A(o) (((gaeadaad_pyobj *)(o))->a)
598 #define GAEADAAD_F(o) (((gaeadaad_pyobj *)(o))->f)
599 #define GAEADAAD_HSZ(o) (((gaeadaad_pyobj *)(o))->hsz)
600 #define GAEADAAD_HLEN(o) (((gaeadaad_pyobj *)(o))->hlen)
601 extern PyObject *gaeadaad_pywrap(PyObject *, gaead_aad *, unsigned, size_t);
602 extern int convgaeadaad(PyObject *, void *);
604 typedef struct gcaeadenc_pyobj {
608 #define GCAEADENC_KEY(o) (((gcaeadenc_pyobj *)(o))->key)
609 extern PyTypeObject *gcaeadenc_pytype;
611 typedef struct gaeadenc_pyobj {
616 size_t hsz, msz, tsz;
620 extern PyTypeObject *gaeadenc_pytype;
621 #define GAEADENC_PYCHECK(o) PyObject_TypeCheck((o), gaeadenc_pytype)
622 #define GAEADENC_AAD(o) (((gaeadenc_pyobj *)(o))->aad)
623 #define GAEADENC_E(o) (((gaeadenc_pyobj *)(o))->e)
624 #define GAEADENC_F(o) (((gaeadenc_pyobj *)(o))->f)
625 #define GAEADENC_HSZ(o) (((gaeadenc_pyobj *)(o))->hsz)
626 #define GAEADENC_MSZ(o) (((gaeadenc_pyobj *)(o))->msz)
627 #define GAEADENC_TSZ(o) (((gaeadenc_pyobj *)(o))->tsz)
628 #define GAEADENC_MLEN(o) (((gaeadenc_pyobj *)(o))->mlen)
629 extern PyObject *gaeadenc_pywrap(PyObject *, gaead_enc *, unsigned,
630 size_t, size_t, size_t);
631 extern int convgaeadenc(PyObject *, void *);
633 typedef struct gcaeaddec_pyobj {
637 #define GCAEADDEC_KEY(o) (((gcaeaddec_pyobj *)(o))->key)
638 extern PyTypeObject *gcaeaddec_pytype;
640 typedef struct gaeaddec_pyobj {
645 size_t hsz, csz, tsz;
649 extern PyTypeObject *gaeaddec_pytype;
650 #define GAEADDEC_PYCHECK(o) PyObject_TypeCheck((o), gaeaddec_pytype)
651 #define GAEADDEC_AAD(o) (((gaeaddec_pyobj *)(o))->aad)
652 #define GAEADDEC_D(o) (((gaeaddec_pyobj *)(o))->d)
653 #define GAEADDEC_F(o) (((gaeaddec_pyobj *)(o))->f)
654 #define GAEADDEC_HSZ(o) (((gaeaddec_pyobj *)(o))->hsz)
655 #define GAEADDEC_CSZ(o) (((gaeaddec_pyobj *)(o))->csz)
656 #define GAEADDEC_TSZ(o) (((gaeaddec_pyobj *)(o))->tsz)
657 #define GAEADDEC_CLEN(o) (((gaeaddec_pyobj *)(o))->clen)
658 extern PyObject *gaeaddec_pywrap(PyObject *, gaead_dec *, unsigned,
659 size_t, size_t, size_t);
660 extern int convgaeaddec(PyObject *, void *);
662 typedef struct gchash_pyobj {
667 extern PyTypeObject *gchash_pytype;
668 #define GCHASH_PYCHECK(o) PyObject_TypeCheck((o), gchash_pytype)
669 #define GCHASH_CH(o) (((gchash_pyobj *)(o))->ch)
670 extern PyObject *gchash_pywrap(gchash *);
671 extern int convgchash(PyObject *, void *);
673 typedef struct ghash_pyobj {
678 extern PyTypeObject *ghash_pytype, *gmhash_pytype;
679 extern PyObject *sha_pyobj, *has160_pyobj;
680 #define GHASH_PYCHECK(o) PyObject_TypeCheck((o), ghash_pytype)
681 #define GHASH_H(o) (((ghash_pyobj *)(o))->h)
682 extern PyObject *ghash_pywrap(PyObject *, ghash *);
683 extern int convghash(PyObject *, void *);
684 extern int convgmhash(PyObject *, void *);
686 typedef struct gcmac_pyobj {
691 extern PyTypeObject *gcmac_pytype;
692 #define GCMAC_PYCHECK(o) PyObject_TypeCheck((o), gcmac_pytype)
693 #define GCMAC_CM(o) (((gcmac_pyobj *)(o))->cm)
694 #define GCMAC_F(o) (((gcmac_pyobj *)(o))->f)
695 extern PyObject *gcmac_pywrap(gcmac *);
696 extern int convgcmac(PyObject *, void *);
698 typedef struct gmac_pyobj {
703 extern PyTypeObject *gmac_pytype;
704 #define GMAC_PYCHECK(o) PyObject_TypeCheck((o), gmac_pytype)
705 #define GMAC_M(o) (((gmac_pyobj *)(o))->m)
706 #define GMAC_F(o) (((gmac_pyobj *)(o))->f)
707 extern PyObject *gmac_pywrap(PyObject *, gmac *);
708 extern int convgmac(PyObject *, void *);
710 /*----- Key generation ----------------------------------------------------*/
712 typedef struct pfilt_pyobj {
718 extern PyTypeObject *pfilt_pytype;
719 #define PFILT_PYCHECK(o) PyObject_TypeCheck(o, pfilt_pytype)
720 #define PFILT_F(o) (&((pfilt_pyobj *)(o))->f)
721 #define PFILT_ST(o) (((pfilt_pyobj *)(o))->st)
723 typedef struct { pgen_proc *proc; void *ctx; } pgev;
724 #define PGEV_HEAD PyObject_HEAD pgev pg;
726 typedef struct pgev_pyobj {
730 extern PyTypeObject *pgev_pytype;
731 #define PGEV_PYCHECK(o) PyObject_TypeCheck(o, pgev_pytype)
732 #define PGEV_PG(o) (&((pgev_pyobj *)(o))->pg)
734 typedef struct pypgev {
740 extern int convpgev(PyObject *, void *);
741 extern void droppgev(pypgev *);
742 extern void pgenerr(struct excinfo *exc);
744 /*----- That's all, folks -------------------------------------------------*/