Initial checkin.
[catacomb-perl] / catacomb-perl.h
1 /* -*-c-*-
2 *
3 * $Id: catacomb-perl.h,v 1.1 2004/04/02 18:04:01 mdw Exp $
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 /*----- Revision history --------------------------------------------------*
30 *
31 * $Log: catacomb-perl.h,v $
32 * Revision 1.1 2004/04/02 18:04:01 mdw
33 * Initial checkin.
34 *
35 */
36
37 #ifndef CATACOMB_PERL_H
38 #define CATACOMB_PERL_H
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /*----- Header files ------------------------------------------------------*/
45
46 #include <assert.h>
47 #include <stdio.h>
48 #include <stdarg.h>
49 #include <stdlib.h>
50 #include <string.h>
51
52 #include <EXTERN.h>
53 #include <perl.h>
54 #include <XSUB.h>
55
56 #include <catacomb/gcipher.h>
57 #include <catacomb/ghash.h>
58 #include <catacomb/gmac.h>
59
60 #include <catacomb/grand.h>
61 #include <catacomb/fibrand.h>
62 #include <catacomb/lcrand.h>
63 #include <catacomb/dsarand.h>
64 #include <catacomb/rand.h>
65 #include <catacomb/noise.h>
66
67 #include <catacomb/passphrase.h>
68
69 #include <catacomb/mp.h>
70 #include <catacomb/mpint.h>
71 #include <catacomb/mpmul.h>
72 #include <catacomb/mprand.h>
73 #include <catacomb/mpcrt.h>
74 #include <catacomb/mpmont.h>
75 #include <catacomb/mpbarrett.h>
76
77 #include <catacomb/pfilt.h>
78 #include <catacomb/rabin.h>
79 #include <catacomb/pgen.h>
80 #include <catacomb/limlee.h>
81 #include <catacomb/strongprime.h>
82
83 /*----- Misc support ------------------------------------------------------*/
84
85 struct consttab { const char *name; UV val; };
86
87 extern U32 findconst(const struct consttab *cc,
88 const char *pkg, const char *name);
89
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 gccipher *ciphertab[];
105 extern const gchash *hashtab[];
106 extern const gcmac *mactab[];
107 extern const struct randtab mgftab[], ctrtab[], ofbtab[];
108
109 extern SV *findrand(const struct randtab *rt, const char *cls,
110 const char *name, SV *k);
111 extern void listrand(const struct randtab *rt);
112
113 /*------ Multiprecision maths ---------------------------------------------*/
114
115 typedef mpmont MP_Mont;
116 typedef mpbarrett MP_Barrett;
117 typedef mpcrt MP_CRT;
118
119 #define XSINTERFACE_FUNC_SETMP(cv, f) \
120 CvXSUBANY(cv).any_dptr = (void (*) _((void *)))(mp_##f)
121
122 #define SET_MP(sv, x) SET(sv, x, "Catacomb::MP")
123 #define RET_MP(x) RET(x, "Catacomb::MP")
124
125 extern mp *mp_fromiv(mp *d, IV iv);
126 extern IV mp_toiv(mp *x);
127 extern mp *mp_readsv(mp *m, SV *sv, STRLEN *off, int radix);
128 extern int mp_writesv(mp *m, SV *sv, int radix);
129 extern mp *mp_fromsv(SV *sv, const char *what, int radix, int keep, ...);
130
131 /*----- Prime generation --------------------------------------------------*/
132
133 typedef struct { pfilt pf; int rc; } MP_Prime_Filter;
134 typedef rabin MP_Prime_Rabin;
135 typedef SV MP_Prime_Gen_Proc, MP_Prime_Gen_NullProc;
136 typedef struct { pgen_proc *p; void *ctx; } pgmagic, MP_Prime_Gen_MagicProc;
137 typedef struct { pgmagic mg; pgen_filterctx f; } MP_Prime_Gen_FilterStepper;
138 typedef struct { pgmagic mg; pgen_jumpctx j; pfilt pf; }
139 MP_Prime_Gen_JumpStepper;
140 typedef struct { pgmagic mg; rabin r; } MP_Prime_Gen_RabinTester;
141 typedef struct pgen_event MP_Prime_Gen_Event;
142
143 extern void pgproc_get(SV *sv, pgen_proc **p, void **ctx);
144
145 /*----- That's all, folks -------------------------------------------------*/
146
147 #ifdef __cplusplus
148 }
149 #endif
150
151 #endif