5 * Main header file for Catacomb/Perl
7 * (c) 2001 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the Perl interface to Catacomb.
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.
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.
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.
29 #ifndef CATACOMB_PERL_H
30 #define CATACOMB_PERL_H
36 /*----- Header files ------------------------------------------------------*/
49 #include <catacomb/blkc.h>
50 #include <catacomb/gcipher.h>
51 #include <catacomb/ghash.h>
52 #include <catacomb/gmac.h>
54 #include <catacomb/grand.h>
55 #include <catacomb/fibrand.h>
56 #include <catacomb/lcrand.h>
57 #include <catacomb/dsarand.h>
58 #include <catacomb/rand.h>
59 #include <catacomb/noise.h>
61 #include <catacomb/share.h>
62 #include <catacomb/gfshare.h>
64 #include <catacomb/key.h>
65 #include <catacomb/passphrase.h>
67 #include <catacomb/mp.h>
68 #include <catacomb/gf.h>
69 #include <catacomb/ec.h>
70 #include <catacomb/rsa.h>
71 #include <catacomb/dh.h>
72 #include <catacomb/dsa.h>
73 #include <catacomb/gdsa.h>
74 #include <catacomb/gkcdsa.h>
75 #include <catacomb/field.h>
76 #include <catacomb/group.h>
77 #include <catacomb/mpint.h>
78 #include <catacomb/mpmul.h>
79 #include <catacomb/mprand.h>
80 #include <catacomb/mpcrt.h>
81 #include <catacomb/mpmont.h>
82 #include <catacomb/mpbarrett.h>
83 #include <catacomb/mpreduce.h>
84 #include <catacomb/gfreduce.h>
86 #include <catacomb/pfilt.h>
87 #include <catacomb/rabin.h>
88 #include <catacomb/pgen.h>
89 #include <catacomb/limlee.h>
90 #include <catacomb/strongprime.h>
92 /*----- Misc support ------------------------------------------------------*/
94 struct consttab { const char *name; UV val; };
96 typedef struct cursor {
100 struct { AV *av; unsigned i; } a;
107 extern U32 findconst(const struct consttab *cc,
108 const char *pkg, const char *name);
109 extern void ptrtosv(SV **sv, void *p, const char *type);
110 extern void *ptrfromsv(SV *sv, const char *type, const char *what, ...);
111 extern void *ptrfromsvdflt(SV *sv, const char *type, void *dflt,
113 extern void c_init(cursor *c, SV *sv);
114 extern void c_skip(cursor *c);
115 extern SV *c_get(cursor *c, const char *tag, unsigned f);
116 extern ge *groupelt(SV *sv, const char *what);
117 extern mp *fieldelt(SV *sv, const char *what);
118 extern ec *ecpt(SV *sv, const char *what);
120 #define SET(sv, ob, ty) sv_setref_pv((sv), (char *)(ty), (void *)(ob))
121 #define MAKE(ob, ty) SET(NEWSV(0, 0), ob, ty)
122 #define RET(ob, ty) SET(sv_newmortal(), ob, ty)
123 #define C_MP(c, tag) mp_fromsv(c_get(c, tag, CF_MUST), tag, 0, 0)
124 #define C_PTR(c, tag, type) ptrfromsv(c_get(c, tag, CF_MUST), type, tag)
125 #define C_PTRDFLT(c, tag, type, def) \
126 ptrfromsvdflt(c_get(c, tag, 0), type, def, tag)
127 #define C_GE(c, tag) groupelt(c_get(c, tag, CF_MUST), tag)
128 #define C_FE(c, tag) fieldelt(c_get(c, tag, CF_MUST), tag)
129 #define C_EC(c, tag) ecpt(c_get(c, tag, CF_MUST), tag)
130 extern void hvput(HV *hv, const char *k, SV *val);
132 /*----- Crypto algorithms -------------------------------------------------*/
134 typedef struct PRPClass {
139 void (*init)(void *ctx, const void *k, size_t sz);
140 void (*eblk)(const void *ctx, const void *in, void *out);
141 void (*dblk)(const void *ctx, const void *in, void *out);
148 extern PRPClass *const prptab[];
150 struct randtab { const char *name; grand *(*rand)(const void *, size_t); };
152 typedef const octet keysize;
156 typedef grand Rand_True, Rand_DSA;
158 typedef rsa_pubctx RSA_Public;
159 typedef rsa_privctx RSA_Private;
161 typedef gfshare Share_GF;
162 typedef share Share_Prime;
164 extern const struct randtab mgftab[], ctrtab[], ofbtab[];
166 extern void gdsa_privfromsv(gdsa *g, SV *sv);
167 extern void gdsa_pubfromsv(gdsa *g, SV *sv);
168 extern SV *findrand(const struct randtab *rt, const char *cls,
169 const char *name, SV *k);
170 extern void listrand(const struct randtab *rt);
172 /*------ Key mangling -----------------------------------------------------*/
174 typedef struct Key_File {
183 typedef struct Key_AttrIter {
189 typedef key_data Key_DataImpl;
190 typedef struct Key_FileIter {
194 typedef sym_iter Key_StructIter;
195 typedef key_filter Key_Filter;
197 extern void keyreport(const char *file, int line, const char *err, void *p);
198 extern SV *keyerr(int rc);
200 /*------ Multiprecision maths ---------------------------------------------*/
203 typedef mpmont MP_Mont;
204 typedef mpbarrett MP_Barrett;
205 typedef mpcrt MP_CRT;
207 typedef mpreduce MP_Reduce;
208 typedef gfreduce GF_Reduce;
210 typedef ec_curve EC_Curve;
216 #define XSINTERFACE_FUNC_SETMP(cv, f) \
217 CvXSUBANY(cv).any_dptr = (void (*) _((void *)))(mp_##f)
218 #define XSINTERFACE_FUNC_SETGF(cv, f) \
219 CvXSUBANY(cv).any_dptr = (void (*) _((void *)))(gf_##f)
221 #define SET_MP(sv, x) SET(sv, x, "Catacomb::MP")
222 #define MAKE_MP(x) MAKE(x, "Catacomb::MP")
223 #define RET_MP(x) RET(x, "Catacomb::MP")
225 #define SET_GF(sv, x) SET(sv, x, "Catacomb::GF")
226 #define MAKE_GF(x) MAKE(x, "Catacomb::GF")
227 #define RET_GF(x) RET(x, "Catacomb::GF")
229 extern mp *mp_fromiv(mp *d, IV iv);
230 extern IV mp_toiv(mp *x);
231 extern mp *mp_readsv(mp *m, SV *sv, STRLEN *off, int radix);
232 extern int mp_writesv(mp *m, SV *sv, int radix);
233 extern mp *mp_fromsv(SV *sv, const char *what, int radix, int keep, ...);
234 extern int group_writesv(group *g, ge *x, SV *sv);
236 /*----- Prime generation --------------------------------------------------*/
238 typedef struct { pfilt pf; int rc; } MP_Prime_Filter;
239 typedef rabin MP_Prime_Rabin;
240 typedef SV MP_Prime_Gen_Proc, MP_Prime_Gen_NullProc;
241 typedef struct { pgen_proc *p; void *ctx; } pgmagic, MP_Prime_Gen_MagicProc;
242 typedef struct { pgmagic mg; pgen_filterctx f; } MP_Prime_Gen_FilterStepper;
243 typedef struct { pgmagic mg; pgen_jumpctx j; pfilt pf; }
244 MP_Prime_Gen_JumpStepper;
245 typedef struct { pgmagic mg; rabin r; } MP_Prime_Gen_RabinTester;
246 typedef struct pgen_event MP_Prime_Gen_Event;
248 extern void pgproc_get(SV *sv, pgen_proc **p, void **ctx);
250 /*----- Other gear --------------------------------------------------------*/
252 extern void names(const char *name);
254 extern SV *info_field(field *f);
255 extern SV *info_curve(ec_curve *c);
256 extern SV *info_group(group *g);
258 extern field *copy_field(field *f);
259 extern ec_curve *copy_curve(ec_curve *c);
260 extern group *copy_group(group *g);
262 /*----- That's all, folks -------------------------------------------------*/