Set ELF visibility to keep all of our external symbols to ourselves.
[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 /*----- 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
136 PRIVATE_SYMBOLS;
137
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)
152 #define TYERR(str) EXCERR(PyExc_TypeError, str)
153 #define IXERR(str) EXCERR(PyExc_IndexError, str)
154 #define ZDIVERR(str) EXCERR(PyExc_ZeroDivisionError, str)
155 #define SYSERR(str) EXCERR(PyExc_SystemError, str)
156 #define NIERR(str) EXCERR(PyExc_NotImplementedError, str)
157 #define INDEXERR(idx) do { \
158 PyErr_SetObject(PyExc_KeyError, idx); \
159 goto end; \
160 } while (0)
161 #define OSERR(name) do { \
162 PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); \
163 goto end; \
164 } while (0)
165 #define PGENERR do { pgenerr(); goto end; } while (0)
166
167 #define CONVFUNC(ty, cty, ext) \
168 int conv##ty(PyObject *o, void *p) \
169 { \
170 if (!PyObject_TypeCheck(o, ty##_pytype)) \
171 TYERR("wanted a " #ty); \
172 *(cty *)p = ext(o); \
173 return (1); \
174 end: \
175 return (0); \
176 }
177
178 #if PY_VERSION_HEX < 0x02050000 /* Compatibility hack */
179 # define ht_name name
180 # define ht_type type
181 #endif
182
183 #define root_pytype 0
184 #define type_pytype &PyType_Type
185 #define INITTYPE_META(ty, base, meta) do { \
186 ty##_pytype_skel.tp_base = base##_pytype; \
187 ty##_pytype = inittype(&ty##_pytype_skel, meta##_pytype); \
188 } while (0)
189 #define INITTYPE(ty, base) INITTYPE_META(ty, base, type)
190
191 #define INSERT(name, ob) do { \
192 PyObject *_o = (PyObject *)(ob); \
193 Py_INCREF(_o); \
194 PyModule_AddObject(mod, name, _o); \
195 } while (0)
196
197 #define INSEXC(name, var, base, meth) \
198 INSERT(name, var = mkexc(mod, base, name, meth))
199
200 #define METH(func, doc) \
201 { #func, METHNAME(func), METH_VARARGS, doc },
202 #define KWMETH(func, doc) \
203 { #func, (PyCFunction)METHNAME(func), \
204 METH_VARARGS | METH_KEYWORDS, doc },
205
206 #define GET(func, doc) \
207 { #func, GETSETNAME(get, func), 0, doc },
208 #define GETSET(func, doc) \
209 { #func, GETSETNAME(get, func), GETSETNAME(set, func), doc },
210
211 #define MEMBER(name, ty, f, doc) \
212 { #name, ty, offsetof(MEMBERSTRUCT, name), f, doc },
213
214 #define MODULES(_) \
215 _(util) \
216 _(bytestring) _(buffer) \
217 _(rand) _(algorithms) _(pubkey) _(pgen) \
218 _(mp) _(field) _(ec) _(group) \
219 _(passphrase) _(share) _(key)
220 #define DOMODINIT(m) m##_pyinit();
221 #define DOMODINSERT(m) m##_pyinsert(mod);
222 #define INIT_MODULES do { MODULES(DOMODINIT) } while (0)
223 #define INSERT_MODULES do { MODULES(DOMODINSERT) } while (0)
224
225 #define DO(m) \
226 extern void m##_pyinit(void); \
227 extern void m##_pyinsert(PyObject *);
228 MODULES(DO)
229 #undef DO
230
231 #define FREEOBJ(obj) \
232 (((PyObject *)(obj))->ob_type->tp_free((PyObject *)(obj)))
233
234 #define GEN(func, base) \
235 static PyObject *func(void) \
236 { \
237 PyObject *d = PyDict_New(); \
238 PyObject *o; \
239 int i; \
240 \
241 for (i = 0; g##base##tab[i]; i++) { \
242 o = gc##base##_pywrap((/*unconst*/ gc##base *)g##base##tab[i]); \
243 PyDict_SetItemString(d, \
244 (/*unconst*/ char *)g##base##tab[i]->name, \
245 o); \
246 Py_DECREF(o); \
247 } \
248 return (d); \
249 }
250
251 #define KWLIST (/*unconst*/ char **)kwlist
252
253 struct nameval { const char *name; unsigned long value; };
254 extern void setconstants(PyObject *, const struct nameval *);
255
256 extern PyObject *mexp_common(PyObject *, PyObject *, size_t,
257 PyObject *(*id)(PyObject *),
258 int (*fill)(void *, PyObject *,
259 PyObject *, PyObject *),
260 PyObject *(*exp)(PyObject *, void *, int),
261 void (*drop)(void *));
262
263 extern int convulong(PyObject *, void *);
264 #define DECL_CONVU_(n) extern int convu##n(PyObject *, void *);
265 DOUINTSZ(DECL_CONVU_)
266 extern int convmpw(PyObject *, void *);
267 extern int convuint(PyObject *, void *);
268 extern int convk64(PyObject *, void *);
269 extern int convszt(PyObject *, void *);
270 extern int convbool(PyObject *, void *);
271 extern PyObject *abstract_pynew(PyTypeObject *, PyObject *, PyObject *);
272 extern PyObject *getbool(int);
273 extern PyObject *getulong(unsigned long);
274 extern PyObject *getk64(kludge64);
275 extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *);
276
277 extern PyObject *mkexc(PyObject *, PyObject *, const char *, PyMethodDef *);
278 extern void typeready(PyTypeObject *);
279 extern PyTypeObject *inittype(PyTypeObject *, PyTypeObject *);
280 extern void addmethods(const PyMethodDef *);
281 extern PyMethodDef *donemethods(void);
282
283 /*----- Mapping methods ---------------------------------------------------*/
284
285 #define GMAP_METH(func, doc) { #func, gmapmeth_##func, METH_VARARGS, doc },
286 #define GMAP_KWMETH(func, doc) \
287 { #func, (PyCFunction)gmapmeth_##func, METH_VARARGS|METH_KEYWORDS, doc },
288 #define GMAP_METHDECL(func, doc) \
289 extern PyObject *gmapmeth_##func(PyObject *, PyObject *);
290 #define GMAP_KWMETHDECL(func, doc) \
291 extern PyObject *gmapmeth_##func(PyObject *, PyObject *, PyObject *);
292
293 #define GMAP_DOROMETHODS(METH, KWMETH) \
294 METH (has_key, "D.has_key(KEY) -> BOOL") \
295 METH (keys, "D.keys() -> LIST") \
296 METH (values, "D.values() -> LIST") \
297 METH (items, "D.items() -> LIST") \
298 METH (iterkeys, "D.iterkeys() -> ITER") \
299 METH (itervalues, "D.itervalues() -> ITER") \
300 METH (iteritems, "D.iteritems() -> ITER") \
301 KWMETH(get, "D.get(KEY, [default = None]) -> VALUE") \
302
303 #define GMAP_DOMETHODS(METH, KWMETH) \
304 GMAP_DOROMETHODS(METH, KWMETH) \
305 METH (clear, "D.clear()") \
306 KWMETH(setdefault, "D.setdefault(K, [default = None]) -> VALUE") \
307 KWMETH(pop, "D.pop(KEY, [default = <error>]) -> VALUE") \
308 METH (popitem, "D.popitem() -> (KEY, VALUE)") \
309 METH (update, "D.update(MAP)")
310
311 GMAP_DOMETHODS(GMAP_METHDECL, GMAP_KWMETHDECL)
312 #define GMAP_ROMETHODS GMAP_DOROMETHODS(GMAP_METH, GMAP_KWMETH)
313 #define GMAP_METHODS GMAP_DOMETHODS(GMAP_METH, GMAP_KWMETH)
314 extern Py_ssize_t gmap_pysize(PyObject *);
315 extern PySequenceMethods gmap_pysequence;
316 extern PyMethodDef gmap_pymethods[];
317
318 /*----- Bytestrings -------------------------------------------------------*/
319
320 PyTypeObject *bytestring_pyobj;
321 PyObject *bytestring_pywrap(const void *, size_t);
322 PyObject *bytestring_pywrapbuf(buf *);
323
324 /*----- Multiprecision arithmetic -----------------------------------------*/
325
326 typedef struct mp_pyobj {
327 PyObject_HEAD
328 mp *x;
329 } mp_pyobj;
330
331 extern PyTypeObject *mp_pytype;
332 extern PyTypeObject *gf_pytype;
333 #define MP_X(o) (((mp_pyobj *)(o))->x)
334 #define MP_PYCHECK(o) PyObject_TypeCheck((o), mp_pytype)
335 #define GF_PYCHECK(o) PyObject_TypeCheck((o), gf_pytype)
336
337 extern mp *mp_frompylong(PyObject *);
338 extern PyObject *mp_topylong(mp *);
339 extern mp *tomp(PyObject *);
340 extern mp *getmp(PyObject *);
341 extern int convmp(PyObject *, void *);
342 extern mp *getgf(PyObject *);
343 extern int convgf(PyObject *, void *);
344 extern PyObject *mp_pywrap(mp *);
345 extern PyObject *gf_pywrap(mp *);
346 extern mp *mp_frompyobject(PyObject *, int);
347 extern PyObject *mp_topystring(mp *, int,
348 const char *, const char *, const char *);
349 extern int mp_tolong_checked(mp *, long *, int);
350
351 /*----- Abstract fields ---------------------------------------------------*/
352
353 typedef struct field_pyobj {
354 PyHeapTypeObject ty;
355 field *f;
356 } field_pyobj;
357
358 extern PyTypeObject *fe_pytype;
359 #define FE_PYCHECK(o) PyObject_TypeCheck((o), fe_pytype)
360 #define FE_F(o) (((fe_pyobj *)(o))->f)
361 #define FE_FOBJ(o) ((PyObject *)(o)->ob_type)
362 #define FE_X(o) (((fe_pyobj *)(o))->x)
363 extern PyObject *fe_pywrap(PyObject *, mp *);
364 extern mp *getfe(field *, PyObject *);
365
366 typedef struct fe_pyobj {
367 PyObject_HEAD
368 field *f;
369 mp *x;
370 } fe_pyobj;
371
372 extern PyTypeObject *field_pytype;
373 extern PyTypeObject *primefield_pytype;
374 extern PyTypeObject *niceprimefield_pytype;
375 extern PyTypeObject *binfield_pytype;
376 extern PyTypeObject *binpolyfield_pytype;
377 extern PyTypeObject *binnormfield_pytype;
378 #define FIELD_PYCHECK(o) PyObject_TypeCheck((o), field_pytype)
379 #define FIELD_F(o) (((field_pyobj *)(o))->f)
380 extern PyObject *field_pywrap(field *);
381 extern field *field_copy(field *);
382
383 /*----- Elliptic curves ---------------------------------------------------*/
384
385 typedef struct ecpt_pyobj {
386 PyObject_HEAD
387 ec_curve *c;
388 ec p;
389 } ecpt_pyobj;
390
391 extern PyTypeObject *ecpt_pytype, *ecptcurve_pytype;
392 #define ECPT_PYCHECK(o) PyObject_TypeCheck((o), ecpt_pytype)
393 #define ECPTCURVE_PYCHECK(o) PyObject_TypeCheck((o), ecptcurve_pytype)
394 #define ECPT_C(o) (((ecpt_pyobj *)(o))->c)
395 #define ECPT_COBJ(o) ((PyObject *)(o)->ob_type)
396 #define ECPT_FOBJ(o) ECCURVE_FOBJ(ECPT_COBJ((o)))
397 #define ECPT_P(o) (&((ecpt_pyobj *)(o))->p)
398 extern PyObject *ecpt_pywrap(PyObject *, ec *);
399 extern PyObject *ecpt_pywrapout(void *, ec *);
400 extern int toecpt(ec_curve *, ec *, PyObject *);
401 extern int getecpt(ec_curve *, ec *, PyObject *);
402 extern void getecptout(ec *, PyObject *);
403 extern int convecpt(PyObject *, void *);
404
405 typedef struct eccurve_pyobj {
406 PyHeapTypeObject ty;
407 ec_curve *c;
408 PyObject *fobj;
409 } eccurve_pyobj;
410
411 extern PyTypeObject *eccurve_pytype;
412 extern PyTypeObject *ecprimecurve_pytype;
413 extern PyTypeObject *ecprimeprojcurve_pytype;
414 extern PyTypeObject *ecbincurve_pytype;
415 extern PyTypeObject *ecbinprojcurve_pytype;
416 #define ECCURVE_PYCHECK(o) PyObject_TypeCheck((o), eccurve_pytype)
417 #define ECCURVE_C(o) (((eccurve_pyobj *)(o))->c)
418 #define ECCURVE_FOBJ(o) (((eccurve_pyobj *)(o))->fobj)
419 extern PyObject *eccurve_pywrap(PyObject *, ec_curve *);
420 extern ec_curve *eccurve_copy(ec_curve *);
421
422 typedef struct ecinfo_pyobj {
423 PyObject_HEAD
424 ec_info ei;
425 PyObject *cobj;
426 } ecinfo_pyobj;
427
428 extern PyTypeObject *ecinfo_pytype;
429 #define ECINFO_PYCHECK(o) PyObject_TypeCheck((o), ecinfo_pytype)
430 #define ECINFO_EI(o) (&((ecinfo_pyobj *)(o))->ei)
431 #define ECINFO_COBJ(o) (((ecinfo_pyobj *)(o))->cobj)
432 extern void ecinfo_copy(ec_info *, const ec_info *);
433 extern PyObject *ecinfo_pywrap(ec_info *);
434
435 /*----- Cyclic groups -----------------------------------------------------*/
436
437 typedef struct fginfo_pyobj {
438 PyObject_HEAD
439 gprime_param dp;
440 } fginfo_pyobj;
441
442 PyTypeObject *fginfo_pytype, *dhinfo_pytype, *bindhinfo_pytype;
443 #define FGINFO_DP(fg) (&((fginfo_pyobj *)(fg))->dp)
444 PyObject *fginfo_pywrap(gprime_param *, PyTypeObject *);
445
446 typedef struct ge_pyobj {
447 PyObject_HEAD
448 ge *x;
449 group *g;
450 } ge_pyobj;
451
452 extern PyTypeObject *ge_pytype;
453 #define GE_PYCHECK(o) PyObject_TypeCheck((o), ge_pytype)
454 #define GE_X(o) (((ge_pyobj *)(o))->x)
455 #define GE_G(o) (((ge_pyobj *)(o))->g)
456 #define GE_GOBJ(o) ((PyObject *)(group_pyobj *)(o)->ob_type)
457 extern PyObject *ge_pywrap(PyObject *, ge *);
458
459 typedef struct group_pyobj {
460 PyHeapTypeObject ty;
461 group *g;
462 } group_pyobj;
463
464 extern PyTypeObject *group_pytype;
465 extern PyTypeObject *primegroup_pytype, *bingroup_pytype, *ecgroup_pytype;
466 #define GROUP_G(o) (((group_pyobj *)(o))->g)
467 extern PyObject *group_pywrap(group *);
468 extern group *group_copy(group *);
469
470 /*----- Random number generators ------------------------------------------*/
471
472 #define f_freeme 1u
473
474 typedef struct grand_pyobj {
475 PyObject_HEAD
476 unsigned f;
477 grand *r;
478 } grand_pyobj;
479
480 extern PyTypeObject *grand_pytype, *truerand_pytype;
481 extern PyTypeObject *lcrand_pytype,* fibrand_pytype;
482 extern PyTypeObject *dsarand_pytype, *bbs_pytype;
483 extern PyObject *rand_pyobj;
484 #define GRAND_PYCHECK(o) PyObject_TypeCheck((o), grand_pytype)
485 #define GRAND_F(o) (((grand_pyobj *)(o))->f)
486 #define GRAND_R(o) (((grand_pyobj *)(o))->r)
487 extern PyObject *grand_pywrap(grand *, unsigned);
488 extern int convgrand(PyObject *, void *);
489
490 /*----- Key sizes ---------------------------------------------------------*/
491
492 typedef struct keysz_pyobj {
493 PyObject_HEAD
494 int dfl;
495 } keysz_pyobj;
496
497 typedef struct keyszrange_pyobj {
498 PyObject_HEAD
499 int dfl;
500 int min, max, mod;
501 } keyszrange_pyobj;
502
503 typedef struct keyszset_pyobj {
504 PyObject_HEAD
505 int dfl;
506 PyObject *set;
507 } keyszset_pyobj;
508
509 #define KEYSZ_PYCHECK(o) PyObject_TypeCheck((o), keysz_pytype)
510 extern PyObject *keysz_pywrap(const octet *);
511
512 /*----- Symmetric cryptography --------------------------------------------*/
513
514 typedef struct gccipher_pyobj {
515 PyHeapTypeObject ty;
516 gccipher *cc;
517 } gccipher_pyobj;
518
519 extern PyTypeObject *gccipher_pytype;
520 #define GCCIPHER_PYCHECK(o) PyObject_TypeCheck((o), gccipher_pytype)
521 #define GCCIPHER_CC(o) (((gccipher_pyobj *)(o))->cc)
522 extern PyObject *gccipher_pywrap(gccipher *);
523 extern int convgccipher(PyObject *, void *);
524
525 typedef struct gcipher_pyobj {
526 PyObject_HEAD
527 gcipher *c;
528 } gcipher_pyobj;
529
530 extern PyTypeObject *gcipher_pytype;
531 #define GCIPHER_PYCHECK(o) PyObject_TypeCheck((o), gcipher_pytype)
532 #define GCIPHER_C(o) (((gcipher_pyobj *)(o))->c)
533 extern PyObject *gcipher_pywrap(PyObject *, gcipher *);
534 extern int convgcipher(PyObject *, void *);
535
536 typedef struct gcaead_pyobj {
537 PyHeapTypeObject ty;
538 gcaead *aec;
539 struct gcaeadaad_pyobj *aad;
540 struct gcaeadenc_pyobj *enc;
541 struct gcaeaddec_pyobj *dec;
542 } gcaead_pyobj;
543
544 extern PyTypeObject *gcaead_pytype;
545 #define GCAEAD_PYCHECK(o) PyObject_TypeCheck((o), gcaead_pytype)
546 #define GCAEAD_AEC(o) (((gcaead_pyobj *)(o))->aec)
547 #define GCAEAD_AAD(o) (((gcaead_pyobj *)(o))->aad)
548 #define GCAEAD_ENC(o) (((gcaead_pyobj *)(o))->enc)
549 #define GCAEAD_DEC(o) (((gcaead_pyobj *)(o))->dec)
550 extern PyObject *gcaead_pywrap(gcaead *);
551 extern int convgcaead(PyObject *, void *);
552
553 typedef struct gaeadkey_pyobj {
554 PyObject_HEAD
555 gaead_key *k;
556 } gaeadkey_pyobj;
557
558 extern PyTypeObject *gaeadkey_pytype;
559 #define GAEADKEY_PYCHECK(o) PyObject_TypeCheck((o), gaeadkey_pytype)
560 #define GAEADKEY_K(o) (((gaeadkey_pyobj *)(o))->k)
561 extern PyObject *gaeadkey_pywrap(PyObject *, gaead_key *);
562 extern int convgaeadkey(PyObject *, void *);
563
564 typedef struct gcaeadaad_pyobj {
565 PyHeapTypeObject ty;
566 gcaead_pyobj *key;
567 } gcaeadaad_pyobj;
568 #define GCAEADAAD_KEY(o) (((gcaeadaad_pyobj *)(o))->key)
569 extern PyTypeObject *gcaeadaad_pytype;
570
571 typedef struct gaeadaad_pyobj {
572 PyObject_HEAD
573 gaead_aad *a;
574 unsigned f;
575 #define AEADF_DEAD 32768u
576 size_t hsz, hlen;
577 } gaeadaad_pyobj;
578
579 extern PyTypeObject *gaeadaad_pytype;
580 #define GAEADAAD_PYCHECK(o) PyObject_TypeCheck((o), gaeadaad_pytype)
581 #define GAEADAAD_A(o) (((gaeadaad_pyobj *)(o))->a)
582 #define GAEADAAD_F(o) (((gaeadaad_pyobj *)(o))->f)
583 #define GAEADAAD_HSZ(o) (((gaeadaad_pyobj *)(o))->hsz)
584 #define GAEADAAD_HLEN(o) (((gaeadaad_pyobj *)(o))->hlen)
585 extern PyObject *gaeadaad_pywrap(PyObject *, gaead_aad *, unsigned, size_t);
586 extern int convgaeadaad(PyObject *, void *);
587
588 typedef struct gcaeadenc_pyobj {
589 PyHeapTypeObject ty;
590 gcaead_pyobj *key;
591 } gcaeadenc_pyobj;
592 #define GCAEADENC_KEY(o) (((gcaeadenc_pyobj *)(o))->key)
593 extern PyTypeObject *gcaeadenc_pytype;
594
595 typedef struct gaeadenc_pyobj {
596 PyObject_HEAD
597 gaead_enc *e;
598 gaeadaad_pyobj *aad;
599 unsigned f;
600 size_t hsz, msz, tsz;
601 size_t mlen;
602 } gaeadenc_pyobj;
603
604 extern PyTypeObject *gaeadenc_pytype;
605 #define GAEADENC_PYCHECK(o) PyObject_TypeCheck((o), gaeadenc_pytype)
606 #define GAEADENC_AAD(o) (((gaeadenc_pyobj *)(o))->aad)
607 #define GAEADENC_E(o) (((gaeadenc_pyobj *)(o))->e)
608 #define GAEADENC_F(o) (((gaeadenc_pyobj *)(o))->f)
609 #define GAEADENC_HSZ(o) (((gaeadenc_pyobj *)(o))->hsz)
610 #define GAEADENC_MSZ(o) (((gaeadenc_pyobj *)(o))->msz)
611 #define GAEADENC_TSZ(o) (((gaeadenc_pyobj *)(o))->tsz)
612 #define GAEADENC_MLEN(o) (((gaeadenc_pyobj *)(o))->mlen)
613 extern PyObject *gaeadenc_pywrap(PyObject *, gaead_enc *, unsigned,
614 size_t, size_t, size_t);
615 extern int convgaeadenc(PyObject *, void *);
616
617 typedef struct gcaeaddec_pyobj {
618 PyHeapTypeObject ty;
619 gcaead_pyobj *key;
620 } gcaeaddec_pyobj;
621 #define GCAEADDEC_KEY(o) (((gcaeaddec_pyobj *)(o))->key)
622 extern PyTypeObject *gcaeaddec_pytype;
623
624 typedef struct gaeaddec_pyobj {
625 PyObject_HEAD
626 gaead_dec *d;
627 gaeadaad_pyobj *aad;
628 unsigned f;
629 size_t hsz, csz, tsz;
630 size_t clen;
631 } gaeaddec_pyobj;
632
633 extern PyTypeObject *gaeaddec_pytype;
634 #define GAEADDEC_PYCHECK(o) PyObject_TypeCheck((o), gaeaddec_pytype)
635 #define GAEADDEC_AAD(o) (((gaeaddec_pyobj *)(o))->aad)
636 #define GAEADDEC_D(o) (((gaeaddec_pyobj *)(o))->d)
637 #define GAEADDEC_F(o) (((gaeaddec_pyobj *)(o))->f)
638 #define GAEADDEC_HSZ(o) (((gaeaddec_pyobj *)(o))->hsz)
639 #define GAEADDEC_CSZ(o) (((gaeaddec_pyobj *)(o))->csz)
640 #define GAEADDEC_TSZ(o) (((gaeaddec_pyobj *)(o))->tsz)
641 #define GAEADDEC_CLEN(o) (((gaeaddec_pyobj *)(o))->clen)
642 extern PyObject *gaeaddec_pywrap(PyObject *, gaead_dec *, unsigned,
643 size_t, size_t, size_t);
644 extern int convgaeaddec(PyObject *, void *);
645
646 typedef struct gchash_pyobj {
647 PyHeapTypeObject ty;
648 gchash *ch;
649 } gchash_pyobj;
650
651 extern PyTypeObject *gchash_pytype;
652 #define GCHASH_PYCHECK(o) PyObject_TypeCheck((o), gchash_pytype)
653 #define GCHASH_CH(o) (((gchash_pyobj *)(o))->ch)
654 extern PyObject *gchash_pywrap(gchash *);
655 extern int convgchash(PyObject *, void *);
656
657 typedef struct ghash_pyobj {
658 PyObject_HEAD
659 ghash *h;
660 } ghash_pyobj;
661
662 extern PyTypeObject *ghash_pytype, *gmhash_pytype;
663 extern PyObject *sha_pyobj, *has160_pyobj;
664 #define GHASH_PYCHECK(o) PyObject_TypeCheck((o), ghash_pytype)
665 #define GHASH_H(o) (((ghash_pyobj *)(o))->h)
666 extern PyObject *ghash_pywrap(PyObject *, ghash *);
667 extern int convghash(PyObject *, void *);
668 extern int convgmhash(PyObject *, void *);
669
670 typedef struct gcmac_pyobj {
671 PyHeapTypeObject ty;
672 gcmac *cm;
673 } gcmac_pyobj;
674
675 extern PyTypeObject *gcmac_pytype;
676 #define GCMAC_PYCHECK(o) PyObject_TypeCheck((o), gcmac_pytype)
677 #define GCMAC_CM(o) (((gcmac_pyobj *)(o))->cm)
678 #define GCMAC_F(o) (((gcmac_pyobj *)(o))->f)
679 extern PyObject *gcmac_pywrap(gcmac *);
680 extern int convgcmac(PyObject *, void *);
681
682 typedef struct gmac_pyobj {
683 PyHeapTypeObject ty;
684 gmac *m;
685 } gmac_pyobj;
686
687 extern PyTypeObject *gmac_pytype;
688 #define GMAC_PYCHECK(o) PyObject_TypeCheck((o), gmac_pytype)
689 #define GMAC_M(o) (((gmac_pyobj *)(o))->m)
690 #define GMAC_F(o) (((gmac_pyobj *)(o))->f)
691 extern PyObject *gmac_pywrap(PyObject *, gmac *);
692 extern int convgmac(PyObject *, void *);
693
694 /*----- Key generation ----------------------------------------------------*/
695
696 typedef struct pfilt_pyobj {
697 PyObject_HEAD
698 pfilt f;
699 int st;
700 } pfilt_pyobj;
701
702 extern PyTypeObject *pfilt_pytype;
703 #define PFILT_PYCHECK(o) PyObject_TypeCheck(o, pfilt_pytype)
704 #define PFILT_F(o) (&((pfilt_pyobj *)(o))->f)
705 #define PFILT_ST(o) (((pfilt_pyobj *)(o))->st)
706
707 typedef struct { pgen_proc *proc; void *ctx; } pgev;
708 #define PGEV_HEAD PyObject_HEAD pgev pg;
709
710 typedef struct pgev_pyobj {
711 PGEV_HEAD
712 } pgev_pyobj;
713
714 extern PyTypeObject *pgev_pytype;
715 #define PGEV_PYCHECK(o) PyObject_TypeCheck(o, pgev_pytype)
716 #define PGEV_PG(o) (&((pgev_pyobj *)(o))->pg)
717
718 extern int convpgev(PyObject *, void *);
719 extern void droppgev(pgev *);
720 extern void pgenerr(void);
721
722 /*----- That's all, folks -------------------------------------------------*/
723
724 #ifdef __cplusplus
725 }
726 #endif
727
728 #endif