chiark / gitweb /
algorithms.c (ShakeNN.done): Offer a (sensible) default hash size.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 14 Oct 2019 00:03:25 +0000 (01:03 +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 dd0bd0a65631e986c705b8088103bd7389d33d14..42dbe6fa50e3a2d988e28c13340c4c83f30d6a68 100644 (file)
@@ -3063,11 +3063,13 @@ end:
   return (0);
 }
 
-static PyObject *shakemeth_done(PyObject *me, PyObject *arg)
+static PyObject *shakemeth_done(PyObject *me, PyObject *arg, PyObject *kw)
 {
   PyObject *rc = 0;
-  size_t n;
-  if (!PyArg_ParseTuple(arg, "O&:done", convszt, &n)) goto end;
+  size_t n = 100 - SHAKE_H(me)->h.r/2;
+  static const char *const kwlist[] = { "hsz", 0 };
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:done", KWLIST, convszt, &n))
+    goto end;
   if (shake_check(me, 0)) goto end;
   rc = bytestring_pywrap(0, n);
   shake_done(SHAKE_H(me), BIN_PTR(rc), n);
@@ -3147,7 +3149,7 @@ static const PyMethodDef shake_pymethods[] = {
 #undef METHBUF_
   METH (hashstrz,      "S.hashstrz(STRING)")
   NAMETH(xof,          "S.xof()")
-  METH (done,          "S.done(LEN) -> H")
+  KWMETH(done,         "S.done([hsz = CAP]) -> H")
   METH (get,           "S.get(LEN) -> H")
   METH (mask,          "S.mask(M) -> C")
 #undef METHNAME
index bf637ef996eb6f2c74d5c7cdb835450696cbfcc1..3301228f7b0997ade905f86668dc4d344689e9dd 100644 (file)
@@ -797,14 +797,14 @@ class TestKeccak (HashBufferTestMixin):
     ## Check the menagerie of random hashing methods.
     def mkhash(_):
       x = xcls(func = func, perso = perso)
-      return x, lambda: x.done(100 - x.rate//2)
+      return x, x.done
     me.check_hashbuffer(mkhash)
 
     ## Check the state machine tracking.
     x = xcls(); me.assertEqual(x.state, "absorb")
     x.hash(m); me.assertEqual(x.state, "absorb")
     xx = x.copy()
-    h = xx.done(100 - x.rate//2)
+    h = xx.done(); me.assertEqual(len(h), 100 - x.rate//2)
     me.assertEqual(xx.state, "dead")
     me.assertRaises(ValueError, xx.done, 1)
     me.assertRaises(ValueError, xx.get, 1)