| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * $Id: catacomb-perl.h,v 1.2 2004/04/08 01:36:21 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 | #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 <assert.h> |
| 39 | #include <stdio.h> |
| 40 | #include <stdarg.h> |
| 41 | #include <stdlib.h> |
| 42 | #include <string.h> |
| 43 | |
| 44 | #include <EXTERN.h> |
| 45 | #include <perl.h> |
| 46 | #include <XSUB.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/passphrase.h> |
| 60 | |
| 61 | #include <catacomb/mp.h> |
| 62 | #include <catacomb/mpint.h> |
| 63 | #include <catacomb/mpmul.h> |
| 64 | #include <catacomb/mprand.h> |
| 65 | #include <catacomb/mpcrt.h> |
| 66 | #include <catacomb/mpmont.h> |
| 67 | #include <catacomb/mpbarrett.h> |
| 68 | |
| 69 | #include <catacomb/pfilt.h> |
| 70 | #include <catacomb/rabin.h> |
| 71 | #include <catacomb/pgen.h> |
| 72 | #include <catacomb/limlee.h> |
| 73 | #include <catacomb/strongprime.h> |
| 74 | |
| 75 | /*----- Misc support ------------------------------------------------------*/ |
| 76 | |
| 77 | struct consttab { const char *name; UV val; }; |
| 78 | |
| 79 | extern U32 findconst(const struct consttab *cc, |
| 80 | const char *pkg, const char *name); |
| 81 | |
| 82 | #define SET(sv, ob, ty) sv_setref_pv((sv), (char *)(ty), (void *)(ob)) |
| 83 | #define MAKE(ob, ty) SET(NEWSV(0, 0), ob, ty) |
| 84 | #define RET(ob, ty) SET(sv_newmortal(), ob, ty) |
| 85 | |
| 86 | /*----- Crypto algorithms -------------------------------------------------*/ |
| 87 | |
| 88 | struct randtab { const char *name; grand *(*rand)(const void *, size_t); }; |
| 89 | |
| 90 | typedef const octet keysize; |
| 91 | typedef gmac gMAC; |
| 92 | typedef gcmac gcMAC; |
| 93 | |
| 94 | typedef grand Rand_True, Rand_DSA; |
| 95 | |
| 96 | extern const gccipher *ciphertab[]; |
| 97 | extern const gchash *hashtab[]; |
| 98 | extern const gcmac *mactab[]; |
| 99 | extern const struct randtab mgftab[], ctrtab[], ofbtab[]; |
| 100 | |
| 101 | extern SV *findrand(const struct randtab *rt, const char *cls, |
| 102 | const char *name, SV *k); |
| 103 | extern void listrand(const struct randtab *rt); |
| 104 | |
| 105 | /*------ Multiprecision maths ---------------------------------------------*/ |
| 106 | |
| 107 | typedef mpmont MP_Mont; |
| 108 | typedef mpbarrett MP_Barrett; |
| 109 | typedef mpcrt MP_CRT; |
| 110 | |
| 111 | #define XSINTERFACE_FUNC_SETMP(cv, f) \ |
| 112 | CvXSUBANY(cv).any_dptr = (void (*) _((void *)))(mp_##f) |
| 113 | |
| 114 | #define SET_MP(sv, x) SET(sv, x, "Catacomb::MP") |
| 115 | #define RET_MP(x) RET(x, "Catacomb::MP") |
| 116 | |
| 117 | extern mp *mp_fromiv(mp *d, IV iv); |
| 118 | extern IV mp_toiv(mp *x); |
| 119 | extern mp *mp_readsv(mp *m, SV *sv, STRLEN *off, int radix); |
| 120 | extern int mp_writesv(mp *m, SV *sv, int radix); |
| 121 | extern mp *mp_fromsv(SV *sv, const char *what, int radix, int keep, ...); |
| 122 | |
| 123 | /*----- Prime generation --------------------------------------------------*/ |
| 124 | |
| 125 | typedef struct { pfilt pf; int rc; } MP_Prime_Filter; |
| 126 | typedef rabin MP_Prime_Rabin; |
| 127 | typedef SV MP_Prime_Gen_Proc, MP_Prime_Gen_NullProc; |
| 128 | typedef struct { pgen_proc *p; void *ctx; } pgmagic, MP_Prime_Gen_MagicProc; |
| 129 | typedef struct { pgmagic mg; pgen_filterctx f; } MP_Prime_Gen_FilterStepper; |
| 130 | typedef struct { pgmagic mg; pgen_jumpctx j; pfilt pf; } |
| 131 | MP_Prime_Gen_JumpStepper; |
| 132 | typedef struct { pgmagic mg; rabin r; } MP_Prime_Gen_RabinTester; |
| 133 | typedef struct pgen_event MP_Prime_Gen_Event; |
| 134 | |
| 135 | extern void pgproc_get(SV *sv, pgen_proc **p, void **ctx); |
| 136 | |
| 137 | /*----- That's all, folks -------------------------------------------------*/ |
| 138 | |
| 139 | #ifdef __cplusplus |
| 140 | } |
| 141 | #endif |
| 142 | |
| 143 | #endif |