From c719150915e19e1be2a5a315e5e565e1a541921f Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 14 Oct 2019 01:01:05 +0100 Subject: [PATCH] algorithms.c: Add a Keccak `set' method now there's upstream support. Bump dependency on Catacomb. --- algorithms.c | 22 ++++++++++++++++++++++ debian/control | 2 +- setup.py | 2 +- t/t-algorithms.py | 7 +++++-- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/algorithms.c b/algorithms.c index 48bd480..be07fb7 100644 --- a/algorithms.c +++ b/algorithms.c @@ -2912,6 +2912,27 @@ end: return (0); } +static PyObject *kxvikmeth_set(PyObject *me, PyObject *arg) +{ + kxvik_pyobj *k = (kxvik_pyobj *)me; + kludge64 t[25]; + const octet *q; + unsigned i; + struct bin in; + size_t n; + + if (!PyArg_ParseTuple(arg, "O&:set", convbin, &in)) goto end; + if (in.sz > 200) VALERR("out of range"); + q = in.p; n = in.sz; + i = 0; + while (n >= 8) { LOAD64_L_(t[i], q); i++; q += 8; n -= 8; } + if (n) VALERR("not 64-bit aligned"); + keccak1600_set(&k->s, t, i); + RETURN_ME; +end: + return (0); +} + static PyObject *kxvikmeth_extract(PyObject *me, PyObject *arg) { kxvik_pyobj *k = (kxvik_pyobj *)me; @@ -2951,6 +2972,7 @@ static const PyMethodDef kxvik_pymethods[] = { #define METHNAME(func) kxvikmeth_##func NAMETH(copy, "KECCAK.copy() -> KECCAK'") METH (mix, "KECCAK.mix(DATA)") + METH (set, "KECCAK.set(DATA)") METH (extract, "KECCAK.extract(NOCTETS)") NAMETH(step, "KECCAK.step()") #undef METHNAME diff --git a/debian/control b/debian/control index 2957d2e..66a2caa 100644 --- a/debian/control +++ b/debian/control @@ -6,7 +6,7 @@ XS-Python3-Version: >= 3.0 Maintainer: Mark Wooding Build-Depends: debhelper (>= 10), dh-python, pkg-config, python (>= 2.6.6-3~), python-all-dev, python3-all-dev, - mlib-dev (>= 2.4.99~), catacomb-dev (>= 2.5.0) + mlib-dev (>= 2.4.99~), catacomb-dev (>= 2.5.99~) Standards-Version: 3.8.0 Package: python-catacomb diff --git a/setup.py b/setup.py index 87a321c..045ee3e 100755 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import distutils.core as DC import mdwsetup as MS -MS.pkg_config('catacomb', '2.5.0') +MS.pkg_config('catacomb', '2.5.99~') MS.pkg_config('mLib', '2.4.99~') cat = DC.Extension('catacomb._base', diff --git a/t/t-algorithms.py b/t/t-algorithms.py index 593e6cf..455e947 100644 --- a/t/t-algorithms.py +++ b/t/t-algorithms.py @@ -746,11 +746,11 @@ class TestKeccak (HashBufferTestMixin): st1.mix(m0).step() me.assertNotEqual(st0.extract(32), st1.extract(32)) - ## Check state copying. + ## Check state copying and `mix' vs `set'. st1 = st0.copy() mask = st1.extract(len(m1)) st0.mix(m1) - st1.mix(m1) + st1.set(m1 ^ mask) me.assertEqual(st0.extract(32), st1.extract(32)) ## Check error conditions. @@ -758,6 +758,9 @@ class TestKeccak (HashBufferTestMixin): me.assertRaises(ValueError, st0.extract, 201) st0.mix(T.span(200)) me.assertRaises(ValueError, st0.mix, T.span(201)) + st0.set(T.span(200)) + me.assertRaises(ValueError, st0.set, T.span(201)) + me.assertRaises(ValueError, st0.set, T.span(199)) def check_shake(me, xcls, c, done_matches_xof = True): """ -- 2.11.0