algorithms.c (ShakeNN constructor): Support `None' for func/perso args.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 14 Oct 2019 00:01:33 +0000 (01:01 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 11 Apr 2020 11:49:31 +0000 (12:49 +0100)
algorithms.c
t/t-algorithms.py

index 4e22a54..dd0bd0a 100644 (file)
@@ -2976,12 +2976,14 @@ static PyObject *shake_dopynew(void (*initfn)(shake_ctx *,
                               PyObject *arg, PyObject *kw)
 {
   shake_pyobj *rc = 0;
+  PyObject *pobj = Py_None, *fobj = Py_None;
   struct bin p = { 0, 0 }, f = { 0, 0 };
   static const char *const kwlist[] = { "perso", "func", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&O&:new", KWLIST,
-                                  convbin, &p, convbin, &f))
-    goto end;
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "|OO:new", KWLIST, &pobj, &fobj))
+      goto end;
+  if (pobj != Py_None && !convbin(pobj, &p)) goto end;
+  if (fobj != Py_None && !convbin(fobj, &f)) goto end;
   rc = (shake_pyobj *)ty->tp_alloc(ty, 0);
   initfn(&rc->h, f.p, f.sz, p.p, p.sz);
   rc->st = 0;
index d7b97cb..bf637ef 100644 (file)
@@ -820,7 +820,7 @@ class TestKeccak (HashBufferTestMixin):
 
   def check_kmac(me, mcls, c):
     k = T.span(32)
-    me.check_shake(lambda func = None, perso = T.bin(""):
+    me.check_shake(lambda func = None, perso = None:
                      mcls(k, perso = perso),
                    c, done_matches_xof = False)