Commit | Line | Data |
---|---|---|
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 *); | |
202 | MODULES(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 | ||
225 | struct nameval { const char *name; unsigned long value; }; | |
226 | extern void setconstants(PyObject *, const struct nameval *); | |
227 | ||
228 | extern 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 | ||
235 | extern int convulong(PyObject *, void *); | |
236 | #define DECL_CONVU_(n) extern int convu##n(PyObject *, void *); | |
237 | DOUINTSZ(DECL_CONVU_) | |
238 | extern int convmpw(PyObject *, void *); | |
239 | extern int convuint(PyObject *, void *); | |
240 | extern int convszt(PyObject *, void *); | |
241 | extern int convbool(PyObject *, void *); | |
242 | extern PyObject *abstract_pynew(PyTypeObject *, PyObject *, PyObject *); | |
243 | extern PyObject *getbool(int); | |
1e082a86 | 244 | extern PyObject *getulong(unsigned long); |
68ec53f3 MW |
245 | extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *); |
246 | ||
247 | extern PyObject * mkexc(PyObject *, PyObject *, const char *, PyMethodDef *); | |
248 | extern PyTypeObject *inittype(PyTypeObject *); | |
249 | extern void addmethods(const PyMethodDef *); | |
250 | extern 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 | ||
280 | GMAP_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) |
283 | extern int gmap_pysize(PyObject *); | |
284 | extern PySequenceMethods gmap_pysequence; | |
285 | extern PyMethodDef gmap_pymethods[]; | |
286 | ||
b6a86d2e | 287 | /*----- Bytestrings -------------------------------------------------------*/ |
288 | ||
289 | PyTypeObject *bytestring_pyobj; | |
290 | PyObject *bytestring_pywrap(const void *, size_t); | |
291 | PyObject *bytestring_pywrapbuf(buf *); | |
292 | ||
293 | /*----- Multiprecision arithmetic -----------------------------------------*/ | |
294 | ||
295 | typedef struct mp_pyobj { | |
296 | PyObject_HEAD | |
297 | mp *x; | |
298 | } mp_pyobj; | |
299 | ||
300 | extern PyTypeObject *mp_pytype; | |
301 | extern 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 |
306 | extern mp *mp_frompylong(PyObject *); |
307 | extern PyObject *mp_topylong(mp *); | |
b6a86d2e | 308 | extern mp *tomp(PyObject *); |
309 | extern mp *getmp(PyObject *); | |
310 | extern int convmp(PyObject *, void *); | |
311 | extern mp *getgf(PyObject *); | |
312 | extern int convgf(PyObject *, void *); | |
313 | extern PyObject *mp_pywrap(mp *); | |
314 | extern PyObject *gf_pywrap(mp *); | |
315 | extern mp *mp_frompyobject(PyObject *, int); | |
316 | extern PyObject *mp_topystring(mp *, int, | |
317 | const char *, const char *, const char *); | |
318 | extern int mp_tolong_checked(mp *, long *); | |
319 | ||
320 | /*----- Abstract fields ---------------------------------------------------*/ | |
321 | ||
322 | typedef struct field_pyobj { | |
f0526039 | 323 | PyHeapTypeObject ty; |
b6a86d2e | 324 | field *f; |
325 | } field_pyobj; | |
326 | ||
327 | extern 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) | |
332 | extern PyObject *fe_pywrap(PyObject *, mp *); | |
333 | extern mp *getfe(field *, PyObject *); | |
334 | ||
335 | typedef struct fe_pyobj { | |
336 | PyObject_HEAD | |
337 | field *f; | |
b6a86d2e | 338 | mp *x; |
339 | } fe_pyobj; | |
0b1eafbf | 340 | |
b6a86d2e | 341 | extern PyTypeObject *field_pytype; |
342 | extern PyTypeObject *primefield_pytype; | |
343 | extern PyTypeObject *niceprimefield_pytype; | |
344 | extern PyTypeObject *binfield_pytype; | |
345 | extern PyTypeObject *binpolyfield_pytype; | |
346 | extern PyTypeObject *binnormfield_pytype; | |
347 | #define FIELD_PYCHECK(o) PyObject_TypeCheck((o), field_pytype) | |
348 | #define FIELD_F(o) (((field_pyobj *)(o))->f) | |
349 | extern PyObject *field_pywrap(field *); | |
350 | extern field *field_copy(field *); | |
351 | ||
352 | /*----- Elliptic curves ---------------------------------------------------*/ | |
353 | ||
354 | typedef struct ecpt_pyobj { | |
355 | PyObject_HEAD | |
356 | ec_curve *c; | |
357 | ec p; | |
358 | } ecpt_pyobj; | |
359 | ||
360 | extern 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) | |
367 | extern PyObject *ecpt_pywrap(PyObject *, ec *); | |
368 | extern PyObject *ecpt_pywrapout(void *, ec *); | |
369 | extern int toecpt(ec_curve *, ec *, PyObject *); | |
370 | extern int getecpt(ec_curve *, ec *, PyObject *); | |
371 | extern void getecptout(ec *, PyObject *); | |
73a712fa | 372 | extern int convecpt(PyObject *, void *); |
b6a86d2e | 373 | |
374 | typedef struct eccurve_pyobj { | |
f0526039 | 375 | PyHeapTypeObject ty; |
b6a86d2e | 376 | ec_curve *c; |
377 | PyObject *fobj; | |
378 | } eccurve_pyobj; | |
379 | ||
380 | extern PyTypeObject *eccurve_pytype; | |
381 | extern PyTypeObject *ecprimecurve_pytype; | |
382 | extern PyTypeObject *ecprimeprojcurve_pytype; | |
383 | extern PyTypeObject *ecbincurve_pytype; | |
384 | extern 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) | |
388 | extern PyObject *eccurve_pywrap(PyObject *, ec_curve *); | |
389 | extern ec_curve *eccurve_copy(ec_curve *); | |
390 | ||
391 | typedef struct ecinfo_pyobj { | |
392 | PyObject_HEAD | |
393 | ec_info ei; | |
394 | PyObject *cobj; | |
395 | } ecinfo_pyobj; | |
0b1eafbf | 396 | |
b6a86d2e | 397 | extern 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) | |
401 | extern void ecinfo_copy(ec_info *, const ec_info *); | |
402 | extern PyObject *ecinfo_pywrap(ec_info *); | |
403 | ||
404 | /*----- Cyclic groups -----------------------------------------------------*/ | |
405 | ||
406 | typedef struct fginfo_pyobj { | |
407 | PyObject_HEAD | |
408 | gprime_param dp; | |
409 | } fginfo_pyobj; | |
410 | ||
411 | PyTypeObject *fginfo_pytype, *dhinfo_pytype, *bindhinfo_pytype; | |
412 | #define FGINFO_DP(fg) (&((fginfo_pyobj *)(fg))->dp) | |
413 | PyObject *fginfo_pywrap(gprime_param *, PyTypeObject *); | |
414 | ||
415 | typedef struct ge_pyobj { | |
416 | PyObject_HEAD | |
417 | ge *x; | |
418 | group *g; | |
419 | } ge_pyobj; | |
420 | ||
421 | extern 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) | |
426 | extern PyObject *ge_pywrap(PyObject *, ge *); | |
427 | ||
428 | typedef struct group_pyobj { | |
f0526039 | 429 | PyHeapTypeObject ty; |
b6a86d2e | 430 | group *g; |
431 | } group_pyobj; | |
432 | ||
433 | extern PyTypeObject *group_pytype; | |
434 | extern PyTypeObject *primegroup_pytype, *bingroup_pytype, *ecgroup_pytype; | |
435 | #define GROUP_G(o) (((group_pyobj *)(o))->g) | |
436 | extern PyObject *group_pywrap(group *); | |
437 | extern group *group_copy(group *); | |
438 | ||
439 | /*----- Random number generators ------------------------------------------*/ | |
440 | ||
441 | #define f_freeme 1u | |
442 | ||
443 | typedef struct grand_pyobj { | |
444 | PyObject_HEAD | |
445 | unsigned f; | |
446 | grand *r; | |
447 | } grand_pyobj; | |
448 | ||
449 | extern PyTypeObject *grand_pytype, *truerand_pytype; | |
450 | extern PyTypeObject *lcrand_pytype,* fibrand_pytype; | |
451 | extern PyTypeObject *dsarand_pytype, *bbs_pytype; | |
452 | extern 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) | |
456 | extern PyObject *grand_pywrap(grand *, unsigned); | |
457 | extern int convgrand(PyObject *, void *); | |
458 | ||
459 | /*----- Key sizes ---------------------------------------------------------*/ | |
460 | ||
461 | typedef struct keysz_pyobj { | |
462 | PyObject_HEAD | |
463 | int dfl; | |
464 | } keysz_pyobj; | |
465 | ||
466 | typedef struct keyszrange_pyobj { | |
467 | PyObject_HEAD | |
468 | int dfl; | |
469 | int min, max, mod; | |
470 | } keyszrange_pyobj; | |
471 | ||
472 | typedef 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) | |
479 | extern PyObject *keysz_pywrap(const octet *); | |
480 | ||
481 | /*----- Symmetric cryptography --------------------------------------------*/ | |
482 | ||
483 | typedef struct gccipher_pyobj { | |
f0526039 | 484 | PyHeapTypeObject ty; |
b6a86d2e | 485 | gccipher *cc; |
486 | } gccipher_pyobj; | |
487 | ||
488 | extern 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) | |
492 | extern PyObject *gccipher_pywrap(gccipher *); | |
493 | extern int convgccipher(PyObject *, void *); | |
494 | extern int convgcipher(PyObject *, void *); | |
495 | ||
496 | typedef struct gcipher_pyobj { | |
497 | PyObject_HEAD | |
498 | unsigned f; | |
499 | gcipher *c; | |
500 | } gcipher_pyobj; | |
501 | ||
502 | extern 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) | |
506 | extern PyObject *gcipher_pywrap(PyObject *, gcipher *, unsigned); | |
507 | extern int convgcipher(PyObject *, void *); | |
508 | ||
509 | typedef struct gchash_pyobj { | |
f0526039 | 510 | PyHeapTypeObject ty; |
b6a86d2e | 511 | gchash *ch; |
512 | } gchash_pyobj; | |
513 | ||
514 | extern 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) | |
518 | extern PyObject *gchash_pywrap(gchash *); | |
519 | extern int convgchash(PyObject *, void *); | |
520 | ||
521 | typedef struct ghash_pyobj { | |
522 | PyObject_HEAD | |
523 | unsigned f; | |
524 | ghash *h; | |
525 | } ghash_pyobj; | |
526 | ||
527 | extern PyTypeObject *ghash_pytype, *gmhash_pytype; | |
528 | extern 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) | |
532 | extern PyObject *ghash_pywrap(PyObject *, ghash *, unsigned); | |
533 | extern int convghash(PyObject *, void *); | |
534 | extern int convgmhash(PyObject *, void *); | |
535 | ||
536 | typedef struct gcmac_pyobj { | |
f0526039 | 537 | PyHeapTypeObject ty; |
b6a86d2e | 538 | gcmac *cm; |
539 | } gcmac_pyobj; | |
540 | ||
541 | extern 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) | |
545 | extern PyObject *gcmac_pywrap(gcmac *); | |
546 | extern int convgcmac(PyObject *, void *); | |
547 | ||
548 | typedef struct gmac_pyobj { | |
f0526039 | 549 | PyHeapTypeObject ty; |
b6a86d2e | 550 | unsigned f; |
551 | gmac *m; | |
b6a86d2e | 552 | } gmac_pyobj; |
553 | ||
554 | extern 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) |
558 | extern PyObject *gmac_pywrap(PyObject *, gmac *, unsigned); | |
559 | extern int convgmac(PyObject *, void *); | |
560 | ||
b6a86d2e | 561 | /*----- Key generation ----------------------------------------------------*/ |
0b1eafbf | 562 | |
b6a86d2e | 563 | typedef struct pfilt_pyobj { |
564 | PyObject_HEAD | |
565 | pfilt f; | |
566 | int st; | |
567 | } pfilt_pyobj; | |
568 | ||
569 | extern 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 | ||
574 | typedef struct { pgen_proc *proc; void *ctx; } pgev; | |
575 | #define PGEV_HEAD PyObject_HEAD pgev pg; | |
576 | ||
577 | typedef struct pgev_pyobj { | |
578 | PGEV_HEAD | |
579 | } pgev_pyobj; | |
580 | ||
581 | extern PyTypeObject *pgev_pytype; | |
582 | #define PGEV_PYCHECK(o) PyObject_TypeCheck(o, pgev_pytype) | |
583 | #define PGEV_PG(o) (&((pgev_pyobj *)(o))->pg) | |
584 | ||
585 | extern int convpgev(PyObject *, void *); | |
586 | extern void droppgev(pgev *); | |
587 | extern void pgenerr(void); | |
588 | ||
b6a86d2e | 589 | /*----- That's all, folks -------------------------------------------------*/ |
590 | ||
591 | #ifdef __cplusplus | |
592 | } | |
593 | #endif | |
594 | ||
595 | #endif |