algorithms.c: Add missing `copy' methods on hash and Keccak objects.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 7 Feb 2019 11:42:05 +0000 (11:42 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 21 Sep 2019 10:46:49 +0000 (11:46 +0100)
algorithms.c

index 8eced24..50ae068 100644 (file)
@@ -770,6 +770,12 @@ static PyObject *gchget_hashsz(PyObject *me, void *hunoz)
 static PyObject *gchget_bufsz(PyObject *me, void *hunoz)
   { return (PyInt_FromLong(GCHASH_CH(me)->bufsz)); }
 
+static PyObject *ghmeth_copy(PyObject *me, PyObject *arg)
+{
+  if (!PyArg_ParseTuple(arg, ":copy")) return (0);
+  return (ghash_pywrap((PyObject *)me->ob_type, GH_COPY(GHASH_H(me))));
+}
+
 static PyObject *ghmeth_hash(PyObject *me, PyObject *arg)
 {
   char *p;
@@ -834,6 +840,7 @@ static PyGetSetDef gchash_pygetset[] = {
 
 static PyMethodDef ghash_pymethods[] = {
 #define METHNAME(name) ghmeth_##name
+  METH (copy,                  "H.copy() -> HH")
   METH (hash,                  "H.hash(M)")
 #define METHU_(n, W, w) METH(hashu##w, "H.hashu" #w "(WORD)")
   DOUINTCONV(METHU_)
@@ -1598,6 +1605,16 @@ end:
   return ((PyObject *)rc);
 }
 
+static PyObject *kxvikmeth_copy(PyObject *me, PyObject *arg)
+{
+  kxvik_pyobj *k = (kxvik_pyobj *)me, *rc = 0;
+  if (!PyArg_ParseTuple(arg, ":copy")) goto end;
+  rc = (kxvik_pyobj *)k->ob_type->tp_alloc(k->ob_type, 0);
+  rc->s = k->s; rc->n = k->n;
+end:
+  return ((PyObject *)rc);
+}
+
 static PyObject *kxvikmeth_mix(PyObject *me, PyObject *arg)
 {
   kxvik_pyobj *k = (kxvik_pyobj *)me;
@@ -1676,6 +1693,7 @@ static PyGetSetDef kxvik_pygetset[] = {
 
 static PyMethodDef kxvik_pymethods[] = {
 #define METHNAME(func) kxvikmeth_##func
+  METH (copy,                  "KECCAK.copy() -> KECCAK'")
   METH (mix,                   "KECCAK.mix(DATA)")
   METH (extract,               "KECCAK.extract(NOCTETS)")
   METH (step,                  "KECCAK.step()")