rand.c: Make nonce/IV arguments to cipher-based random generators optional.
[catacomb-python] / rand.c
diff --git a/rand.c b/rand.c
index 22a0b3c..ada2baa 100644 (file)
--- a/rand.c
+++ b/rand.c
@@ -642,7 +642,7 @@ static PyObject *gcirand_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
   static const char *const kwlist[] = { "key", "i", 0 };
   struct bin k;
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:new", KWLIST,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|O&:new", KWLIST,
                                   convbin, &k, convu32, &i))
     goto end;
   if (keysz(k.sz, info->keysz) != k.sz) VALERR("bad key length");
@@ -657,9 +657,11 @@ static PyObject *gcnrand_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
 {
   const gccrand_info *info = GCCRAND_INFO(ty);
   static const char *const kwlist[] = { "key", "nonce", 0 };
+  static const octet zn[24] = { 0 };
   struct bin k, n;
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:new", KWLIST,
+  n.p = zn; n.sz = info->noncesz; assert(info->noncesz <= sizeof(zn));
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|O&:new", KWLIST,
                                   convbin, &k, convbin, &n))
     goto end;
   if (keysz(k.sz, info->keysz) != k.sz) VALERR("bad key length");