Various changes. Kinda in the middle of it here, but it seems to work.
[catacomb-perl] / catacomb-perl.h
1 /* -*-c-*-
2 *
3 * $Id$
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
29 #ifndef CATACOMB_PERL_H
30 #define CATACOMB_PERL_H
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /*----- Header files ------------------------------------------------------*/
37
38 #include <EXTERN.h>
39 #include <perl.h>
40 #include <XSUB.h>
41
42 #include <assert.h>
43 #include <stdio.h>
44 #include <stdarg.h>
45 #include <stdlib.h>
46 #include <string.h>
47
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
59 #include <catacomb/key.h>
60 #include <catacomb/passphrase.h>
61
62 #include <catacomb/mp.h>
63 #include <catacomb/gf.h>
64 #include <catacomb/ec.h>
65 #include <catacomb/field.h>
66 #include <catacomb/group.h>
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>
73 #include <catacomb/mpreduce.h>
74 #include <catacomb/gfreduce.h>
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
84 struct consttab { const char *name; UV val; };
85
86 extern U32 findconst(const struct consttab *cc,
87 const char *pkg, const char *name);
88 extern void ptrtosv(SV **sv, void *p, const char *type);
89 extern void *ptrfromsv(SV *sv, const char *type, const char *what, ...);
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
96 struct randtab { const char *name; grand *(*rand)(const void *, size_t); };
97
98 typedef const octet keysize;
99 typedef gmac gMAC;
100 typedef gcmac gcMAC;
101
102 typedef grand Rand_True, Rand_DSA;
103
104 extern const struct randtab mgftab[], ctrtab[], ofbtab[];
105
106 extern SV *findrand(const struct randtab *rt, const char *cls,
107 const char *name, SV *k);
108 extern void listrand(const struct randtab *rt);
109
110 /*------ Key mangling -----------------------------------------------------*/
111
112 typedef struct Key {
113 key_file *kf;
114 key *k;
115 } Key;
116
117 typedef int KeyErr;
118 typedef key_data Key_Data;
119 typedef key_file Key_File;
120
121 extern void warn_keyreporter(const char *file, int line,
122 const char *err, void *p);
123 extern SV *keyerr(int rc);
124
125 /*------ Multiprecision maths ---------------------------------------------*/
126
127 typedef mp gf;
128 typedef mpmont MP_Mont;
129 typedef mpbarrett MP_Barrett;
130 typedef mpcrt MP_CRT;
131
132 typedef mpreduce MP_Reduce;
133 typedef gfreduce GF_Reduce;
134
135 typedef ec EC_Point;
136 typedef ec_curve EC_Curve;
137 typedef field Field;
138
139 #define XSINTERFACE_FUNC_SETMP(cv, f) \
140 CvXSUBANY(cv).any_dptr = (void (*) _((void *)))(mp_##f)
141 #define XSINTERFACE_FUNC_SETGF(cv, f) \
142 CvXSUBANY(cv).any_dptr = (void (*) _((void *)))(gf_##f)
143
144 #define SET_MP(sv, x) SET(sv, x, "Catacomb::MP")
145 #define RET_MP(x) RET(x, "Catacomb::MP")
146
147 #define SET_GF(sv, x) SET(sv, x, "Catacomb::GF")
148 #define RET_GF(x) RET(x, "Catacomb::GF")
149
150 extern mp *mp_fromiv(mp *d, IV iv);
151 extern IV mp_toiv(mp *x);
152 extern mp *mp_readsv(mp *m, SV *sv, STRLEN *off, int radix);
153 extern int mp_writesv(mp *m, SV *sv, int radix);
154 extern mp *mp_fromsv(SV *sv, const char *what, const char *ty,
155 int radix, int keep, ...);
156
157 /*----- Prime generation --------------------------------------------------*/
158
159 typedef struct { pfilt pf; int rc; } MP_Prime_Filter;
160 typedef rabin MP_Prime_Rabin;
161 typedef SV MP_Prime_Gen_Proc, MP_Prime_Gen_NullProc;
162 typedef struct { pgen_proc *p; void *ctx; } pgmagic, MP_Prime_Gen_MagicProc;
163 typedef struct { pgmagic mg; pgen_filterctx f; } MP_Prime_Gen_FilterStepper;
164 typedef struct { pgmagic mg; pgen_jumpctx j; pfilt pf; }
165 MP_Prime_Gen_JumpStepper;
166 typedef struct { pgmagic mg; rabin r; } MP_Prime_Gen_RabinTester;
167 typedef struct pgen_event MP_Prime_Gen_Event;
168
169 extern void pgproc_get(SV *sv, pgen_proc **p, void **ctx);
170
171 /*----- Other gear --------------------------------------------------------*/
172
173 extern field *copy_field(field *f);
174 extern ec_curve *copy_curve(ec_curve *c);
175 extern group *copy_group(group *g);
176
177 /*----- That's all, folks -------------------------------------------------*/
178
179 #ifdef __cplusplus
180 }
181 #endif
182
183 #endif