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