chiark / gitweb /
algorithms: Add PRPs as objects in their own right.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 28 Jan 2006 18:07:53 +0000 (18:07 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 28 Jan 2006 18:07:53 +0000 (18:07 +0000)
algorithms.c
algorithms.h
algorithms.py
catacomb-python.h

index cd7a04d5ad8482a8dd05b60fc60b3e90d999aaf3..71b8e560f7ec51e6c7451d1d963b6f1d6c7ee829 100644 (file)
@@ -1166,6 +1166,251 @@ static PyTypeObject gmhash_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
+/*----- Pseudorandom permutations -----------------------------------------*/
+
+static PyTypeObject *gcprp_pytype, *gprp_pytype;
+
+typedef struct prpinfo {
+  const char *name;
+  const octet *keysz;
+  size_t ctxsz;
+  size_t blksz;
+  void (*init)(void *, const void *, size_t);
+  void (*eblk)(void *, const void *, void *);
+  void (*dblk)(void *, const void *, void *);
+} prpinfo;
+
+#define PRP_DEF(PRE, pre)                                              \
+  static void pre##_prpinit(void *ctx, const void *k, size_t ksz)      \
+    { pre##_init(ctx, k, ksz); }                                       \
+  static void pre##_prpeblk(void *ctx, const void *in, void *out)      \
+  {                                                                    \
+    uint32 w[PRE##_BLKSZ/4]; BLKC_LOAD(PRE, w, in);                    \
+    pre##_eblk(ctx, w, w); BLKC_STORE(PRE, out, w);                    \
+  }                                                                    \
+  static void pre##_prpdblk(void *ctx, const void *in, void *out)      \
+  {                                                                    \
+    uint32 w[PRE##_BLKSZ/4]; BLKC_LOAD(PRE, w, in);                    \
+    pre##_dblk(ctx, w, w); BLKC_STORE(PRE, out, w);                    \
+  }                                                                    \
+  static const prpinfo pre##_prpinfo = {                               \
+    #pre, pre##_keysz, sizeof(pre##_ctx), PRE##_BLKSZ,                 \
+    pre##_prpinit, pre##_prpeblk, pre##_prpdblk                                \
+  };
+PRPS(PRP_DEF)
+
+static const struct prpinfo *const gprptab[] = {
+#define PRP_ENTRY(PRE, pre) &pre##_prpinfo,
+  PRPS(PRP_ENTRY)
+  0
+};    
+
+typedef struct gcprp_pyobj {
+  PyHeapTypeObject ty;
+  const prpinfo *prp;
+} gcprp_pyobj;
+#define GCPRP_PRP(o) (((gcprp_pyobj *)(o))->prp)
+
+typedef struct gprp_pyobj {
+  PyObject_HEAD
+  const prpinfo *prp;
+} gprp_pyobj;
+#define GPRP_PRP(o) (((gprp_pyobj *)(o))->prp)
+#define GPRP_CTX(o) (((gprp_pyobj *)(o)) + 1)
+
+typedef struct prp {
+  const prpinfo *prp;
+  void *ctx;
+} prp;
+
+static PyObject *gprp_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
+{
+  char *kwlist[] = { "key", 0 };
+  char *k;
+  int sz;
+  const prpinfo *prp = GCPRP_PRP(ty);
+  PyObject *me;
+
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", kwlist, &k, &sz))
+    goto end;
+  if (keysz(sz, prp->keysz) != sz) VALERR("bad key length");
+  me = (PyObject *)ty->tp_alloc(ty, 0);
+  GPRP_PRP(me) = prp;
+  prp->init(GPRP_CTX(me), k, sz);
+  Py_INCREF(me);
+  return (me);
+end:
+  return (0);  
+}
+
+static void gprp_pydealloc(PyObject *me)
+  { Py_DECREF(me->ob_type); FREEOBJ(me); }
+
+static PyObject *gcprp_pywrap(const prpinfo *prp)
+{
+  gcprp_pyobj *g = newtype(gcprp_pytype, 0, prp->name);
+  g->prp = prp;
+  g->ty.type.tp_basicsize = sizeof(gprp_pyobj) + prp->ctxsz;
+  g->ty.type.tp_base = gprp_pytype;
+  Py_INCREF(gprp_pytype);
+  g->ty.type.tp_flags = (Py_TPFLAGS_DEFAULT |
+                        Py_TPFLAGS_BASETYPE |
+                        Py_TPFLAGS_HEAPTYPE);
+  g->ty.type.tp_alloc = PyType_GenericAlloc;
+  g->ty.type.tp_free = 0;
+  g->ty.type.tp_new = gprp_pynew;
+  PyType_Ready(&g->ty.type);
+  return ((PyObject *)g);
+}
+
+static PyObject *gcpget_name(PyObject *me, void *hunoz)
+  { return (PyString_FromString(GCPRP_PRP(me)->name)); }
+static PyObject *gcpget_keysz(PyObject *me, void *hunoz)
+  { return (keysz_pywrap(GCPRP_PRP(me)->keysz)); }
+static PyObject *gcpget_blksz(PyObject *me, void *hunoz)
+  { return (PyInt_FromLong(GCPRP_PRP(me)->blksz)); }
+
+static PyObject *gpmeth_encrypt(PyObject *me, PyObject *arg)
+{
+  char *p;
+  int n;
+  PyObject *rc = 0;
+
+  if (!PyArg_ParseTuple(arg, "s#:encrypt", &p, &n)) goto end;
+  if (n != GPRP_PRP(me)->blksz) VALERR("incorrect block length");
+  rc = bytestring_pywrap(0, n);
+  GPRP_PRP(me)->eblk(GPRP_CTX(me), p, PyString_AS_STRING(rc));
+end:
+  return (rc);
+}
+
+static PyObject *gpmeth_decrypt(PyObject *me, PyObject *arg)
+{
+  char *p;
+  int n;
+  PyObject *rc = 0;
+
+  if (!PyArg_ParseTuple(arg, "s#:decrypt", &p, &n)) goto end;
+  if (n != GPRP_PRP(me)->blksz) VALERR("incorrect block length");
+  rc = bytestring_pywrap(0, n);
+  GPRP_PRP(me)->dblk(GPRP_CTX(me), p, PyString_AS_STRING(rc));
+end:
+  return (rc);
+}
+
+static PyGetSetDef gcprp_pygetset[] = {
+#define GETSETNAME(op, name) gcp##op##_##name
+  GET  (keysz,                 "CP.keysz -> acceptable key sizes")
+  GET  (blksz,                 "CP.blksz -> block size")
+  GET  (name,                  "CP.name -> name of this kind of PRP")
+#undef GETSETNAME
+  { 0 }
+};
+
+static PyMethodDef gprp_pymethods[] = {
+#define METHNAME(name) gpmeth_##name
+  METH (encrypt,               "P.encrypt(PT) -> CT")
+  METH (decrypt,               "P.decrypt(CT) -> PT")
+#undef METHNAME
+  { 0 }
+};
+
+static PyTypeObject gcprp_pytype_skel = {
+  PyObject_HEAD_INIT(0) 0,             /* Header */
+  "catacomb.GCPRP",                    /* @tp_name@ */
+  sizeof(gcprp_pyobj),                 /* @tp_basicsize@ */
+  0,                                   /* @tp_itemsize@ */
+
+  0,                                   /* @tp_dealloc@ */
+  0,                                   /* @tp_print@ */
+  0,                                   /* @tp_getattr@ */
+  0,                                   /* @tp_setattr@ */
+  0,                                   /* @tp_compare@ */
+  0,                                   /* @tp_repr@ */
+  0,                                   /* @tp_as_number@ */
+  0,                                   /* @tp_as_sequence@ */
+  0,                                   /* @tp_as_mapping@ */
+  0,                                   /* @tp_hash@ */
+  0,                                   /* @tp_call@ */
+  0,                                   /* @tp_str@ */
+  0,                                   /* @tp_getattro@ */
+  0,                                   /* @tp_setattro@ */
+  0,                                   /* @tp_as_buffer@ */
+  Py_TPFLAGS_DEFAULT |                 /* @tp_flags@ */
+    Py_TPFLAGS_BASETYPE,
+
+  /* @tp_doc@ */
+"Pseudorandom permutation metaclass.",
+
+  0,                                   /* @tp_traverse@ */
+  0,                                   /* @tp_clear@ */
+  0,                                   /* @tp_richcompare@ */
+  0,                                   /* @tp_weaklistoffset@ */
+  0,                                   /* @tp_iter@ */
+  0,                                   /* @tp_iternext@ */
+  0,                                   /* @tp_methods@ */
+  0,                                   /* @tp_members@ */
+  gcprp_pygetset,                      /* @tp_getset@ */
+  0,                                   /* @tp_base@ */
+  0,                                   /* @tp_dict@ */
+  0,                                   /* @tp_descr_get@ */
+  0,                                   /* @tp_descr_set@ */
+  0,                                   /* @tp_dictoffset@ */
+  0,                                   /* @tp_init@ */
+  PyType_GenericAlloc,                 /* @tp_alloc@ */
+  abstract_pynew,                      /* @tp_new@ */
+  0,                                   /* @tp_free@ */
+  0                                    /* @tp_is_gc@ */
+};
+
+static PyTypeObject gprp_pytype_skel = {
+  PyObject_HEAD_INIT(0) 0,             /* Header */
+  "catacomb.GPRP",                     /* @tp_name@ */
+  sizeof(gprp_pyobj),                  /* @tp_basicsize@ */
+  0,                                   /* @tp_itemsize@ */
+
+  gprp_pydealloc,                      /* @tp_dealloc@ */
+  0,                                   /* @tp_print@ */
+  0,                                   /* @tp_getattr@ */
+  0,                                   /* @tp_setattr@ */
+  0,                                   /* @tp_compare@ */
+  0,                                   /* @tp_repr@ */
+  0,                                   /* @tp_as_number@ */
+  0,                                   /* @tp_as_sequence@ */
+  0,                                   /* @tp_as_mapping@ */
+  0,                                   /* @tp_hash@ */
+  0,                                   /* @tp_call@ */
+  0,                                   /* @tp_str@ */
+  0,                                   /* @tp_getattro@ */
+  0,                                   /* @tp_setattro@ */
+  0,                                   /* @tp_as_buffer@ */
+  Py_TPFLAGS_DEFAULT |                 /* @tp_flags@ */
+    Py_TPFLAGS_BASETYPE,
+
+  /* @tp_doc@ */
+"Pseudorandom permutation, abstract base class.",
+
+  0,                                   /* @tp_traverse@ */
+  0,                                   /* @tp_clear@ */
+  0,                                   /* @tp_richcompare@ */
+  0,                                   /* @tp_weaklistoffset@ */
+  0,                                   /* @tp_iter@ */
+  0,                                   /* @tp_iternext@ */
+  gprp_pymethods,                      /* @tp_methods@ */
+  0,                                   /* @tp_members@ */
+  0,                                   /* @tp_getset@ */
+  0,                                   /* @tp_base@ */
+  0,                                   /* @tp_dict@ */
+  0,                                   /* @tp_descr_get@ */
+  0,                                   /* @tp_descr_set@ */
+  0,                                   /* @tp_dictoffset@ */
+  0,                                   /* @tp_init@ */
+  PyType_GenericAlloc,                 /* @tp_alloc@ */
+  abstract_pynew,                      /* @tp_new@ */
+  0,                                   /* @tp_free@ */
+  0                                    /* @tp_is_gc@ */
+};
+
 /*----- Main code ---------------------------------------------------------*/
 
 void algorithms_pyinit(void)
@@ -1181,6 +1426,8 @@ void algorithms_pyinit(void)
   INITTYPE(gcmac, type);
   INITTYPE(gmac, type);
   INITTYPE(gmhash, ghash);
+  INITTYPE(gcprp, type);
+  INITTYPE(gprp, root);
 }
 
 #define GEN(func, base)                                                        \
@@ -1202,6 +1449,8 @@ void algorithms_pyinit(void)
 GEN(gcciphers, cipher)
 GEN(gchashes, hash)
 GEN(gcmacs, mac)
+#define gcprp prpinfo
+GEN(gcprps, prp)
 
 void algorithms_pyinsert(PyObject *mod)
 {
@@ -1222,6 +1471,9 @@ void algorithms_pyinsert(PyObject *mod)
   INSERT("GMAC", gmac_pytype);
   INSERT("GMACHash", gmhash_pytype);
   INSERT("gcmacs", gcmacs());
+  INSERT("GCPRP", gcprp_pytype);
+  INSERT("GPRP", gprp_pytype);
+  INSERT("gcprps", gcprps());
 }
 
 /*----- That's all, folks -------------------------------------------------*/
index 26099ebce987e45b9d83d6a3025024fc0126add0..3ebef05a3675fa809eda876302bf2a04277be95e 100644 (file)
 #include <catacomb/whirlpool256-mgf.h>
 #include <catacomb/whirlpool256-hmac.h>
 
-#define PRPS(DO) \
-  DO(DES, des) \
-  DO(DESX, desx) \
-  DO(DES3, des3) \
-  DO(MARS, mars) \
-  DO(IDEA, idea) \
-  DO(SAFER, safer) \
-  DO(SAFERSK, safersk) \
-  DO(BLOWFISH, blowfish) \
-  DO(TWOFISH, twofish) \
-  DO(TEA, tea) \
-  DO(XTEA, xtea) \
-  DO(RC2, rc2) \
-  DO(RC5, rc5) \
-  DO(SKIPJACK, skipjack) \
-  DO(CAST128, cast128) \
-  DO(CAST256, cast256) \
-  DO(SQUARE, square) \
-  DO(RIJNDAEL, rijndael) \
-  DO(RIJNDAEL192, rijndael192) \
-  DO(RIJNDAEL256, rijndael256) \
-  DO(SERPENT, serpent) \
-  DO(NOEKEON, noekeon) \
+#define PRPS(_) \
+  _(DES, des) \
+  _(DESX, desx) \
+  _(DES3, des3) \
+  _(MARS, mars) \
+  _(IDEA, idea) \
+  _(SAFER, safer) \
+  _(SAFERSK, safersk) \
+  _(BLOWFISH, blowfish) \
+  _(TWOFISH, twofish) \
+  _(TEA, tea) \
+  _(XTEA, xtea) \
+  _(RC2, rc2) \
+  _(RC5, rc5) \
+  _(SKIPJACK, skipjack) \
+  _(CAST128, cast128) \
+  _(CAST256, cast256) \
+  _(SQUARE, square) \
+  _(RIJNDAEL, rijndael) \
+  _(RIJNDAEL192, rijndael192) \
+  _(RIJNDAEL256, rijndael256) \
+  _(SERPENT, serpent) \
+  _(NOEKEON, noekeon) \
   /* end */
 
-#define RNGS(DO) \
-  DO("des-ofb", des_ofbrand) \
-  DO("des-counter", des_counterrand) \
-  DO("desx-ofb", desx_ofbrand) \
-  DO("desx-counter", desx_counterrand) \
-  DO("des3-ofb", des3_ofbrand) \
-  DO("des3-counter", des3_counterrand) \
-  DO("mars-ofb", mars_ofbrand) \
-  DO("mars-counter", mars_counterrand) \
-  DO("idea-ofb", idea_ofbrand) \
-  DO("idea-counter", idea_counterrand) \
-  DO("safer-ofb", safer_ofbrand) \
-  DO("safer-counter", safer_counterrand) \
-  DO("safersk-ofb", safersk_ofbrand) \
-  DO("safersk-counter", safersk_counterrand) \
-  DO("blowfish-ofb", blowfish_ofbrand) \
-  DO("blowfish-counter", blowfish_counterrand) \
-  DO("twofish-ofb", twofish_ofbrand) \
-  DO("twofish-counter", twofish_counterrand) \
-  DO("tea-ofb", tea_ofbrand) \
-  DO("tea-counter", tea_counterrand) \
-  DO("xtea-ofb", xtea_ofbrand) \
-  DO("xtea-counter", xtea_counterrand) \
-  DO("rc2-ofb", rc2_ofbrand) \
-  DO("rc2-counter", rc2_counterrand) \
-  DO("rc5-ofb", rc5_ofbrand) \
-  DO("rc5-counter", rc5_counterrand) \
-  DO("skipjack-ofb", skipjack_ofbrand) \
-  DO("skipjack-counter", skipjack_counterrand) \
-  DO("cast128-ofb", cast128_ofbrand) \
-  DO("cast128-counter", cast128_counterrand) \
-  DO("cast256-ofb", cast256_ofbrand) \
-  DO("cast256-counter", cast256_counterrand) \
-  DO("square-ofb", square_ofbrand) \
-  DO("square-counter", square_counterrand) \
-  DO("rijndael-ofb", rijndael_ofbrand) \
-  DO("rijndael-counter", rijndael_counterrand) \
-  DO("rijndael192-ofb", rijndael192_ofbrand) \
-  DO("rijndael192-counter", rijndael192_counterrand) \
-  DO("rijndael256-ofb", rijndael256_ofbrand) \
-  DO("rijndael256-counter", rijndael256_counterrand) \
-  DO("serpent-ofb", serpent_ofbrand) \
-  DO("serpent-counter", serpent_counterrand) \
-  DO("noekeon-ofb", noekeon_ofbrand) \
-  DO("noekeon-counter", noekeon_counterrand) \
-  DO("md2-mgf", md2_mgfrand) \
-  DO("md4-mgf", md4_mgfrand) \
-  DO("md5-mgf", md5_mgfrand) \
-  DO("tiger-mgf", tiger_mgfrand) \
-  DO("has160-mgf", has160_mgfrand) \
-  DO("sha-mgf", sha_mgfrand) \
-  DO("sha224-mgf", sha224_mgfrand) \
-  DO("sha256-mgf", sha256_mgfrand) \
-  DO("sha384-mgf", sha384_mgfrand) \
-  DO("sha512-mgf", sha512_mgfrand) \
-  DO("rmd128-mgf", rmd128_mgfrand) \
-  DO("rmd160-mgf", rmd160_mgfrand) \
-  DO("rmd256-mgf", rmd256_mgfrand) \
-  DO("rmd320-mgf", rmd320_mgfrand) \
-  DO("whirlpool-mgf", whirlpool_mgfrand) \
-  DO("whirlpool256-mgf", whirlpool256_mgfrand) \
-  DO("rc4", rc4_rand) \
-  DO("seal", seal_randkludge) \
+#define RNGF_INT 1u
+
+#define RNGS(_) \
+  _("des-ofb", des_keysz, des_ofbrand, 0) \
+  _("des-counter", des_keysz, des_counterrand, 0) \
+  _("desx-ofb", desx_keysz, desx_ofbrand, 0) \
+  _("desx-counter", desx_keysz, desx_counterrand, 0) \
+  _("des3-ofb", des3_keysz, des3_ofbrand, 0) \
+  _("des3-counter", des3_keysz, des3_counterrand, 0) \
+  _("mars-ofb", mars_keysz, mars_ofbrand, 0) \
+  _("mars-counter", mars_keysz, mars_counterrand, 0) \
+  _("idea-ofb", idea_keysz, idea_ofbrand, 0) \
+  _("idea-counter", idea_keysz, idea_counterrand, 0) \
+  _("safer-ofb", safer_keysz, safer_ofbrand, 0) \
+  _("safer-counter", safer_keysz, safer_counterrand, 0) \
+  _("safersk-ofb", safersk_keysz, safersk_ofbrand, 0) \
+  _("safersk-counter", safersk_keysz, safersk_counterrand, 0) \
+  _("blowfish-ofb", blowfish_keysz, blowfish_ofbrand, 0) \
+  _("blowfish-counter", blowfish_keysz, blowfish_counterrand, 0) \
+  _("twofish-ofb", twofish_keysz, twofish_ofbrand, 0) \
+  _("twofish-counter", twofish_keysz, twofish_counterrand, 0) \
+  _("tea-ofb", tea_keysz, tea_ofbrand, 0) \
+  _("tea-counter", tea_keysz, tea_counterrand, 0) \
+  _("xtea-ofb", xtea_keysz, xtea_ofbrand, 0) \
+  _("xtea-counter", xtea_keysz, xtea_counterrand, 0) \
+  _("rc2-ofb", rc2_keysz, rc2_ofbrand, 0) \
+  _("rc2-counter", rc2_keysz, rc2_counterrand, 0) \
+  _("rc5-ofb", rc5_keysz, rc5_ofbrand, 0) \
+  _("rc5-counter", rc5_keysz, rc5_counterrand, 0) \
+  _("skipjack-ofb", skipjack_keysz, skipjack_ofbrand, 0) \
+  _("skipjack-counter", skipjack_keysz, skipjack_counterrand, 0) \
+  _("cast128-ofb", cast128_keysz, cast128_ofbrand, 0) \
+  _("cast128-counter", cast128_keysz, cast128_counterrand, 0) \
+  _("cast256-ofb", cast256_keysz, cast256_ofbrand, 0) \
+  _("cast256-counter", cast256_keysz, cast256_counterrand, 0) \
+  _("square-ofb", square_keysz, square_ofbrand, 0) \
+  _("square-counter", square_keysz, square_counterrand, 0) \
+  _("rijndael-ofb", rijndael_keysz, rijndael_ofbrand, 0) \
+  _("rijndael-counter", rijndael_keysz, rijndael_counterrand, 0) \
+  _("rijndael192-ofb", rijndael192_keysz, rijndael192_ofbrand, 0) \
+  _("rijndael192-counter", rijndael192_keysz, rijndael192_counterrand, 0) \
+  _("rijndael256-ofb", rijndael256_keysz, rijndael256_ofbrand, 0) \
+  _("rijndael256-counter", rijndael256_keysz, rijndael256_counterrand, 0) \
+  _("serpent-ofb", serpent_keysz, serpent_ofbrand, 0) \
+  _("serpent-counter", serpent_keysz, serpent_counterrand, 0) \
+  _("noekeon-ofb", noekeon_keysz, noekeon_ofbrand, 0) \
+  _("noekeon-counter", noekeon_keysz, noekeon_counterrand, 0) \
+  _("md2-mgf", md2_mgfkeysz, md2_mgfrand, 0) \
+  _("md4-mgf", md4_mgfkeysz, md4_mgfrand, 0) \
+  _("md5-mgf", md5_mgfkeysz, md5_mgfrand, 0) \
+  _("tiger-mgf", tiger_mgfkeysz, tiger_mgfrand, 0) \
+  _("has160-mgf", has160_mgfkeysz, has160_mgfrand, 0) \
+  _("sha-mgf", sha_mgfkeysz, sha_mgfrand, 0) \
+  _("sha224-mgf", sha224_mgfkeysz, sha224_mgfrand, 0) \
+  _("sha256-mgf", sha256_mgfkeysz, sha256_mgfrand, 0) \
+  _("sha384-mgf", sha384_mgfkeysz, sha384_mgfrand, 0) \
+  _("sha512-mgf", sha512_mgfkeysz, sha512_mgfrand, 0) \
+  _("rmd128-mgf", rmd128_mgfkeysz, rmd128_mgfrand, 0) \
+  _("rmd160-mgf", rmd160_mgfkeysz, rmd160_mgfrand, 0) \
+  _("rmd256-mgf", rmd256_mgfkeysz, rmd256_mgfrand, 0) \
+  _("rmd320-mgf", rmd320_mgfkeysz, rmd320_mgfrand, 0) \
+  _("whirlpool-mgf", whirlpool_mgfkeysz, whirlpool_mgfrand, 0) \
+  _("whirlpool256-mgf", whirlpool256_mgfkeysz, whirlpool256_mgfrand, 0) \
+  _("rc4", rc4_keysz, rc4_rand, 0) \
+  _("seal", seal_keysz, seal_rand, RNGF_INT) \
   /* end */
 
index cc209c6ffdd682383a0b4877d9c03dfd87460273..23487057b3db5433ee9aa12bb4cd7dfd17a21aae 100644 (file)
@@ -55,18 +55,25 @@ for i in hashes:
     print '#include <catacomb/%s-%s.h>' % (i, j)
 print
 
-print '#define PRPS(DO) \\'
+print '#define PRPS(_) \\'
 for i in prps:
-  print '  DO(%s, %s) \\' % (i.upper(), i)
+  print '  _(%s, %s) \\' % (i.upper(), i)
 print '  /* end */'
 print
 
-print '#define RNGS(DO) \\'
-for i in (cross(prps, ['ofb', 'counter']) +
-          cross(hashes, 'mgf')):
-  print '  DO("%(prim)s-%(mode)s", %(prim)s_%(mode)srand) \\' % \
-        {'prim': i[0], 'mode': i[1]}
-print '  DO("rc4", rc4_rand) \\'
-print '  DO("seal", seal_randkludge) \\'
+print '#define RNGF_INT 1u'
+print
+
+print '#define RNGS(_) \\'
+for i in (cross(prps, ['ofb', 'counter'])):
+  print ('  _("%(prim)s-%(mode)s", %(prim)s_keysz, ' +
+         '%(prim)s_%(mode)srand, 0) \\') % \
+         {'prim': i[0], 'mode': i[1]}
+for i in (cross(hashes, 'mgf')):
+  print ('  _("%(prim)s-%(mode)s", %(prim)s_%(mode)skeysz, ' +
+         '%(prim)s_%(mode)srand, 0) \\') % \
+         {'prim': i[0], 'mode': i[1]}
+print '  _("rc4", rc4_keysz, rc4_rand, 0) \\'
+print '  _("seal", seal_keysz, seal_rand, RNGF_INT) \\'
 print '  /* end */'
 print
index b9b1fd5f9cab1a4cdab2f6e91ceec74d1e22a21d..d71caa9b77e75b170ccc50e996039b66faa1af9b 100644 (file)
@@ -59,6 +59,7 @@
 #include <catacomb/dsarand.h>
 #include <catacomb/sslprf.h>
 #include <catacomb/tlsprf.h>
+#include <catacomb/blkc.h>
 
 #include <catacomb/gcipher.h>
 #include <catacomb/ghash.h>