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 | ||
ad84d8c2 MW |
36 | #define PY_SSIZE_T_CLEAN |
37 | ||
b6a86d2e | 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> | |
73a712fa | 45 | #include <mLib/quis.h> |
b06387d2 | 46 | #include <mLib/unihash.h> |
b6a86d2e | 47 | |
48 | #include <catacomb/buf.h> | |
54ecf9dd | 49 | #include <catacomb/ct.h> |
b6a86d2e | 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> | |
62058916 | 61 | #include <catacomb/blkc.h> |
b6a86d2e | 62 | |
63 | #include <catacomb/gcipher.h> | |
54ae5879 | 64 | #include <catacomb/gaead.h> |
b6a86d2e | 65 | #include <catacomb/ghash.h> |
66 | #include <catacomb/gmac.h> | |
67 | #include <catacomb/md5.h> | |
68 | #include <catacomb/md5-hmac.h> | |
2ad160b1 | 69 | #include <catacomb/poly1305.h> |
b6a86d2e | 70 | #include <catacomb/sha.h> |
71 | #include <catacomb/sha-mgf.h> | |
72 | #include <catacomb/sha-hmac.h> | |
f85a7079 | 73 | #include <catacomb/keccak1600.h> |
b75462e8 | 74 | #include <catacomb/sha3.h> |
b6a86d2e | 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> | |
9c034c56 | 83 | #include <catacomb/mp-fibonacci.h> |
b6a86d2e | 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> | |
d223dc6b | 93 | #include <catacomb/x25519.h> |
51f4de84 | 94 | #include <catacomb/x448.h> |
70ed69c4 | 95 | #include <catacomb/ed25519.h> |
aa53a95f | 96 | #include <catacomb/ed448.h> |
b6a86d2e | 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 | ||
73a712fa | 120 | #include <catacomb/share.h> |
121 | #include <catacomb/gfshare.h> | |
122 | ||
26a7f37a MW |
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 | ||
b6a86d2e | 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) | |
c6b05f1f | 152 | #define OVFERR(str) EXCERR(PyExc_OverflowError, str) |
b6a86d2e | 153 | #define TYERR(str) EXCERR(PyExc_TypeError, str) |
ca473903 | 154 | #define IXERR(str) EXCERR(PyExc_IndexError, str) |
b6a86d2e | 155 | #define ZDIVERR(str) EXCERR(PyExc_ZeroDivisionError, str) |
b6a86d2e | 156 | #define SYSERR(str) EXCERR(PyExc_SystemError, str) |
68ec53f3 | 157 | #define NIERR(str) EXCERR(PyExc_NotImplementedError, str) |
73a712fa | 158 | #define INDEXERR(idx) do { \ |
159 | PyErr_SetObject(PyExc_KeyError, idx); \ | |
160 | goto end; \ | |
161 | } while (0) | |
b6a86d2e | 162 | #define OSERR(name) do { \ |
163 | PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); \ | |
164 | goto end; \ | |
165 | } while (0) | |
87aa2e3c | 166 | #define PGENERR(exc) do { pgenerr(exc); goto end; } while (0) |
b6a86d2e | 167 | |
168 | #define CONVFUNC(ty, cty, ext) \ | |
169 | int conv##ty(PyObject *o, void *p) \ | |
170 | { \ | |
171 | if (!PyObject_TypeCheck(o, ty##_pytype)) \ | |
172 | TYERR("wanted a " #ty); \ | |
173 | *(cty *)p = ext(o); \ | |
174 | return (1); \ | |
175 | end: \ | |
176 | return (0); \ | |
177 | } | |
178 | ||
179 | #define root_pytype 0 | |
180 | #define type_pytype &PyType_Type | |
017d5f65 | 181 | #define INITTYPE_META(ty, base, meta) do { \ |
b6a86d2e | 182 | ty##_pytype_skel.tp_base = base##_pytype; \ |
017d5f65 | 183 | ty##_pytype = inittype(&ty##_pytype_skel, meta##_pytype); \ |
b6a86d2e | 184 | } while (0) |
017d5f65 | 185 | #define INITTYPE(ty, base) INITTYPE_META(ty, base, type) |
b6a86d2e | 186 | |
87aa2e3c | 187 | extern PyObject *home_module; |
c6a36308 | 188 | extern PyObject *modname; |
87aa2e3c MW |
189 | |
190 | #define INSERT(name, ob) do { \ | |
b6a86d2e | 191 | PyObject *_o = (PyObject *)(ob); \ |
0b1eafbf | 192 | Py_INCREF(_o); \ |
b6a86d2e | 193 | PyModule_AddObject(mod, name, _o); \ |
194 | } while (0) | |
195 | ||
73a712fa | 196 | #define INSEXC(name, var, base, meth) \ |
197 | INSERT(name, var = mkexc(mod, base, name, meth)) | |
198 | ||
b6a86d2e | 199 | #define METH(func, doc) \ |
200 | { #func, METHNAME(func), METH_VARARGS, doc }, | |
201 | #define KWMETH(func, doc) \ | |
202 | { #func, (PyCFunction)METHNAME(func), \ | |
203 | METH_VARARGS | METH_KEYWORDS, doc }, | |
204 | ||
205 | #define GET(func, doc) \ | |
206 | { #func, GETSETNAME(get, func), 0, doc }, | |
207 | #define GETSET(func, doc) \ | |
208 | { #func, GETSETNAME(get, func), GETSETNAME(set, func), doc }, | |
209 | ||
210 | #define MEMBER(name, ty, f, doc) \ | |
211 | { #name, ty, offsetof(MEMBERSTRUCT, name), f, doc }, | |
212 | ||
73a712fa | 213 | #define MODULES(_) \ |
dfe0a897 | 214 | _(util) \ |
73a712fa | 215 | _(bytestring) _(buffer) \ |
216 | _(rand) _(algorithms) _(pubkey) _(pgen) \ | |
217 | _(mp) _(field) _(ec) _(group) \ | |
dfe0a897 | 218 | _(passphrase) _(share) _(key) |
b6a86d2e | 219 | #define DOMODINIT(m) m##_pyinit(); |
220 | #define DOMODINSERT(m) m##_pyinsert(mod); | |
221 | #define INIT_MODULES do { MODULES(DOMODINIT) } while (0) | |
222 | #define INSERT_MODULES do { MODULES(DOMODINSERT) } while (0) | |
223 | ||
224 | #define DO(m) \ | |
225 | extern void m##_pyinit(void); \ | |
226 | extern void m##_pyinsert(PyObject *); | |
227 | MODULES(DO) | |
228 | #undef DO | |
229 | ||
ba45a729 | 230 | #define FREEOBJ(obj) \ |
231 | (((PyObject *)(obj))->ob_type->tp_free((PyObject *)(obj))) | |
232 | ||
68ec53f3 MW |
233 | #define GEN(func, base) \ |
234 | static PyObject *func(void) \ | |
235 | { \ | |
236 | PyObject *d = PyDict_New(); \ | |
237 | PyObject *o; \ | |
238 | int i; \ | |
239 | \ | |
240 | for (i = 0; g##base##tab[i]; i++) { \ | |
241 | o = gc##base##_pywrap((/*unconst*/ gc##base *)g##base##tab[i]); \ | |
242 | PyDict_SetItemString(d, \ | |
243 | (/*unconst*/ char *)g##base##tab[i]->name, \ | |
244 | o); \ | |
245 | Py_DECREF(o); \ | |
246 | } \ | |
247 | return (d); \ | |
248 | } | |
249 | ||
0fed227d MW |
250 | #define KWLIST (/*unconst*/ char **)kwlist |
251 | ||
2ec562f1 MW |
252 | struct nameval { const char *name; unsigned f; unsigned long value; }; |
253 | #define CF_SIGNED 1u | |
68ec53f3 MW |
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 *); | |
1b6734b6 | 268 | extern int convk64(PyObject *, void *); |
68ec53f3 MW |
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); | |
1e082a86 | 273 | extern PyObject *getulong(unsigned long); |
1b6734b6 | 274 | extern PyObject *getk64(kludge64); |
68ec53f3 MW |
275 | extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *); |
276 | ||
87aa2e3c MW |
277 | struct excinfo { PyObject *ty, *val, *tb; }; |
278 | #define EXCINFO_INIT { 0, 0, 0 } | |
279 | ||
d2421f3c | 280 | extern PyObject *mkexc(PyObject *, PyObject *, const char *, PyMethodDef *); |
87aa2e3c MW |
281 | #define INIT_EXCINFO(exc) do { \ |
282 | struct excinfo *_exc = (exc); _exc->ty = _exc->val = _exc->tb = 0; \ | |
283 | } while (0) | |
284 | #define RELEASE_EXCINFO(exc) do { \ | |
285 | struct excinfo *_exc = (exc); \ | |
286 | Py_XDECREF(_exc->ty); _exc->ty = 0; \ | |
287 | Py_XDECREF(_exc->val); _exc->val = 0; \ | |
288 | Py_XDECREF(_exc->tb); _exc->tb = 0; \ | |
289 | } while (0) | |
290 | #define STASH_EXCINFO(exc) do { \ | |
291 | struct excinfo *_exc = (exc); \ | |
292 | PyErr_Fetch(&_exc->ty, &_exc->val, &_exc->tb); \ | |
293 | PyErr_NormalizeException(&_exc->ty, &_exc->val, &_exc->tb); \ | |
294 | } while (0) | |
295 | #define RESTORE_EXCINFO(exc) do { \ | |
296 | struct excinfo *_exc = (exc); \ | |
297 | PyErr_Restore(_exc->ty, _exc->val, _exc->tb); \ | |
298 | _exc->ty = _exc->val = _exc->tb = 0; \ | |
299 | } while (0) | |
300 | extern void report_lost_exception(struct excinfo *, const char *, ...); | |
301 | extern void report_lost_exception_v(struct excinfo *, const char *, va_list); | |
302 | extern void stash_exception(struct excinfo *, const char *, ...); | |
303 | extern void restore_exception(struct excinfo *, const char *, ...); | |
304 | ||
0156e402 | 305 | extern void typeready(PyTypeObject *); |
017d5f65 | 306 | extern PyTypeObject *inittype(PyTypeObject *, PyTypeObject *); |
68ec53f3 MW |
307 | extern void addmethods(const PyMethodDef *); |
308 | extern PyMethodDef *donemethods(void); | |
309 | ||
310 | /*----- Mapping methods ---------------------------------------------------*/ | |
311 | ||
312 | #define GMAP_METH(func, doc) { #func, gmapmeth_##func, METH_VARARGS, doc }, | |
313 | #define GMAP_KWMETH(func, doc) \ | |
314 | { #func, (PyCFunction)gmapmeth_##func, METH_VARARGS|METH_KEYWORDS, doc }, | |
315 | #define GMAP_METHDECL(func, doc) \ | |
316 | extern PyObject *gmapmeth_##func(PyObject *, PyObject *); | |
317 | #define GMAP_KWMETHDECL(func, doc) \ | |
318 | extern PyObject *gmapmeth_##func(PyObject *, PyObject *, PyObject *); | |
319 | ||
2a509510 | 320 | #define GMAP_DOROMETHODS(METH, KWMETH) \ |
68ec53f3 MW |
321 | METH (has_key, "D.has_key(KEY) -> BOOL") \ |
322 | METH (keys, "D.keys() -> LIST") \ | |
323 | METH (values, "D.values() -> LIST") \ | |
324 | METH (items, "D.items() -> LIST") \ | |
325 | METH (iterkeys, "D.iterkeys() -> ITER") \ | |
326 | METH (itervalues, "D.itervalues() -> ITER") \ | |
0b1eafbf | 327 | METH (iteritems, "D.iteritems() -> ITER") \ |
68ec53f3 | 328 | KWMETH(get, "D.get(KEY, [default = None]) -> VALUE") \ |
2a509510 MW |
329 | |
330 | #define GMAP_DOMETHODS(METH, KWMETH) \ | |
331 | GMAP_DOROMETHODS(METH, KWMETH) \ | |
332 | METH (clear, "D.clear()") \ | |
68ec53f3 MW |
333 | KWMETH(setdefault, "D.setdefault(K, [default = None]) -> VALUE") \ |
334 | KWMETH(pop, "D.pop(KEY, [default = <error>]) -> VALUE") \ | |
335 | METH (popitem, "D.popitem() -> (KEY, VALUE)") \ | |
336 | METH (update, "D.update(MAP)") | |
337 | ||
338 | GMAP_DOMETHODS(GMAP_METHDECL, GMAP_KWMETHDECL) | |
2a509510 | 339 | #define GMAP_ROMETHODS GMAP_DOROMETHODS(GMAP_METH, GMAP_KWMETH) |
68ec53f3 | 340 | #define GMAP_METHODS GMAP_DOMETHODS(GMAP_METH, GMAP_KWMETH) |
9d73ed80 | 341 | extern Py_ssize_t gmap_pysize(PyObject *); |
68ec53f3 MW |
342 | extern PySequenceMethods gmap_pysequence; |
343 | extern PyMethodDef gmap_pymethods[]; | |
344 | ||
b6a86d2e | 345 | /*----- Bytestrings -------------------------------------------------------*/ |
346 | ||
b6a86d2e | 347 | PyObject *bytestring_pywrap(const void *, size_t); |
348 | PyObject *bytestring_pywrapbuf(buf *); | |
349 | ||
350 | /*----- Multiprecision arithmetic -----------------------------------------*/ | |
351 | ||
352 | typedef struct mp_pyobj { | |
353 | PyObject_HEAD | |
354 | mp *x; | |
355 | } mp_pyobj; | |
356 | ||
357 | extern PyTypeObject *mp_pytype; | |
358 | extern PyTypeObject *gf_pytype; | |
359 | #define MP_X(o) (((mp_pyobj *)(o))->x) | |
360 | #define MP_PYCHECK(o) PyObject_TypeCheck((o), mp_pytype) | |
361 | #define GF_PYCHECK(o) PyObject_TypeCheck((o), gf_pytype) | |
362 | ||
8d57d6ea MW |
363 | extern mp *mp_frompylong(PyObject *); |
364 | extern PyObject *mp_topylong(mp *); | |
b6a86d2e | 365 | extern mp *tomp(PyObject *); |
366 | extern mp *getmp(PyObject *); | |
367 | extern int convmp(PyObject *, void *); | |
368 | extern mp *getgf(PyObject *); | |
369 | extern int convgf(PyObject *, void *); | |
370 | extern PyObject *mp_pywrap(mp *); | |
371 | extern PyObject *gf_pywrap(mp *); | |
917dbf4b | 372 | extern long mphash(mp *); |
b6a86d2e | 373 | extern mp *mp_frompyobject(PyObject *, int); |
374 | extern PyObject *mp_topystring(mp *, int, | |
375 | const char *, const char *, const char *); | |
41e8ab3d | 376 | extern int mp_tolong_checked(mp *, long *, int); |
b6a86d2e | 377 | |
378 | /*----- Abstract fields ---------------------------------------------------*/ | |
379 | ||
380 | typedef struct field_pyobj { | |
f0526039 | 381 | PyHeapTypeObject ty; |
b6a86d2e | 382 | field *f; |
383 | } field_pyobj; | |
384 | ||
b6a86d2e | 385 | extern PyTypeObject *field_pytype; |
386 | extern PyTypeObject *primefield_pytype; | |
387 | extern PyTypeObject *niceprimefield_pytype; | |
388 | extern PyTypeObject *binfield_pytype; | |
389 | extern PyTypeObject *binpolyfield_pytype; | |
390 | extern PyTypeObject *binnormfield_pytype; | |
391 | #define FIELD_PYCHECK(o) PyObject_TypeCheck((o), field_pytype) | |
392 | #define FIELD_F(o) (((field_pyobj *)(o))->f) | |
393 | extern PyObject *field_pywrap(field *); | |
394 | extern field *field_copy(field *); | |
395 | ||
8eeb5aee MW |
396 | typedef struct fe_pyobj { |
397 | PyObject_HEAD | |
398 | field *f; | |
399 | mp *x; | |
400 | } fe_pyobj; | |
401 | ||
402 | extern PyTypeObject *fe_pytype; | |
403 | #define FE_PYCHECK(o) PyObject_TypeCheck((o), fe_pytype) | |
404 | #define FE_F(o) (((fe_pyobj *)(o))->f) | |
405 | #define FE_FOBJ(o) ((PyObject *)(o)->ob_type) | |
406 | #define FE_X(o) (((fe_pyobj *)(o))->x) | |
407 | extern PyObject *fe_pywrap(PyObject *, mp *); | |
408 | ||
b6a86d2e | 409 | /*----- Elliptic curves ---------------------------------------------------*/ |
410 | ||
8eeb5aee MW |
411 | typedef struct eccurve_pyobj { |
412 | PyHeapTypeObject ty; | |
413 | ec_curve *c; | |
414 | PyObject *fobj; | |
415 | } eccurve_pyobj; | |
416 | ||
417 | extern PyTypeObject *eccurve_pytype; | |
418 | extern PyTypeObject *ecprimecurve_pytype; | |
419 | extern PyTypeObject *ecprimeprojcurve_pytype; | |
420 | extern PyTypeObject *ecbincurve_pytype; | |
421 | extern PyTypeObject *ecbinprojcurve_pytype; | |
422 | #define ECCURVE_PYCHECK(o) PyObject_TypeCheck((o), eccurve_pytype) | |
423 | #define ECCURVE_C(o) (((eccurve_pyobj *)(o))->c) | |
424 | #define ECCURVE_FOBJ(o) (((eccurve_pyobj *)(o))->fobj) | |
425 | extern PyObject *eccurve_pywrap(PyObject *, ec_curve *); | |
426 | extern ec_curve *eccurve_copy(ec_curve *); | |
427 | ||
b6a86d2e | 428 | typedef struct ecpt_pyobj { |
429 | PyObject_HEAD | |
430 | ec_curve *c; | |
431 | ec p; | |
432 | } ecpt_pyobj; | |
433 | ||
434 | extern PyTypeObject *ecpt_pytype, *ecptcurve_pytype; | |
435 | #define ECPT_PYCHECK(o) PyObject_TypeCheck((o), ecpt_pytype) | |
436 | #define ECPTCURVE_PYCHECK(o) PyObject_TypeCheck((o), ecptcurve_pytype) | |
437 | #define ECPT_C(o) (((ecpt_pyobj *)(o))->c) | |
438 | #define ECPT_COBJ(o) ((PyObject *)(o)->ob_type) | |
439 | #define ECPT_FOBJ(o) ECCURVE_FOBJ(ECPT_COBJ((o))) | |
440 | #define ECPT_P(o) (&((ecpt_pyobj *)(o))->p) | |
441 | extern PyObject *ecpt_pywrap(PyObject *, ec *); | |
442 | extern PyObject *ecpt_pywrapout(void *, ec *); | |
443 | extern int toecpt(ec_curve *, ec *, PyObject *); | |
444 | extern int getecpt(ec_curve *, ec *, PyObject *); | |
445 | extern void getecptout(ec *, PyObject *); | |
73a712fa | 446 | extern int convecpt(PyObject *, void *); |
b6a86d2e | 447 | |
b6a86d2e | 448 | typedef struct ecinfo_pyobj { |
449 | PyObject_HEAD | |
450 | ec_info ei; | |
451 | PyObject *cobj; | |
452 | } ecinfo_pyobj; | |
0b1eafbf | 453 | |
b6a86d2e | 454 | extern PyTypeObject *ecinfo_pytype; |
455 | #define ECINFO_PYCHECK(o) PyObject_TypeCheck((o), ecinfo_pytype) | |
456 | #define ECINFO_EI(o) (&((ecinfo_pyobj *)(o))->ei) | |
457 | #define ECINFO_COBJ(o) (((ecinfo_pyobj *)(o))->cobj) | |
458 | extern void ecinfo_copy(ec_info *, const ec_info *); | |
459 | extern PyObject *ecinfo_pywrap(ec_info *); | |
460 | ||
461 | /*----- Cyclic groups -----------------------------------------------------*/ | |
462 | ||
b6a86d2e | 463 | typedef struct ge_pyobj { |
464 | PyObject_HEAD | |
465 | ge *x; | |
466 | group *g; | |
467 | } ge_pyobj; | |
468 | ||
469 | extern PyTypeObject *ge_pytype; | |
470 | #define GE_PYCHECK(o) PyObject_TypeCheck((o), ge_pytype) | |
471 | #define GE_X(o) (((ge_pyobj *)(o))->x) | |
472 | #define GE_G(o) (((ge_pyobj *)(o))->g) | |
473 | #define GE_GOBJ(o) ((PyObject *)(group_pyobj *)(o)->ob_type) | |
474 | extern PyObject *ge_pywrap(PyObject *, ge *); | |
475 | ||
476 | typedef struct group_pyobj { | |
f0526039 | 477 | PyHeapTypeObject ty; |
b6a86d2e | 478 | group *g; |
479 | } group_pyobj; | |
480 | ||
481 | extern PyTypeObject *group_pytype; | |
b6a86d2e | 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 | ||
8eeb5aee | 496 | extern PyTypeObject *grand_pytype; |
b6a86d2e | 497 | extern PyObject *rand_pyobj; |
498 | #define GRAND_PYCHECK(o) PyObject_TypeCheck((o), grand_pytype) | |
499 | #define GRAND_F(o) (((grand_pyobj *)(o))->f) | |
500 | #define GRAND_R(o) (((grand_pyobj *)(o))->r) | |
501 | extern PyObject *grand_pywrap(grand *, unsigned); | |
502 | extern int convgrand(PyObject *, void *); | |
503 | ||
b6a86d2e | 504 | /*----- Symmetric cryptography --------------------------------------------*/ |
505 | ||
8eeb5aee | 506 | extern PyObject *keysz_pywrap(const octet *); |
b6a86d2e | 507 | |
b6a86d2e | 508 | extern int convgccipher(PyObject *, void *); |
8eeb5aee | 509 | extern PyObject *gccipher_pywrap(gccipher *); |
54ae5879 | 510 | |
b6a86d2e | 511 | typedef struct gchash_pyobj { |
f0526039 | 512 | PyHeapTypeObject ty; |
b6a86d2e | 513 | gchash *ch; |
514 | } gchash_pyobj; | |
515 | ||
516 | extern PyTypeObject *gchash_pytype; | |
8eeb5aee | 517 | extern PyObject *sha_pyobj, *has160_pyobj; |
b6a86d2e | 518 | #define GCHASH_PYCHECK(o) PyObject_TypeCheck((o), gchash_pytype) |
519 | #define GCHASH_CH(o) (((gchash_pyobj *)(o))->ch) | |
5a5e08d9 | 520 | extern PyObject *ghash_pywrap(PyObject *, ghash *); |
8eeb5aee | 521 | extern int convgchash(PyObject *, void *); |
b6a86d2e | 522 | extern int convghash(PyObject *, void *); |
b6a86d2e | 523 | |
b6a86d2e | 524 | extern int convgcmac(PyObject *, void *); |
525 | ||
b6a86d2e | 526 | /*----- Key generation ----------------------------------------------------*/ |
0b1eafbf | 527 | |
b6a86d2e | 528 | typedef struct pfilt_pyobj { |
529 | PyObject_HEAD | |
530 | pfilt f; | |
531 | int st; | |
532 | } pfilt_pyobj; | |
533 | ||
534 | extern PyTypeObject *pfilt_pytype; | |
535 | #define PFILT_PYCHECK(o) PyObject_TypeCheck(o, pfilt_pytype) | |
536 | #define PFILT_F(o) (&((pfilt_pyobj *)(o))->f) | |
537 | #define PFILT_ST(o) (((pfilt_pyobj *)(o))->st) | |
538 | ||
539 | typedef struct { pgen_proc *proc; void *ctx; } pgev; | |
540 | #define PGEV_HEAD PyObject_HEAD pgev pg; | |
541 | ||
542 | typedef struct pgev_pyobj { | |
543 | PGEV_HEAD | |
544 | } pgev_pyobj; | |
545 | ||
546 | extern PyTypeObject *pgev_pytype; | |
547 | #define PGEV_PYCHECK(o) PyObject_TypeCheck(o, pgev_pytype) | |
548 | #define PGEV_PG(o) (&((pgev_pyobj *)(o))->pg) | |
549 | ||
87aa2e3c MW |
550 | typedef struct pypgev { |
551 | pgev ev; | |
552 | PyObject *obj; | |
553 | struct excinfo *exc; | |
554 | } pypgev; | |
555 | ||
b6a86d2e | 556 | extern int convpgev(PyObject *, void *); |
87aa2e3c MW |
557 | extern void droppgev(pypgev *); |
558 | extern void pgenerr(struct excinfo *exc); | |
b6a86d2e | 559 | |
b6a86d2e | 560 | /*----- That's all, folks -------------------------------------------------*/ |
561 | ||
562 | #ifdef __cplusplus | |
563 | } | |
564 | #endif | |
565 | ||
566 | #endif |