Much wider support for Catacomb in all its glory.
[catacomb-perl] / catacomb-perl.h
index ec6d8af..ef36efc 100644 (file)
 
 /*----- Header files ------------------------------------------------------*/
 
+#include <assert.h>
+
 #include <EXTERN.h>
 #include <perl.h>
 #include <XSUB.h>
 
-#include <assert.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <catacomb/blkc.h>
 #include <catacomb/gcipher.h>
 #include <catacomb/ghash.h>
 #include <catacomb/gmac.h>
 #include <catacomb/rand.h>
 #include <catacomb/noise.h>
 
+#include <catacomb/share.h>
+#include <catacomb/gfshare.h>
+
 #include <catacomb/key.h>
 #include <catacomb/passphrase.h>
 
 #include <catacomb/mp.h>
 #include <catacomb/gf.h>
 #include <catacomb/ec.h>
+#include <catacomb/rsa.h>
+#include <catacomb/dh.h>
+#include <catacomb/dsa.h>
+#include <catacomb/gdsa.h>
+#include <catacomb/gkcdsa.h>
 #include <catacomb/field.h>
 #include <catacomb/group.h>
 #include <catacomb/mpint.h>
 
 struct consttab { const char *name; UV val; };
 
+typedef struct cursor {
+  unsigned f;
+  union {
+    HV *hv;
+    struct { AV *av; unsigned i; } a;
+  } u;
+} cursor;
+#define CF_ARRAY 0u
+#define CF_HASH 1u
+#define CF_MUST 1u
+
 extern U32 findconst(const struct consttab *cc,
                     const char *pkg, const char *name);
 extern void ptrtosv(SV **sv, void *p, const char *type);
 extern void *ptrfromsv(SV *sv, const char *type, const char *what, ...);
+extern void *ptrfromsvdflt(SV *sv, const char *type, void *dflt,
+                          const char *what);
+extern void c_init(cursor *c, SV *sv);
+extern void c_skip(cursor *c);
+extern SV *c_get(cursor *c, const char *tag, unsigned f);
+extern ge *groupelt(SV *sv, const char *what);
+extern mp *fieldelt(SV *sv, const char *what);
+extern ec *ecpt(SV *sv, const char *what);
+
 #define SET(sv, ob, ty) sv_setref_pv((sv), (char *)(ty), (void *)(ob))
 #define MAKE(ob, ty) SET(NEWSV(0, 0), ob, ty)
 #define RET(ob, ty) SET(sv_newmortal(), ob, ty)
+#define C_MP(c, tag) mp_fromsv(c_get(c, tag, CF_MUST), tag, 0, 0)
+#define C_PTR(c, tag, type) ptrfromsv(c_get(c, tag, CF_MUST), type, tag)
+#define C_PTRDFLT(c, tag, type, def)                                   \
+  ptrfromsvdflt(c_get(c, tag, 0), type, def, tag)
+#define C_GE(c, tag) groupelt(c_get(c, tag, CF_MUST), tag)
+#define C_FE(c, tag) fieldelt(c_get(c, tag, CF_MUST), tag)
+#define C_EC(c, tag) ecpt(c_get(c, tag, CF_MUST), tag)
+extern void hvput(HV *hv, const char *k, SV *val);
 
 /*----- Crypto algorithms -------------------------------------------------*/
 
+typedef struct PRPClass {
+  char *name;
+  const octet *ksz;
+  size_t ctxsz;
+  size_t blksz;
+  void (*init)(void *ctx, const void *k, size_t sz);
+  void (*eblk)(const void *ctx, const void *in, void *out);
+  void (*dblk)(const void *ctx, const void *in, void *out);  
+} PRPClass;
+
+typedef struct PRP {
+  PRPClass *c;
+} PRP;
+
+extern PRPClass *const prptab[];
+  
 struct randtab { const char *name; grand *(*rand)(const void *, size_t); };
 
 typedef const octet keysize;
