Merge branch '1.2.x' into 1.3.x
[pyke] / catacomb-python.h
1 /* -*-c-*-
2 *
3 * Definitions for Catacomb bindings
4 *
5 * (c) 2004 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
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.
16 *
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.
21 *
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 #define PY_SSIZE_T_CLEAN
37
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>
45 #include <mLib/quis.h>
46 #include <mLib/unihash.h>
47
48 #include <catacomb/buf.h>
49 #include <catacomb/ct.h>
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>
61 #include <catacomb/blkc.h>
62
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>
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>
83 #include <catacomb/mp-fibonacci.h>
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>
93 #include <catacomb/x25519.h>
94 #include <catacomb/x448.h>
95 #include <catacomb/ed25519.h>
96 #include <catacomb/ed448.h>
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
120 #include <catacomb/share.h>
121 #include <catacomb/gfshare.h>
122
123 /*----- Utility macros ----------------------------------------------------*/
124
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)
131
132 #define EXCERR(exc, str) do { \
133 PyErr_SetString(exc, str); \
134 goto end; \
135 } while (0)
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); \
145 goto end; \
146 } while (0)
147 #define OSERR(name) do { \
148 PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); \
149 goto end; \
150 } while (0)
151 #define PGENERR(exc) do { pgenerr(exc); goto end; } while (0)
152
153 #define CONVFUNC(ty, cty, ext) \
154 int conv##ty(PyObject *o, void *p) \
155 { \
156 if (!PyObject_TypeCheck(o, ty##_pytype)) \
157 TYERR("wanted a " #ty); \
158 *(cty *)p = ext(o); \
159 return (1); \
160 end: \
161 return (0); \
162 }
163
164 #if PY_VERSION_HEX < 0x02050000 /* Compatibility hack */
165 # define ht_name name
166 # define ht_type type
167 #endif
168
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); \
174 } while (0)
175 #define INITTYPE(ty, base) INITTYPE_META(ty, base, type)
176
177 extern PyObject *home_module;
178
179 #define INSERT(name, ob) do { \
180 PyObject *_o = (PyObject *)(ob); \
181 Py_INCREF(_o); \
182 PyModule_AddObject(mod, name, _o); \
183 } while (0)
184
185 #define INSEXC(name, var, base, meth) \
186 INSERT(name, var = mkexc(mod, base, name, meth))
187
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 },
193
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 },
198
199 #define MEMBER(name, ty, f, doc) \
200 { #name, ty, offsetof(MEMBERSTRUCT, name), f, doc },
201
202 #define MODULES(_) \
203 _(util) \
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)
212
213 #define DO(m) \
214 extern void m##_pyinit(void); \
215 extern void m##_pyinsert(PyObject *);
216 MODULES(DO)
217 #undef DO
218
219 #define FREEOBJ(obj) \
220 (((PyObject *)(obj))->ob_type->tp_free((PyObject *)(obj)))
221
222 #define GEN(func, base) \
223 static PyObject *func(void) \
224 { \
225 PyObject *d = PyDict_New(); \
226 PyObject *o; \
227 int i; \
228 \
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, \
233 o); \
234 Py_DECREF(o); \
235 } \
236 return (d); \
237 }
238
239 #define KWLIST (/*unconst*/ char **)kwlist
240
241 struct nameval { const char *name; unsigned f; unsigned long value; };
242 #define CF_SIGNED 1u
243 extern void setconstants(PyObject *, const struct nameval *);
244
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 *));
251
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 *);
265
266 struct excinfo { PyObject *ty, *val, *tb; };
267 #define EXCINFO_INIT { 0, 0, 0 }
268
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; \
272 } while (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; \
278 } while (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); \
283 } while (0)
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; \
288 } while (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 *, ...);
293
294 extern void typeready(PyTypeObject *);
295 extern PyTypeObject *inittype(PyTypeObject *, PyTypeObject *);
296 extern void addmethods(const PyMethodDef *);
297 extern PyMethodDef *donemethods(void);
298
299 /*----- Mapping methods ---------------------------------------------------*/
300
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 *);
308
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") \
318
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)")
326
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[];
333
334 /*----- Bytestrings -------------------------------------------------------*/
335
336 PyTypeObject *bytestring_pyobj;
337 PyObject *bytestring_pywrap(const void *, size_t);
338 PyObject *bytestring_pywrapbuf(buf *);
339
340 /*----- Multiprecision arithmetic -----------------------------------------*/
341
342 typedef struct mp_pyobj {
343 PyObject_HEAD
344 mp *x;
345 } mp_pyobj;
346
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)
352
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);
367
368 /*----- Abstract fields ---------------------------------------------------*/
369
370 typedef struct field_pyobj {
371 PyHeapTypeObject ty;
372 field *f;
373 } field_pyobj;
374
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 *);
381
382 typedef struct fe_pyobj {
383 PyObject_HEAD
384 field *f;
385 mp *x;
386 } fe_pyobj;
387
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 *);
398
399 /*----- Elliptic curves ---------------------------------------------------*/
400
401 typedef struct ecpt_pyobj {
402 PyObject_HEAD
403 ec_curve *c;
404 ec p;
405 } ecpt_pyobj;
406
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 *);
420
421 typedef struct eccurve_pyobj {
422 PyHeapTypeObject ty;
423 ec_curve *c;
424 PyObject *fobj;
425 } eccurve_pyobj;
426
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 *);
437
438 typedef struct ecinfo_pyobj {
439 PyObject_HEAD
440 ec_info ei;
441 PyObject *cobj;
442 } ecinfo_pyobj;
443
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 *);
450
451 /*----- Cyclic groups -----------------------------------------------------*/
452
453 typedef struct fginfo_pyobj {
454 PyObject_HEAD
455 gprime_param dp;
456 } fginfo_pyobj;
457
458 PyTypeObject *fginfo_pytype, *dhinfo_pytype, *bindhinfo_pytype;
459 #define FGINFO_DP(fg) (&((fginfo_pyobj *)(fg))->dp)
460 PyObject *fginfo_pywrap(gprime_param *, PyTypeObject *);
461
462 typedef struct ge_pyobj {
463 PyObject_HEAD
464 ge *x;
465 group *g;
466 } ge_pyobj;
467
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 *);
474
475 typedef struct group_pyobj {
476 PyHeapTypeObject ty;
477 group *g;
478 } group_pyobj;
479
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 *);
485
486 /*----- Random number generators ------------------------------------------*/
487
488 #define f_freeme 1u
489
490 typedef struct grand_pyobj {
491 PyObject_HEAD
492 unsigned f;
493 grand *r;
494 } grand_pyobj;
495
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 *);
505
506 /*----- Key sizes ---------------------------------------------------------*/
507
508 typedef struct keysz_pyobj {
509 PyObject_HEAD
510 int dfl;
511 } keysz_pyobj;
512
513 typedef struct keyszrange_pyobj {
514 PyObject_HEAD
515 int dfl;
516 int min, max, mod;
517 } keyszrange_pyobj;
518
519 typedef struct keyszset_pyobj {
520 PyObject_HEAD
521 int dfl;
522 PyObject *set;
523 } keyszset_pyobj;
524
525 #define KEYSZ_PYCHECK(o) PyObject_TypeCheck((o), keysz_pytype)
526 extern PyObject *keysz_pywrap(const octet *);
527
528 /*----- Symmetric cryptography --------------------------------------------*/
529
530 typedef struct gccipher_pyobj {
531 PyHeapTypeObject ty;
532 gccipher *cc;
533 } gccipher_pyobj;
534
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 *);
540
541 typedef struct gcipher_pyobj {
542 PyObject_HEAD
543 gcipher *c;
544 } gcipher_pyobj;
545
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 *);
551
552 typedef struct gcaead_pyobj {
553 PyHeapTypeObject ty;
554 gcaead *aec;
555 struct gcaeadaad_pyobj *aad;
556 struct gcaeadenc_pyobj *enc;
557 struct gcaeaddec_pyobj *dec;
558 } gcaead_pyobj;
559
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 *);
568
569 typedef struct gaeadkey_pyobj {
570 PyObject_HEAD
571 gaead_key *k;
572 } gaeadkey_pyobj;
573
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 *);
579
580 typedef struct gcaeadaad_pyobj {
581 PyHeapTypeObject ty;
582 gcaead_pyobj *key;
583 } gcaeadaad_pyobj;
584 #define GCAEADAAD_KEY(o) (((gcaeadaad_pyobj *)(o))->key)
585 extern PyTypeObject *gcaeadaad_pytype;
586
587 typedef struct gaeadaad_pyobj {
588 PyObject_HEAD
589 gaead_aad *a;
590 unsigned f;
591 #define AEADF_DEAD 32768u
592 size_t hsz, hlen;
593 } gaeadaad_pyobj;
594
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 *);
603
604 typedef struct gcaeadenc_pyobj {
605 PyHeapTypeObject ty;
606 gcaead_pyobj *key;
607 } gcaeadenc_pyobj;
608 #define GCAEADENC_KEY(o) (((gcaeadenc_pyobj *)(o))->key)
609 extern PyTypeObject *gcaeadenc_pytype;
610
611 typedef struct gaeadenc_pyobj {
612 PyObject_HEAD
613 gaead_enc *e;
614 gaeadaad_pyobj *aad;
615 unsigned f;
616 size_t hsz, msz, tsz;
617 size_t mlen;
618 } gaeadenc_pyobj;
619
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 *);
632
633 typedef struct gcaeaddec_pyobj {
634 PyHeapTypeObject ty;
635 gcaead_pyobj *key;
636 } gcaeaddec_pyobj;
637 #define GCAEADDEC_KEY(o) (((gcaeaddec_pyobj *)(o))->key)
638 extern PyTypeObject *gcaeaddec_pytype;
639
640 typedef struct gaeaddec_pyobj {
641 PyObject_HEAD
642 gaead_dec *d;
643 gaeadaad_pyobj *aad;
644 unsigned f;
645 size_t hsz, csz, tsz;
646 size_t clen;
647 } gaeaddec_pyobj;
648
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 *);
661
662 typedef struct gchash_pyobj {
663 PyHeapTypeObject ty;
664 gchash *ch;
665 } gchash_pyobj;
666
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 *);
672
673 typedef struct ghash_pyobj {
674 PyObject_HEAD
675 ghash *h;
676 } ghash_pyobj;
677
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 *);
685
686 typedef struct gcmac_pyobj {
687 PyHeapTypeObject ty;
688 gcmac *cm;
689 } gcmac_pyobj;
690
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 *);
697
698 typedef struct gmac_pyobj {
699 PyHeapTypeObject ty;
700 gmac *m;
701 } gmac_pyobj;
702
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 *);
709
710 /*----- Key generation ----------------------------------------------------*/
711
712 typedef struct pfilt_pyobj {
713 PyObject_HEAD
714 pfilt f;
715 int st;
716 } pfilt_pyobj;
717
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)
722
723 typedef struct { pgen_proc *proc; void *ctx; } pgev;
724 #define PGEV_HEAD PyObject_HEAD pgev pg;
725
726 typedef struct pgev_pyobj {
727 PGEV_HEAD
728 } pgev_pyobj;
729
730 extern PyTypeObject *pgev_pytype;
731 #define PGEV_PYCHECK(o) PyObject_TypeCheck(o, pgev_pytype)
732 #define PGEV_PG(o) (&((pgev_pyobj *)(o))->pg)
733
734 typedef struct pypgev {
735 pgev ev;
736 PyObject *obj;
737 struct excinfo *exc;
738 } pypgev;
739
740 extern int convpgev(PyObject *, void *);
741 extern void droppgev(pypgev *);
742 extern void pgenerr(struct excinfo *exc);
743
744 /*----- That's all, folks -------------------------------------------------*/
745
746 #ifdef __cplusplus
747 }
748 #endif
749
750 #endif