Key mangling, and elliptic curves.
[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/mpint.h>
67 #include <catacomb/mpmul.h>
68 #include <catacomb/mprand.h>
69 #include <catacomb/mpcrt.h>
70 #include <catacomb/mpmont.h>
71 #include <catacomb/mpbarrett.h>
72 #include <catacomb/mpreduce.h>
73 #include <catacomb/gfreduce.h>
74
75 #include <catacomb/pfilt.h>
76 #include <catacomb/rabin.h>
77 #include <catacomb/pgen.h>
78 #include <catacomb/limlee.h>
79 #include <catacomb/strongprime.h>
80
81 /*----- Misc support ------------------------------------------------------*/
82
83 struct consttab { const char *name; UV val; };
84
85 extern U32 findconst(const struct consttab *cc,
86 const char *pkg, const char *name);
87 extern void ptrtosv(SV **sv, void *p, const char *type);
88 extern void *ptrfromsv(SV *sv, const char *type, const char *what, ...);
89 #define SET(sv, ob, ty) sv_setref_pv((sv), (char *)(ty), (void *)(ob))
90 #define MAKE(ob, ty) SET(NEWSV(0, 0), ob, ty)
91 #define RET(ob, ty) SET(sv_newmortal(), ob, ty)
92
93 /*----- Crypto algorithms -------------------------------------------------*/
94
95 struct randtab { const char *name; grand *(*rand)(const void *, size_t); };
96
97 typedef const octet keysize;
98 typedef gmac gMAC;
99 typedef gcmac gcMAC;
100
101 typedef grand Rand_True, Rand_DSA;
102
103 extern const struct randtab mgftab[], ctrtab[], ofbtab[];
104
105 extern SV *findrand(const struct randtab *rt, const char *cls,
106 const char *name, SV *k);
107 extern void listrand(const struct randtab *rt);
108
109 /*------ Key mangling -----------------------------------------------------*/
110
111 typedef struct Key {
112 key_file *kf;
113 key *k;
114 } Key;
115
116 typedef int KeyErr;
117 typedef key_data Key_Data;
118 typedef key_file Key_File;
119
120 extern void warn_keyreporter(const char *file, int line,
121 const char *err, void *p);
122 extern SV *keyerr(int rc);
123
124 /*------ Multiprecision maths ---------------------------------------------*/
125
126 typedef mp gf;
127 typedef mpmont MP_Mont;
128 typedef mpbarrett MP_Barrett;
129 typedef mpcrt MP_CRT;
130
131 typedef mpreduce MP_Reduce;
132 typedef gfreduce GF_Reduce;
133
134 typedef ec EC_Point;
135 typedef ec_curve EC_Curve;
136 typedef field Field;
137
138 #define XSINTERFACE_FUNC_SETMP(cv, f) \
139 CvXSUBANY(cv).any_dptr = (void (*) _((void *)))(mp_##f)
140 #define XSINTERFACE_FUNC_SETGF(cv, f) \
141 CvXSUBANY(cv).any_dptr = (void (*) _((void *)))(gf_##f)
142
143 #define SET_MP(sv, x) SET(sv, x, "Catacomb::MP")
144 #define RET_MP(x) RET(x, "Catacomb::MP")
145
146 #define SET_GF(sv, x) SET(sv, x, "Catacomb::GF")
147 #define RET_GF(x) RET(x, "Catacomb::GF")
148
149 extern mp *mp_fromiv(mp *d, IV iv);
150 extern IV mp_toiv(mp *x);
151 extern mp *mp_readsv(mp *m, SV *sv, STRLEN *off, int radix);
152 extern int mp_writesv(mp *m, SV *sv, int radix);
153 extern mp *mp_fromsv(SV *sv, const char *what, const char *ty,
154 int radix, int keep, ...);
155
156 /*----- Prime generation --------------------------------------------------*/
157
158 typedef struct { pfilt pf; int rc; } MP_Prime_Filter;
159 typedef rabin MP_Prime_Rabin;
160 typedef SV MP_Prime_Gen_Proc, MP_Prime_Gen_NullProc;
161 typedef struct { pgen_proc *p; void *ctx; } pgmagic, MP_Prime_Gen_MagicProc;
162 typedef struct { pgmagic mg; pgen_filterctx f; } MP_Prime_Gen_FilterStepper;
163 typedef struct { pgmagic mg; pgen_jumpctx j; pfilt pf; }
164 MP_Prime_Gen_JumpStepper;
165 typedef struct { pgmagic mg; rabin r; } MP_Prime_Gen_RabinTester;
166 typedef struct pgen_event MP_Prime_Gen_Event;
167
168 extern void pgproc_get(SV *sv, pgen_proc **p, void **ctx);
169
170 /*----- That's all, folks -------------------------------------------------*/
171
172 #ifdef __cplusplus
173 }
174 #endif
175
176 #endif