Commit | Line | Data |
---|---|---|
d7ab1bab | 1 | /* -*-c-*- |
2 | * | |
d7ab1bab | 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> | |
84 | #include <catacomb/pfilt.h> | |
85 | #include <catacomb/strongprime.h> | |
86 | #include <catacomb/limlee.h> | |
87 | #include <catacomb/dh.h> | |
88 | #include <catacomb/ptab.h> | |
89 | #include <catacomb/bintab.h> | |
90 | #include <catacomb/dsa.h> | |
848ba392 | 91 | #include <catacomb/x25519.h> |
eb8aa4ec | 92 | #include <catacomb/x448.h> |
dafb2da4 | 93 | #include <catacomb/ed25519.h> |
eee202c3 | 94 | #include <catacomb/ed448.h> |
d7ab1bab | 95 | |
96 | #include <catacomb/gf.h> | |
97 | #include <catacomb/gfreduce.h> | |
98 | #include <catacomb/gfn.h> | |
99 | ||
100 | #include <catacomb/field.h> | |
101 | #include <catacomb/field-guts.h> | |
102 | ||
103 | #include <catacomb/ec.h> | |
104 | #include <catacomb/ec-raw.h> | |
105 | #include <catacomb/ectab.h> | |
106 | ||
107 | #include <catacomb/group.h> | |
108 | #include <catacomb/group-guts.h> | |
109 | ||
110 | #include <catacomb/gdsa.h> | |
111 | #include <catacomb/gkcdsa.h> | |
112 | #include <catacomb/rsa.h> | |
113 | ||
114 | #include <catacomb/key.h> | |
115 | #include <catacomb/passphrase.h> | |
116 | #include <catacomb/pixie.h> | |
117 | ||
46e6ad89 | 118 | #include <catacomb/share.h> |
119 | #include <catacomb/gfshare.h> | |
6640e060 MW |
120 | PRIVATE_SYMBOLS; |
121 | ||
10e6f88a | 122 | /*----- Miscellaneous preliminaries ---------------------------------------*/ |
d7ab1bab | 123 | |
10e6f88a | 124 | /* Submodules. */ |
46e6ad89 | 125 | #define MODULES(_) \ |
10e6f88a | 126 | _(pyke_core) _(pyke_gmap) \ |
46e6ad89 | 127 | _(bytestring) _(buffer) \ |
128 | _(rand) _(algorithms) _(pubkey) _(pgen) \ | |
129 | _(mp) _(field) _(ec) _(group) \ | |
0b1b92bd | 130 | _(passphrase) _(share) _(key) |
4e191783 | 131 | MODULES(DECLARE_MODINIT) |
d7ab1bab | 132 | |
10e6f88a MW |
133 | /* Exceptions. */ |
134 | #define PGENERR(err) do { pgenerr(err); goto end; } while (0) | |
135 | ||
136 | /* Conversions. */ | |
137 | extern int convmpw(PyObject *, void *); | |
3aa33042 | 138 | |
10e6f88a | 139 | /* Make a dictionary of generic-crypto classes. */ |
11cb3d97 MW |
140 | #define GEN(func, base) \ |
141 | static PyObject *func(void) \ | |
142 | { \ | |
143 | PyObject *d = PyDict_New(); \ | |
144 | PyObject *o; \ | |
145 | int i; \ | |
146 | \ | |
147 | for (i = 0; g##base##tab[i]; i++) { \ | |
148 | o = gc##base##_pywrap((/*unconst*/ gc##base *)g##base##tab[i]); \ | |
149 | PyDict_SetItemString(d, \ | |
150 | (/*unconst*/ char *)g##base##tab[i]->name, \ | |
151 | o); \ | |
152 | Py_DECREF(o); \ | |
153 | } \ | |
154 | return (d); \ | |
155 | } | |
156 | ||
10e6f88a | 157 | /* Common handling for simultaneous exponentiation. */ |
11cb3d97 MW |
158 | extern PyObject *mexp_common(PyObject *, PyObject *, size_t, |
159 | PyObject *(*id)(PyObject *), | |
160 | int (*fill)(void *, PyObject *, | |
161 | PyObject *, PyObject *), | |
162 | PyObject *(*exp)(PyObject *, void *, int), | |
163 | void (*drop)(void *)); | |
164 | ||
d7ab1bab | 165 | /*----- Bytestrings -------------------------------------------------------*/ |
166 | ||
d7ab1bab | 167 | PyObject *bytestring_pywrap(const void *, size_t); |
168 | PyObject *bytestring_pywrapbuf(buf *); | |
169 | ||
170 | /*----- Multiprecision arithmetic -----------------------------------------*/ | |
171 | ||
172 | typedef struct mp_pyobj { | |
173 | PyObject_HEAD | |
174 | mp *x; | |
175 | } mp_pyobj; | |
176 | ||
177 | extern PyTypeObject *mp_pytype; | |
178 | extern PyTypeObject *gf_pytype; | |
179 | #define MP_X(o) (((mp_pyobj *)(o))->x) | |
180 | #define MP_PYCHECK(o) PyObject_TypeCheck((o), mp_pytype) | |
181 | #define GF_PYCHECK(o) PyObject_TypeCheck((o), gf_pytype) | |
182 | ||
f368b46e MW |
183 | extern mp *mp_frompylong(PyObject *); |
184 | extern PyObject *mp_topylong(mp *); | |
d7ab1bab | 185 | extern mp *tomp(PyObject *); |
186 | extern mp *getmp(PyObject *); | |
187 | extern int convmp(PyObject *, void *); | |
188 | extern mp *getgf(PyObject *); | |
189 | extern int convgf(PyObject *, void *); | |
190 | extern PyObject *mp_pywrap(mp *); | |
191 | extern PyObject *gf_pywrap(mp *); | |
be6df1c3 | 192 | extern long mphash(mp *); |
d7ab1bab | 193 | extern mp *mp_frompyobject(PyObject *, int); |
194 | extern PyObject *mp_topystring(mp *, int, | |
195 | const char *, const char *, const char *); | |
bc243788 | 196 | extern int mp_tolong_checked(mp *, long *, int); |
d7ab1bab | 197 | |
198 | /*----- Abstract fields ---------------------------------------------------*/ | |
199 | ||
200 | typedef struct field_pyobj { | |
df9f8366 | 201 | PyHeapTypeObject ty; |
d7ab1bab | 202 | field *f; |
203 | } field_pyobj; | |
204 | ||
d7ab1bab | 205 | extern PyTypeObject *field_pytype; |
206 | extern PyTypeObject *primefield_pytype; | |
207 | extern PyTypeObject *niceprimefield_pytype; | |
208 | extern PyTypeObject *binfield_pytype; | |
209 | extern PyTypeObject *binpolyfield_pytype; | |
210 | extern PyTypeObject *binnormfield_pytype; | |
211 | #define FIELD_PYCHECK(o) PyObject_TypeCheck((o), field_pytype) | |
212 | #define FIELD_F(o) (((field_pyobj *)(o))->f) | |
213 | extern PyObject *field_pywrap(field *); | |
214 | extern field *field_copy(field *); | |
215 | ||
c6e89d48 MW |
216 | typedef struct fe_pyobj { |
217 | PyObject_HEAD | |
218 | field *f; | |
219 | mp *x; | |
220 | } fe_pyobj; | |
221 | ||
222 | extern PyTypeObject *fe_pytype; | |
223 | #define FE_PYCHECK(o) PyObject_TypeCheck((o), fe_pytype) | |
224 | #define FE_F(o) (((fe_pyobj *)(o))->f) | |
225 | #define FE_FOBJ(o) ((PyObject *)(o)->ob_type) | |
226 | #define FE_X(o) (((fe_pyobj *)(o))->x) | |
227 | extern PyObject *fe_pywrap(PyObject *, mp *); | |
228 | ||
d7ab1bab | 229 | /*----- Elliptic curves ---------------------------------------------------*/ |
230 | ||
c6e89d48 MW |
231 | typedef struct eccurve_pyobj { |
232 | PyHeapTypeObject ty; | |
233 | ec_curve *c; | |
234 | PyObject *fobj; | |
235 | } eccurve_pyobj; | |
236 | ||
237 | extern PyTypeObject *eccurve_pytype; | |
238 | extern PyTypeObject *ecprimecurve_pytype; | |
239 | extern PyTypeObject *ecprimeprojcurve_pytype; | |
240 | extern PyTypeObject *ecbincurve_pytype; | |
241 | extern PyTypeObject *ecbinprojcurve_pytype; | |
242 | #define ECCURVE_PYCHECK(o) PyObject_TypeCheck((o), eccurve_pytype) | |
243 | #define ECCURVE_C(o) (((eccurve_pyobj *)(o))->c) | |
244 | #define ECCURVE_FOBJ(o) (((eccurve_pyobj *)(o))->fobj) | |
245 | extern PyObject *eccurve_pywrap(PyObject *, ec_curve *); | |
246 | extern ec_curve *eccurve_copy(ec_curve *); | |
247 | ||
d7ab1bab | 248 | typedef struct ecpt_pyobj { |
249 | PyObject_HEAD | |
250 | ec_curve *c; | |
251 | ec p; | |
252 | } ecpt_pyobj; | |
253 | ||
254 | extern PyTypeObject *ecpt_pytype, *ecptcurve_pytype; | |
255 | #define ECPT_PYCHECK(o) PyObject_TypeCheck((o), ecpt_pytype) | |
256 | #define ECPTCURVE_PYCHECK(o) PyObject_TypeCheck((o), ecptcurve_pytype) | |
257 | #define ECPT_C(o) (((ecpt_pyobj *)(o))->c) | |
258 | #define ECPT_COBJ(o) ((PyObject *)(o)->ob_type) | |
259 | #define ECPT_FOBJ(o) ECCURVE_FOBJ(ECPT_COBJ((o))) | |
260 | #define ECPT_P(o) (&((ecpt_pyobj *)(o))->p) | |
261 | extern PyObject *ecpt_pywrap(PyObject *, ec *); | |
262 | extern PyObject *ecpt_pywrapout(void *, ec *); | |
263 | extern int toecpt(ec_curve *, ec *, PyObject *); | |
264 | extern int getecpt(ec_curve *, ec *, PyObject *); | |
265 | extern void getecptout(ec *, PyObject *); | |
46e6ad89 | 266 | extern int convecpt(PyObject *, void *); |
d7ab1bab | 267 | |
d7ab1bab | 268 | typedef struct ecinfo_pyobj { |
269 | PyObject_HEAD | |
270 | ec_info ei; | |
271 | PyObject *cobj; | |
272 | } ecinfo_pyobj; | |
b2687a0a | 273 | |
d7ab1bab | 274 | extern PyTypeObject *ecinfo_pytype; |
275 | #define ECINFO_PYCHECK(o) PyObject_TypeCheck((o), ecinfo_pytype) | |
276 | #define ECINFO_EI(o) (&((ecinfo_pyobj *)(o))->ei) | |
277 | #define ECINFO_COBJ(o) (((ecinfo_pyobj *)(o))->cobj) | |
278 | extern void ecinfo_copy(ec_info *, const ec_info *); | |
279 | extern PyObject *ecinfo_pywrap(ec_info *); | |
280 | ||
281 | /*----- Cyclic groups -----------------------------------------------------*/ | |
282 | ||
d7ab1bab | 283 | typedef struct ge_pyobj { |
284 | PyObject_HEAD | |
285 | ge *x; | |
286 | group *g; | |
287 | } ge_pyobj; | |
288 | ||
289 | extern PyTypeObject *ge_pytype; | |
290 | #define GE_PYCHECK(o) PyObject_TypeCheck((o), ge_pytype) | |
291 | #define GE_X(o) (((ge_pyobj *)(o))->x) | |
292 | #define GE_G(o) (((ge_pyobj *)(o))->g) | |
293 | #define GE_GOBJ(o) ((PyObject *)(group_pyobj *)(o)->ob_type) | |
294 | extern PyObject *ge_pywrap(PyObject *, ge *); | |
295 | ||
296 | typedef struct group_pyobj { | |
df9f8366 | 297 | PyHeapTypeObject ty; |
d7ab1bab | 298 | group *g; |
299 | } group_pyobj; | |
300 | ||
301 | extern PyTypeObject *group_pytype; | |
d7ab1bab | 302 | #define GROUP_G(o) (((group_pyobj *)(o))->g) |
303 | extern PyObject *group_pywrap(group *); | |
304 | extern group *group_copy(group *); | |
305 | ||
306 | /*----- Random number generators ------------------------------------------*/ | |
307 | ||
308 | #define f_freeme 1u | |
309 | ||
310 | typedef struct grand_pyobj { | |
311 | PyObject_HEAD | |
312 | unsigned f; | |
313 | grand *r; | |
314 | } grand_pyobj; | |
315 | ||
c6e89d48 | 316 | extern PyTypeObject *grand_pytype; |
d7ab1bab | 317 | extern PyObject *rand_pyobj; |
318 | #define GRAND_PYCHECK(o) PyObject_TypeCheck((o), grand_pytype) | |
319 | #define GRAND_F(o) (((grand_pyobj *)(o))->f) | |
320 | #define GRAND_R(o) (((grand_pyobj *)(o))->r) | |
321 | extern PyObject *grand_pywrap(grand *, unsigned); | |
322 | extern int convgrand(PyObject *, void *); | |
323 | ||
d7ab1bab | 324 | /*----- Symmetric cryptography --------------------------------------------*/ |
325 | ||
c6e89d48 | 326 | extern PyObject *keysz_pywrap(const octet *); |
d7ab1bab | 327 | |
d7ab1bab | 328 | extern int convgccipher(PyObject *, void *); |
c6e89d48 | 329 | extern PyObject *gccipher_pywrap(gccipher *); |
bebf03ab | 330 | |
d7ab1bab | 331 | typedef struct gchash_pyobj { |
df9f8366 | 332 | PyHeapTypeObject ty; |
d7ab1bab | 333 | gchash *ch; |
334 | } gchash_pyobj; | |
335 | ||
336 | extern PyTypeObject *gchash_pytype; | |
c6e89d48 | 337 | extern PyObject *sha_pyobj, *has160_pyobj; |
d7ab1bab | 338 | #define GCHASH_PYCHECK(o) PyObject_TypeCheck((o), gchash_pytype) |
339 | #define GCHASH_CH(o) (((gchash_pyobj *)(o))->ch) | |
c41d0371 | 340 | extern PyObject *ghash_pywrap(PyObject *, ghash *); |
c6e89d48 | 341 | extern int convgchash(PyObject *, void *); |
d7ab1bab | 342 | extern int convghash(PyObject *, void *); |
d7ab1bab | 343 | |
d7ab1bab | 344 | extern int convgcmac(PyObject *, void *); |
345 | ||
d7ab1bab | 346 | /*----- Key generation ----------------------------------------------------*/ |
b2687a0a | 347 | |
d7ab1bab | 348 | typedef struct pfilt_pyobj { |
349 | PyObject_HEAD | |
350 | pfilt f; | |
351 | int st; | |
352 | } pfilt_pyobj; | |
353 | ||
354 | extern PyTypeObject *pfilt_pytype; | |
355 | #define PFILT_PYCHECK(o) PyObject_TypeCheck(o, pfilt_pytype) | |
356 | #define PFILT_F(o) (&((pfilt_pyobj *)(o))->f) | |
357 | #define PFILT_ST(o) (((pfilt_pyobj *)(o))->st) | |
358 | ||
359 | typedef struct { pgen_proc *proc; void *ctx; } pgev; | |
360 | #define PGEV_HEAD PyObject_HEAD pgev pg; | |
361 | ||
362 | typedef struct pgev_pyobj { | |
363 | PGEV_HEAD | |
364 | } pgev_pyobj; | |
365 | ||
366 | extern PyTypeObject *pgev_pytype; | |
367 | #define PGEV_PYCHECK(o) PyObject_TypeCheck(o, pgev_pytype) | |
368 | #define PGEV_PG(o) (&((pgev_pyobj *)(o))->pg) | |
369 | ||
930d78e3 MW |
370 | typedef struct pypgev { |
371 | pgev ev; | |
372 | PyObject *obj; | |
373 | struct excinfo *exc; | |
374 | } pypgev; | |
375 | ||
d7ab1bab | 376 | extern int convpgev(PyObject *, void *); |
930d78e3 MW |
377 | extern void droppgev(pypgev *); |
378 | extern void pgenerr(struct excinfo *exc); | |
d7ab1bab | 379 | |
d7ab1bab | 380 | /*----- That's all, folks -------------------------------------------------*/ |
381 | ||
382 | #ifdef __cplusplus | |
383 | } | |
384 | #endif | |
385 | ||
386 | #endif |