Commit | Line | Data |
---|---|---|
d7ab1bab | 1 | /* -*-c-*- |
d7ab1bab | 2 | * |
3 | * Definitions for Catacomb bindings | |
4 | * | |
5 | * (c) 2004 Straylight/Edgeware | |
6 | */ | |
7 | ||
b2687a0a | 8 | /*----- Licensing notice --------------------------------------------------* |
d7ab1bab | 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. | |
b2687a0a | 16 | * |
d7ab1bab | 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. | |
b2687a0a | 21 | * |
d7ab1bab | 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 | ||
10e6f88a | 36 | #include "pyke/pyke-mLib.h" |
6b54260d | 37 | |
10e6f88a | 38 | PUBLIC_SYMBOLS; |
d7ab1bab | 39 | #include <longintrepr.h> |
d7ab1bab | 40 | |
d7ab1bab | 41 | #include <mLib/dstr.h> |
42 | #include <mLib/macros.h> | |
46e6ad89 | 43 | #include <mLib/quis.h> |
6d481bc6 | 44 | #include <mLib/unihash.h> |
d7ab1bab | 45 | |
46 | #include <catacomb/buf.h> | |
bfb450cc | 47 | #include <catacomb/ct.h> |
d7ab1bab | 48 | |
49 | #include <catacomb/grand.h> | |
50 | #include <catacomb/rand.h> | |
51 | #include <catacomb/noise.h> | |
52 | #include <catacomb/bbs.h> | |
53 | #include <catacomb/mprand.h> | |
54 | #include <catacomb/lcrand.h> | |
55 | #include <catacomb/fibrand.h> | |
56 | #include <catacomb/dsarand.h> | |
57 | #include <catacomb/sslprf.h> | |
58 | #include <catacomb/tlsprf.h> | |
03ed9abb | 59 | #include <catacomb/blkc.h> |
d7ab1bab | 60 | |
61 | #include <catacomb/gcipher.h> | |
bebf03ab | 62 | #include <catacomb/gaead.h> |
d7ab1bab | 63 | #include <catacomb/ghash.h> |
64 | #include <catacomb/gmac.h> | |
65 | #include <catacomb/md5.h> | |
66 | #include <catacomb/md5-hmac.h> | |
204d480b | 67 | #include <catacomb/poly1305.h> |
d7ab1bab | 68 | #include <catacomb/sha.h> |
69 | #include <catacomb/sha-mgf.h> | |
70 | #include <catacomb/sha-hmac.h> | |
b35fdbe6 | 71 | #include <catacomb/keccak1600.h> |
6bd22b53 | 72 | #include <catacomb/sha3.h> |
d7ab1bab | 73 | |
74 | #include <catacomb/mp.h> | |
75 | #include <catacomb/mpint.h> | |
76 | #include <catacomb/mpmul.h> | |
77 | #include <catacomb/mpcrt.h> | |
78 | #include <catacomb/mpmont.h> | |
79 | #include <catacomb/mpbarrett.h> | |
80 | #include <catacomb/mpreduce.h> | |
6313f40e | 81 | #include <catacomb/mp-fibonacci.h> |
d7ab1bab | 82 | |
83 | #include <catacomb/pgen.h> | |
2b08f130 | 84 | #include <catacomb/primeiter.h> |
d7ab1bab | 85 | #include <catacomb/pfilt.h> |
86 | #include <catacomb/strongprime.h> | |
87 | #include <catacomb/limlee.h> | |
88 | #include <catacomb/dh.h> | |
89 | #include <catacomb/ptab.h> | |
90 | #include <catacomb/bintab.h> | |
91 | #include <catacomb/dsa.h> | |
848ba392 | 92 | #include <catacomb/x25519.h> |
eb8aa4ec | 93 | #include <catacomb/x448.h> |
dafb2da4 | 94 | #include <catacomb/ed25519.h> |
eee202c3 | 95 | #include <catacomb/ed448.h> |
d7ab1bab | 96 | |
97 | #include <catacomb/gf.h> | |
98 | #include <catacomb/gfreduce.h> | |
99 | #include <catacomb/gfn.h> | |
100 | ||
101 | #include <catacomb/field.h> | |
102 | #include <catacomb/field-guts.h> | |
103 | ||
104 | #include <catacomb/ec.h> | |
105 | #include <catacomb/ec-raw.h> | |
106 | #include <catacomb/ectab.h> | |
107 | ||
108 | #include <catacomb/group.h> | |
109 | #include <catacomb/group-guts.h> | |
110 | ||
111 | #include <catacomb/gdsa.h> | |
112 | #include <catacomb/gkcdsa.h> | |
113 | #include <catacomb/rsa.h> | |
114 | ||
115 | #include <catacomb/key.h> | |
116 | #include <catacomb/passphrase.h> | |
117 | #include <catacomb/pixie.h> | |
118 | ||
46e6ad89 | 119 | #include <catacomb/share.h> |
120 | #include <catacomb/gfshare.h> | |
6640e060 MW |
121 | PRIVATE_SYMBOLS; |
122 | ||
10e6f88a | 123 | /*----- Miscellaneous preliminaries ---------------------------------------*/ |
d7ab1bab | 124 | |
10e6f88a | 125 | /* Submodules. */ |
46e6ad89 | 126 | #define MODULES(_) \ |
10e6f88a | 127 | _(pyke_core) _(pyke_gmap) \ |
46e6ad89 | 128 | _(bytestring) _(buffer) \ |
129 | _(rand) _(algorithms) _(pubkey) _(pgen) \ | |
130 | _(mp) _(field) _(ec) _(group) \ | |
0b1b92bd | 131 | _(passphrase) _(share) _(key) |
4e191783 | 132 | MODULES(DECLARE_MODINIT) |
d7ab1bab | 133 | |
10e6f88a MW |
134 | /* Exceptions. */ |
135 | #define PGENERR(err) do { pgenerr(err); goto end; } while (0) | |
136 | ||
137 | /* Conversions. */ | |
138 | extern int convmpw(PyObject *, void *); | |
3aa33042 | 139 | |
a539ffb8 MW |
140 | /* Building tables of things. */ |
141 | extern PyObject *make_algtab(const void *tab, size_t esz, | |
142 | const char *(*namefn)(const void *), | |
143 | PyObject *(*valfn)(const void *)); | |
144 | extern PyObject *make_grouptab(const void *tab, size_t esz, | |
145 | const char *(*namefn)(const void *), | |
146 | int (*ixfn)(const void *), | |
147 | PyObject *(*valfn)(int)); | |
11cb3d97 | 148 | |
10e6f88a | 149 | /* Common handling for simultaneous exponentiation. */ |
11cb3d97 MW |
150 | extern PyObject *mexp_common(PyObject *, PyObject *, size_t, |
151 | PyObject *(*id)(PyObject *), | |
152 | int (*fill)(void *, PyObject *, | |
153 | PyObject *, PyObject *), | |
01d4fd84 | 154 | PyObject *(*exp)(PyObject *, void *, size_t), |
11cb3d97 MW |
155 | void (*drop)(void *)); |
156 | ||
d7ab1bab | 157 | /*----- Bytestrings -------------------------------------------------------*/ |
158 | ||
d7ab1bab | 159 | PyObject *bytestring_pywrap(const void *, size_t); |
160 | PyObject *bytestring_pywrapbuf(buf *); | |
161 | ||
dc088b4d MW |
162 | /*----- Buffers -----------------------------------------------------------*/ |
163 | ||
164 | typedef struct buf_pyobj { | |
165 | PyObject_HEAD | |
166 | buf b; | |
167 | PyObject *sub; | |
168 | unsigned lk; | |
169 | } buf_pyobj; | |
170 | ||
171 | extern PyTypeObject *rbuf_pytype, *wbuf_pytype; | |
172 | #define RBUF_PYCHECK(o) PyObject_TypeCheck((o), rbuf_pytype) | |
173 | #define WBUF_PYCHECK(o) PyObject_TypeCheck((o), wbuf_pytype) | |
174 | #define BUF_B(o) (&((buf_pyobj *)(o))->b) | |
175 | #define BUF_SUB(o) (((buf_pyobj *)(o))->sub) | |
176 | #define BUF_LK(o) (((buf_pyobj *)(o))->lk) | |
177 | ||
178 | extern PyObject *buferr; | |
179 | #define BUFERR(str) do { PyErr_SetString(buferr, str); goto end; } while (0) | |
180 | ||
181 | extern int ensurebuf(PyObject *, size_t); | |
182 | ||
d7ab1bab | 183 | /*----- Multiprecision arithmetic -----------------------------------------*/ |
184 | ||
185 | typedef struct mp_pyobj { | |
186 | PyObject_HEAD | |
187 | mp *x; | |
188 | } mp_pyobj; | |
189 | ||
190 | extern PyTypeObject *mp_pytype; | |
191 | extern PyTypeObject *gf_pytype; | |
192 | #define MP_X(o) (((mp_pyobj *)(o))->x) | |
193 | #define MP_PYCHECK(o) PyObject_TypeCheck((o), mp_pytype) | |
194 | #define GF_PYCHECK(o) PyObject_TypeCheck((o), gf_pytype) | |
195 | ||
f368b46e MW |
196 | extern mp *mp_frompylong(PyObject *); |
197 | extern PyObject *mp_topylong(mp *); | |
d7ab1bab | 198 | extern mp *tomp(PyObject *); |
5b29dfaf | 199 | extern mp *implicitmp(PyObject *); |
d7ab1bab | 200 | extern mp *getmp(PyObject *); |
201 | extern int convmp(PyObject *, void *); | |
5b29dfaf | 202 | extern mp *implicitgf(PyObject *); |
d7ab1bab | 203 | extern mp *getgf(PyObject *); |
204 | extern int convgf(PyObject *, void *); | |
205 | extern PyObject *mp_pywrap(mp *); | |
206 | extern PyObject *gf_pywrap(mp *); | |
d6d78edc | 207 | extern Py_hash_t mphash(mp *); |
d7ab1bab | 208 | extern mp *mp_frompyobject(PyObject *, int); |
209 | extern PyObject *mp_topystring(mp *, int, | |
210 | const char *, const char *, const char *); | |
bc243788 | 211 | extern int mp_tolong_checked(mp *, long *, int); |
d7ab1bab | 212 | |
213 | /*----- Abstract fields ---------------------------------------------------*/ | |
214 | ||
215 | typedef struct field_pyobj { | |
df9f8366 | 216 | PyHeapTypeObject ty; |
d7ab1bab | 217 | field *f; |
218 | } field_pyobj; | |
219 | ||
d7ab1bab | 220 | extern PyTypeObject *field_pytype; |
221 | extern PyTypeObject *primefield_pytype; | |
222 | extern PyTypeObject *niceprimefield_pytype; | |
223 | extern PyTypeObject *binfield_pytype; | |
224 | extern PyTypeObject *binpolyfield_pytype; | |
225 | extern PyTypeObject *binnormfield_pytype; | |
226 | #define FIELD_PYCHECK(o) PyObject_TypeCheck((o), field_pytype) | |
227 | #define FIELD_F(o) (((field_pyobj *)(o))->f) | |
228 | extern PyObject *field_pywrap(field *); | |
229 | extern field *field_copy(field *); | |
230 | ||
c6e89d48 MW |
231 | typedef struct fe_pyobj { |
232 | PyObject_HEAD | |
233 | field *f; | |
234 | mp *x; | |
235 | } fe_pyobj; | |
236 | ||
237 | extern PyTypeObject *fe_pytype; | |
238 | #define FE_PYCHECK(o) PyObject_TypeCheck((o), fe_pytype) | |
239 | #define FE_F(o) (((fe_pyobj *)(o))->f) | |
2a448f86 | 240 | #define FE_FOBJ(o) ((PyObject *)Py_TYPE(o)) |
c6e89d48 MW |
241 | #define FE_X(o) (((fe_pyobj *)(o))->x) |
242 | extern PyObject *fe_pywrap(PyObject *, mp *); | |
243 | ||
d7ab1bab | 244 | /*----- Elliptic curves ---------------------------------------------------*/ |
245 | ||
c6e89d48 MW |
246 | typedef struct eccurve_pyobj { |
247 | PyHeapTypeObject ty; | |
248 | ec_curve *c; | |
249 | PyObject *fobj; | |
250 | } eccurve_pyobj; | |
251 | ||
252 | extern PyTypeObject *eccurve_pytype; | |
253 | extern PyTypeObject *ecprimecurve_pytype; | |
254 | extern PyTypeObject *ecprimeprojcurve_pytype; | |
255 | extern PyTypeObject *ecbincurve_pytype; | |
256 | extern PyTypeObject *ecbinprojcurve_pytype; | |
257 | #define ECCURVE_PYCHECK(o) PyObject_TypeCheck((o), eccurve_pytype) | |
258 | #define ECCURVE_C(o) (((eccurve_pyobj *)(o))->c) | |
259 | #define ECCURVE_FOBJ(o) (((eccurve_pyobj *)(o))->fobj) | |
260 | extern PyObject *eccurve_pywrap(PyObject *, ec_curve *); | |
261 | extern ec_curve *eccurve_copy(ec_curve *); | |
262 | ||
d7ab1bab | 263 | typedef struct ecpt_pyobj { |
264 | PyObject_HEAD | |
265 | ec_curve *c; | |
266 | ec p; | |
267 | } ecpt_pyobj; | |
268 | ||
269 | extern PyTypeObject *ecpt_pytype, *ecptcurve_pytype; | |
270 | #define ECPT_PYCHECK(o) PyObject_TypeCheck((o), ecpt_pytype) | |
271 | #define ECPTCURVE_PYCHECK(o) PyObject_TypeCheck((o), ecptcurve_pytype) | |
272 | #define ECPT_C(o) (((ecpt_pyobj *)(o))->c) | |
2a448f86 | 273 | #define ECPT_COBJ(o) ((PyObject *)Py_TYPE(o)) |
d7ab1bab | 274 | #define ECPT_FOBJ(o) ECCURVE_FOBJ(ECPT_COBJ((o))) |
275 | #define ECPT_P(o) (&((ecpt_pyobj *)(o))->p) | |
276 | extern PyObject *ecpt_pywrap(PyObject *, ec *); | |
277 | extern PyObject *ecpt_pywrapout(void *, ec *); | |
278 | extern int toecpt(ec_curve *, ec *, PyObject *); | |
279 | extern int getecpt(ec_curve *, ec *, PyObject *); | |
280 | extern void getecptout(ec *, PyObject *); | |
46e6ad89 | 281 | extern int convecpt(PyObject *, void *); |
d7ab1bab | 282 | |
d7ab1bab | 283 | typedef struct ecinfo_pyobj { |
284 | PyObject_HEAD | |
285 | ec_info ei; | |
286 | PyObject *cobj; | |
287 | } ecinfo_pyobj; | |
b2687a0a | 288 | |
d7ab1bab | 289 | extern PyTypeObject *ecinfo_pytype; |
290 | #define ECINFO_PYCHECK(o) PyObject_TypeCheck((o), ecinfo_pytype) | |
291 | #define ECINFO_EI(o) (&((ecinfo_pyobj *)(o))->ei) | |
292 | #define ECINFO_COBJ(o) (((ecinfo_pyobj *)(o))->cobj) | |
293 | extern void ecinfo_copy(ec_info *, const ec_info *); | |
294 | extern PyObject *ecinfo_pywrap(ec_info *); | |
295 | ||
296 | /*----- Cyclic groups -----------------------------------------------------*/ | |
297 | ||
d7ab1bab | 298 | typedef struct ge_pyobj { |
299 | PyObject_HEAD | |
300 | ge *x; | |
301 | group *g; | |
302 | } ge_pyobj; | |
303 | ||
304 | extern PyTypeObject *ge_pytype; | |
305 | #define GE_PYCHECK(o) PyObject_TypeCheck((o), ge_pytype) | |
306 | #define GE_X(o) (((ge_pyobj *)(o))->x) | |
307 | #define GE_G(o) (((ge_pyobj *)(o))->g) | |
2a448f86 | 308 | #define GE_GOBJ(o) (PyObject *)(Py_TYPE(o)) |
d7ab1bab | 309 | extern PyObject *ge_pywrap(PyObject *, ge *); |
310 | ||
311 | typedef struct group_pyobj { | |
df9f8366 | 312 | PyHeapTypeObject ty; |
d7ab1bab | 313 | group *g; |
314 | } group_pyobj; | |
315 | ||
316 | extern PyTypeObject *group_pytype; | |
d7ab1bab | 317 | #define GROUP_G(o) (((group_pyobj *)(o))->g) |
318 | extern PyObject *group_pywrap(group *); | |
319 | extern group *group_copy(group *); | |
320 | ||
321 | /*----- Random number generators ------------------------------------------*/ | |
322 | ||
323 | #define f_freeme 1u | |
324 | ||
325 | typedef struct grand_pyobj { | |
326 | PyObject_HEAD | |
327 | unsigned f; | |
328 | grand *r; | |
329 | } grand_pyobj; | |
330 | ||
c6e89d48 | 331 | extern PyTypeObject *grand_pytype; |
d7ab1bab | 332 | extern PyObject *rand_pyobj; |
333 | #define GRAND_PYCHECK(o) PyObject_TypeCheck((o), grand_pytype) | |
334 | #define GRAND_F(o) (((grand_pyobj *)(o))->f) | |
335 | #define GRAND_R(o) (((grand_pyobj *)(o))->r) | |
336 | extern PyObject *grand_pywrap(grand *, unsigned); | |
337 | extern int convgrand(PyObject *, void *); | |
338 | ||
d7ab1bab | 339 | /*----- Symmetric cryptography --------------------------------------------*/ |
340 | ||
c6e89d48 | 341 | extern PyObject *keysz_pywrap(const octet *); |
d7ab1bab | 342 | |
d7ab1bab | 343 | extern int convgccipher(PyObject *, void *); |
c6e89d48 | 344 | extern PyObject *gccipher_pywrap(gccipher *); |
bebf03ab | 345 | |
d7ab1bab | 346 | typedef struct gchash_pyobj { |
df9f8366 | 347 | PyHeapTypeObject ty; |
d7ab1bab | 348 | gchash *ch; |
349 | } gchash_pyobj; | |
350 | ||
351 | extern PyTypeObject *gchash_pytype; | |
c6e89d48 | 352 | extern PyObject *sha_pyobj, *has160_pyobj; |
d7ab1bab | 353 | #define GCHASH_PYCHECK(o) PyObject_TypeCheck((o), gchash_pytype) |
354 | #define GCHASH_CH(o) (((gchash_pyobj *)(o))->ch) | |
c41d0371 | 355 | extern PyObject *ghash_pywrap(PyObject *, ghash *); |
c6e89d48 | 356 | extern int convgchash(PyObject *, void *); |
d7ab1bab | 357 | extern int convghash(PyObject *, void *); |
d7ab1bab | 358 | |
d7ab1bab | 359 | extern int convgcmac(PyObject *, void *); |
360 | ||
d7ab1bab | 361 | /*----- Key generation ----------------------------------------------------*/ |
b2687a0a | 362 | |
d7ab1bab | 363 | typedef struct pfilt_pyobj { |
364 | PyObject_HEAD | |
365 | pfilt f; | |
366 | int st; | |
367 | } pfilt_pyobj; | |
368 | ||
369 | extern PyTypeObject *pfilt_pytype; | |
370 | #define PFILT_PYCHECK(o) PyObject_TypeCheck(o, pfilt_pytype) | |
371 | #define PFILT_F(o) (&((pfilt_pyobj *)(o))->f) | |
372 | #define PFILT_ST(o) (((pfilt_pyobj *)(o))->st) | |
373 | ||
374 | typedef struct { pgen_proc *proc; void *ctx; } pgev; | |
375 | #define PGEV_HEAD PyObject_HEAD pgev pg; | |
376 | ||
377 | typedef struct pgev_pyobj { | |
378 | PGEV_HEAD | |
379 | } pgev_pyobj; | |
380 | ||
381 | extern PyTypeObject *pgev_pytype; | |
382 | #define PGEV_PYCHECK(o) PyObject_TypeCheck(o, pgev_pytype) | |
383 | #define PGEV_PG(o) (&((pgev_pyobj *)(o))->pg) | |
384 | ||
930d78e3 MW |
385 | typedef struct pypgev { |
386 | pgev ev; | |
387 | PyObject *obj; | |
388 | struct excinfo *exc; | |
389 | } pypgev; | |
390 | ||
d7ab1bab | 391 | extern int convpgev(PyObject *, void *); |
930d78e3 MW |
392 | extern void droppgev(pypgev *); |
393 | extern void pgenerr(struct excinfo *exc); | |
d7ab1bab | 394 | |
d7ab1bab | 395 | /*----- That's all, folks -------------------------------------------------*/ |
396 | ||
397 | #ifdef __cplusplus | |
398 | } | |
399 | #endif | |
400 | ||
401 | #endif |