@@ -101,25 +155,46 @@ typedef gcmac gcMAC;
 
 typedef grand Rand_True, Rand_DSA;
 
+typedef rsa_pubctx RSA_Public;
+typedef rsa_privctx RSA_Private;
+
+typedef gfshare Share_GF;
+typedef share Share_Prime;
+
 extern const struct randtab mgftab[], ctrtab[], ofbtab[];
 
+extern void gdsa_privfromsv(gdsa *g, SV *sv);
+extern void gdsa_pubfromsv(gdsa *g, SV *sv);
 extern SV *findrand(const struct randtab *rt, const char *cls,
                    const char *name, SV *k);
 extern void listrand(const struct randtab *rt);
 
 /*------ Key mangling -----------------------------------------------------*/
 
+typedef struct Key_File {
+  unsigned ref;
+  key_file kf;
+} Key_File;
+
 typedef struct Key {
-  key_file *kf;
+  Key_File *kf;
   key *k;
 } Key;
+typedef struct Key_AttrIter {
+  Key_File *kf;
+  key_attriter i;
+} Key_AttrIter;
 
 typedef int KeyErr;
-typedef key_data Key_Data;
-typedef key_file Key_File;
-
-extern void warn_keyreporter(const char *file, int line,
-                            const char *err, void *p);
+typedef key_data Key_DataImpl;
+typedef struct Key_FileIter {
+  Key_File *kf;
+  key_iter i;
+} Key_FileIter;
+typedef sym_iter Key_StructIter;
+typedef key_filter Key_Filter;
+
+extern void keyreport(const char *file, int line, const char *err, void *p);
 extern SV *keyerr(int rc);
 
 /*------ Multiprecision maths ---------------------------------------------*/
@@ -132,9 +207,11 @@ typedef mpcrt MP_CRT;
 typedef mpreduce MP_Reduce;
 typedef gfreduce GF_Reduce;
 
-typedef ec EC_Point;
 typedef ec_curve EC_Curve;
 typedef field Field;
+typedef mp fe;
+
+typedef group Group;
 
 #define XSINTERFACE_FUNC_SETMP(cv, f) \
   CvXSUBANY(cv).any_dptr = (void (*) _((void *)))(mp_##f)
@@ -142,17 +219,19 @@ typedef field Field;
   CvXSUBANY(cv).any_dptr = (void (*) _((void *)))(gf_##f)
 
 #define SET_MP(sv, x) SET(sv, x, "Catacomb::MP")
+#define MAKE_MP(x) MAKE(x, "Catacomb::MP")
 #define RET_MP(x) RET(x, "Catacomb::MP")
 
 #define SET_GF(sv, x) SET(sv, x, "Catacomb::GF")
+#define MAKE_GF(x) MAKE(x, "Catacomb::GF")
 #define RET_GF(x) RET(x, "Catacomb::GF")
 
 extern mp *mp_fromiv(mp *d, IV iv);
 extern IV mp_toiv(mp *x);
 extern mp *mp_readsv(mp *m, SV *sv, STRLEN *off, int radix);
 extern int mp_writesv(mp *m, SV *sv, int radix);
-extern mp *mp_fromsv(SV *sv, const char *what, const char *ty,
-                    int radix, int keep, ...);
+extern mp *mp_fromsv(SV *sv, const char *what, int radix, int keep, ...);
+extern int group_writesv(group *g, ge *x, SV *sv);
 
 /*----- Prime generation --------------------------------------------------*/
 
@@ -170,6 +249,12 @@ extern void pgproc_get(SV *sv, pgen_proc **p, void **ctx);
 
 /*----- Other gear --------------------------------------------------------*/
 
+extern void names(const char *name);
+
+extern SV *info_field(field *f);
+extern SV *info_curve(ec_curve *c);
+extern SV *info_group(group *g);
+
 extern field *copy_field(field *f);
 extern ec_curve *copy_curve(ec_curve *c);
 extern group *copy_group(group *g);