Various changes. Kinda in the middle of it here, but it seems to work.
[catacomb-perl] / catacomb-perl.h
CommitLineData
660b443c 1/* -*-c-*-
2 *
a1a90aaf 3 * $Id$
660b443c 4 *
5 * Main header file for Catacomb/Perl
6 *
7 * (c) 2001 Straylight/Edgeware
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of the Perl interface to Catacomb.
13 *
14 * Catacomb/Perl is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * Catacomb/Perl is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Catacomb/Perl; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 */
28
660b443c 29#ifndef CATACOMB_PERL_H
30#define CATACOMB_PERL_H
31
32#ifdef __cplusplus
33 extern "C" {
34#endif
35
36/*----- Header files ------------------------------------------------------*/
37
a1a90aaf 38#include <EXTERN.h>
39#include <perl.h>
40#include <XSUB.h>
41
660b443c 42#include <assert.h>
43#include <stdio.h>
44#include <stdarg.h>
45#include <stdlib.h>
46#include <string.h>
47
660b443c 48#include <catacomb/gcipher.h>
49#include <catacomb/ghash.h>
50#include <catacomb/gmac.h>
51
52#include <catacomb/grand.h>
53#include <catacomb/fibrand.h>
54#include <catacomb/lcrand.h>
55#include <catacomb/dsarand.h>
56#include <catacomb/rand.h>
57#include <catacomb/noise.h>
58
a1a90aaf 59#include <catacomb/key.h>
660b443c 60#include <catacomb/passphrase.h>
61
62#include <catacomb/mp.h>
a1a90aaf 63#include <catacomb/gf.h>
64#include <catacomb/ec.h>
65#include <catacomb/field.h>
f9952aec 66#include <catacomb/group.h>
660b443c 67#include <catacomb/mpint.h>
68#include <catacomb/mpmul.h>
69#include <catacomb/mprand.h>
70#include <catacomb/mpcrt.h>
71#include <catacomb/mpmont.h>
72#include <catacomb/mpbarrett.h>
a1a90aaf 73#include <catacomb/mpreduce.h>
74#include <catacomb/gfreduce.h>
660b443c 75
76#include <catacomb/pfilt.h>
77#include <catacomb/rabin.h>
78#include <catacomb/pgen.h>
79#include <catacomb/limlee.h>
80#include <catacomb/strongprime.h>
81
82/*----- Misc support ------------------------------------------------------*/
83
84struct consttab { const char *name; UV val; };
85
86extern U32 findconst(const struct consttab *cc,
87 const char *pkg, const char *name);
a1a90aaf 88extern void ptrtosv(SV **sv, void *p, const char *type);
89extern void *ptrfromsv(SV *sv, const char *type, const char *what, ...);
660b443c 90#define SET(sv, ob, ty) sv_setref_pv((sv), (char *)(ty), (void *)(ob))
91#define MAKE(ob, ty) SET(NEWSV(0, 0), ob, ty)
92#define RET(ob, ty) SET(sv_newmortal(), ob, ty)
93
94/*----- Crypto algorithms -------------------------------------------------*/
95
96struct randtab { const char *name; grand *(*rand)(const void *, size_t); };
97
98typedef const octet keysize;
99typedef gmac gMAC;
100typedef gcmac gcMAC;
101
102typedef grand Rand_True, Rand_DSA;
103
660b443c 104extern const struct randtab mgftab[], ctrtab[], ofbtab[];
105
106extern SV *findrand(const struct randtab *rt, const char *cls,
107 const char *name, SV *k);
108extern void listrand(const struct randtab *rt);
109
a1a90aaf 110/*------ Key mangling -----------------------------------------------------*/
111
112typedef struct Key {
113 key_file *kf;
114 key *k;
115} Key;
116
117typedef int KeyErr;
118typedef key_data Key_Data;
119typedef key_file Key_File;
120
121extern void warn_keyreporter(const char *file, int line,
122 const char *err, void *p);
123extern SV *keyerr(int rc);
124
660b443c 125/*------ Multiprecision maths ---------------------------------------------*/
126
a1a90aaf 127typedef mp gf;
660b443c 128typedef mpmont MP_Mont;
129typedef mpbarrett MP_Barrett;
130typedef mpcrt MP_CRT;
131
a1a90aaf 132typedef mpreduce MP_Reduce;
133typedef gfreduce GF_Reduce;
134
135typedef ec EC_Point;
136typedef ec_curve EC_Curve;
137typedef field Field;
138
660b443c 139#define XSINTERFACE_FUNC_SETMP(cv, f) \
140 CvXSUBANY(cv).any_dptr = (void (*) _((void *)))(mp_##f)
a1a90aaf 141#define XSINTERFACE_FUNC_SETGF(cv, f) \
142 CvXSUBANY(cv).any_dptr = (void (*) _((void *)))(gf_##f)
660b443c 143
144#define SET_MP(sv, x) SET(sv, x, "Catacomb::MP")
145#define RET_MP(x) RET(x, "Catacomb::MP")
146
a1a90aaf 147#define SET_GF(sv, x) SET(sv, x, "Catacomb::GF")
148#define RET_GF(x) RET(x, "Catacomb::GF")
149
660b443c 150extern mp *mp_fromiv(mp *d, IV iv);
151extern IV mp_toiv(mp *x);
152extern mp *mp_readsv(mp *m, SV *sv, STRLEN *off, int radix);
153extern int mp_writesv(mp *m, SV *sv, int radix);
a1a90aaf 154extern mp *mp_fromsv(SV *sv, const char *what, const char *ty,
155 int radix, int keep, ...);
660b443c 156
157/*----- Prime generation --------------------------------------------------*/
158
159typedef struct { pfilt pf; int rc; } MP_Prime_Filter;
160typedef rabin MP_Prime_Rabin;
161typedef SV MP_Prime_Gen_Proc, MP_Prime_Gen_NullProc;
162typedef struct { pgen_proc *p; void *ctx; } pgmagic, MP_Prime_Gen_MagicProc;
163typedef struct { pgmagic mg; pgen_filterctx f; } MP_Prime_Gen_FilterStepper;
164typedef struct { pgmagic mg; pgen_jumpctx j; pfilt pf; }
165 MP_Prime_Gen_JumpStepper;
166typedef struct { pgmagic mg; rabin r; } MP_Prime_Gen_RabinTester;
167typedef struct pgen_event MP_Prime_Gen_Event;
168
169extern void pgproc_get(SV *sv, pgen_proc **p, void **ctx);
170
f9952aec 171/*----- Other gear --------------------------------------------------------*/
172
173extern field *copy_field(field *f);
174extern ec_curve *copy_curve(ec_curve *c);
175extern group *copy_group(group *g);
176
660b443c 177/*----- That's all, folks -------------------------------------------------*/
178
179#ifdef __cplusplus
180 }
181#endif
182
183#endif