rand.c, algorithms.py: Change how kinds of RNGs are distinguished.
[catacomb-python] / rand.c
diff --git a/rand.c b/rand.c
index f163efa..5402737 100644 (file)
--- a/rand.c
+++ b/rand.c
@@ -591,9 +591,15 @@ typedef struct gccrand_info {
   gcrand_func *func;
 } gccrand_info;
 
-#define RNGF_INT 1u
-#define RNGF_NONCE 2u
-#define RNGF_LATIN 4u
+#define RNGF_MASK 255u
+
+enum {
+  RNG_PLAIN = 0,
+  RNG_SEAL,
+  RNG_LATIN,
+  RNG_SHAKE,
+  RNG_KMAC
+};
 
 typedef struct gccrand_pyobj {
   PyHeapTypeObject ty;
@@ -670,17 +676,21 @@ static PyObject *gccrand_pywrap(const gccrand_info *info)
   gccrand_pyobj *g = newtype(gccrand_pytype, 0, info->name);
   g->info = info;
   g->ty.ht_type.tp_basicsize = sizeof(grand_pyobj);
-  g->ty.ht_type.tp_base =
-    (info->f & RNGF_LATIN) ? gclatinrand_pytype : gcrand_pytype;
+  switch (info->f&RNGF_MASK) {
+    case RNG_LATIN: g->ty.ht_type.tp_base = gclatinrand_pytype; break;
+    default: g->ty.ht_type.tp_base = gcrand_pytype; break;
+  }
   Py_INCREF(g->ty.ht_type.tp_base);
   g->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT |
                            Py_TPFLAGS_BASETYPE |
                            Py_TPFLAGS_HEAPTYPE);
   g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
   g->ty.ht_type.tp_free = 0;
-  if (info->f & RNGF_INT) g->ty.ht_type.tp_new = gcirand_pynew;
-  else if (info->f & RNGF_NONCE) g->ty.ht_type.tp_new = gcnrand_pynew;
-  else g->ty.ht_type.tp_new = gcrand_pynew;
+  switch (info->f&RNGF_MASK) {
+    case RNG_LATIN: g->ty.ht_type.tp_new = gcnrand_pynew; break;
+    case RNG_SEAL: g->ty.ht_type.tp_new = gcirand_pynew; break;
+    default: g->ty.ht_type.tp_new = gcrand_pynew; break;
+  }
   typeready(&g->ty.ht_type);
   return ((PyObject *)g);
 }