+ /* @tp_doc@ */
+"Authenticated encryption AAD hash.",
+
+ 0, /* @tp_traverse@ */
+ 0, /* @tp_clear@ */
+ 0, /* @tp_richcompare@ */
+ 0, /* @tp_weaklistoffset@ */
+ 0, /* @tp_iter@ */
+ 0, /* @tp_iternext@ */
+ gaeadaad_pymethods, /* @tp_methods@ */
+ 0, /* @tp_members@ */
+ gaeadaad_pygetset, /* @tp_getset@ */
+ 0, /* @tp_base@ */
+ 0, /* @tp_dict@ */
+ 0, /* @tp_descr_get@ */
+ 0, /* @tp_descr_set@ */
+ 0, /* @tp_dictoffset@ */
+ 0, /* @tp_init@ */
+ PyType_GenericAlloc, /* @tp_alloc@ */
+ abstract_pynew, /* @tp_new@ */
+ 0, /* @tp_free@ */
+ 0 /* @tp_is_gc@ */
+};
+
+static PyTypeObject gcaeadenc_pytype_skel = {
+ PyObject_HEAD_INIT(0) 0, /* Header */
+ "GAEEncClass", /* @tp_name@ */
+ sizeof(gcaeadenc_pyobj), /* @tp_basicsize@ */
+ 0, /* @tp_itemsize@ */
+
+ 0, /* @tp_dealloc@ */
+ 0, /* @tp_print@ */
+ 0, /* @tp_getattr@ */
+ 0, /* @tp_setattr@ */
+ 0, /* @tp_compare@ */
+ 0, /* @tp_repr@ */
+ 0, /* @tp_as_number@ */
+ 0, /* @tp_as_sequence@ */
+ 0, /* @tp_as_mapping@ */
+ 0, /* @tp_hash@ */
+ 0, /* @tp_call@ */
+ 0, /* @tp_str@ */
+ 0, /* @tp_getattro@ */
+ 0, /* @tp_setattro@ */
+ 0, /* @tp_as_buffer@ */
+ Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
+ Py_TPFLAGS_BASETYPE,
+
+ /* @tp_doc@ */
+"Authenticated encryption operation metaclass.",
+
+ 0, /* @tp_traverse@ */
+ 0, /* @tp_clear@ */
+ 0, /* @tp_richcompare@ */
+ 0, /* @tp_weaklistoffset@ */
+ 0, /* @tp_iter@ */
+ 0, /* @tp_iternext@ */
+ 0, /* @tp_methods@ */
+ 0, /* @tp_members@ */
+ 0, /* @tp_getset@ */
+ 0, /* @tp_base@ */
+ 0, /* @tp_dict@ */
+ 0, /* @tp_descr_get@ */
+ 0, /* @tp_descr_set@ */
+ 0, /* @tp_dictoffset@ */
+ 0, /* @tp_init@ */
+ PyType_GenericAlloc, /* @tp_alloc@ */
+ abstract_pynew, /* @tp_new@ */
+ 0, /* @tp_free@ */
+ 0 /* @tp_is_gc@ */
+};
+
+static PyTypeObject gaeadenc_pytype_skel = {
+ PyObject_HEAD_INIT(0) 0, /* Header */
+ "GAEEnc", /* @tp_name@ */
+ sizeof(gaeadenc_pyobj), /* @tp_basicsize@ */
+ 0, /* @tp_itemsize@ */
+
+ gaeadenc_pydealloc, /* @tp_dealloc@ */
+ 0, /* @tp_print@ */
+ 0, /* @tp_getattr@ */
+ 0, /* @tp_setattr@ */
+ 0, /* @tp_compare@ */
+ 0, /* @tp_repr@ */
+ 0, /* @tp_as_number@ */
+ 0, /* @tp_as_sequence@ */
+ 0, /* @tp_as_mapping@ */
+ 0, /* @tp_hash@ */
+ 0, /* @tp_call@ */
+ 0, /* @tp_str@ */
+ 0, /* @tp_getattro@ */
+ 0, /* @tp_setattro@ */
+ 0, /* @tp_as_buffer@ */
+ Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
+ Py_TPFLAGS_BASETYPE,
+
+ /* @tp_doc@ */
+"Authenticated encryption operation.",
+
+ 0, /* @tp_traverse@ */
+ 0, /* @tp_clear@ */
+ 0, /* @tp_richcompare@ */
+ 0, /* @tp_weaklistoffset@ */
+ 0, /* @tp_iter@ */
+ 0, /* @tp_iternext@ */
+ gaeadenc_pymethods, /* @tp_methods@ */
+ 0, /* @tp_members@ */
+ gaeadenc_pygetset, /* @tp_getset@ */
+ 0, /* @tp_base@ */
+ 0, /* @tp_dict@ */
+ 0, /* @tp_descr_get@ */
+ 0, /* @tp_descr_set@ */
+ 0, /* @tp_dictoffset@ */
+ 0, /* @tp_init@ */
+ PyType_GenericAlloc, /* @tp_alloc@ */
+ abstract_pynew, /* @tp_new@ */
+ 0, /* @tp_free@ */
+ 0 /* @tp_is_gc@ */
+};
+
+static PyTypeObject gcaeaddec_pytype_skel = {
+ PyObject_HEAD_INIT(0) 0, /* Header */
+ "GAEDecClass", /* @tp_name@ */
+ sizeof(gcaeaddec_pyobj), /* @tp_basicsize@ */
+ 0, /* @tp_itemsize@ */
+
+ 0, /* @tp_dealloc@ */
+ 0, /* @tp_print@ */
+ 0, /* @tp_getattr@ */
+ 0, /* @tp_setattr@ */
+ 0, /* @tp_compare@ */
+ 0, /* @tp_repr@ */
+ 0, /* @tp_as_number@ */
+ 0, /* @tp_as_sequence@ */
+ 0, /* @tp_as_mapping@ */
+ 0, /* @tp_hash@ */
+ 0, /* @tp_call@ */
+ 0, /* @tp_str@ */
+ 0, /* @tp_getattro@ */
+ 0, /* @tp_setattro@ */
+ 0, /* @tp_as_buffer@ */
+ Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
+ Py_TPFLAGS_BASETYPE,
+
+ /* @tp_doc@ */
+"Authenticated decryption operation metaclass.",
+
+ 0, /* @tp_traverse@ */
+ 0, /* @tp_clear@ */
+ 0, /* @tp_richcompare@ */
+ 0, /* @tp_weaklistoffset@ */
+ 0, /* @tp_iter@ */
+ 0, /* @tp_iternext@ */
+ 0, /* @tp_methods@ */
+ 0, /* @tp_members@ */
+ 0, /* @tp_getset@ */
+ 0, /* @tp_base@ */
+ 0, /* @tp_dict@ */
+ 0, /* @tp_descr_get@ */
+ 0, /* @tp_descr_set@ */
+ 0, /* @tp_dictoffset@ */
+ 0, /* @tp_init@ */
+ PyType_GenericAlloc, /* @tp_alloc@ */
+ abstract_pynew, /* @tp_new@ */
+ 0, /* @tp_free@ */
+ 0 /* @tp_is_gc@ */
+};
+
+static PyTypeObject gaeaddec_pytype_skel = {
+ PyObject_HEAD_INIT(0) 0, /* Header */
+ "GAEDec", /* @tp_name@ */
+ sizeof(gaeaddec_pyobj), /* @tp_basicsize@ */
+ 0, /* @tp_itemsize@ */
+
+ gaeaddec_pydealloc, /* @tp_dealloc@ */
+ 0, /* @tp_print@ */
+ 0, /* @tp_getattr@ */
+ 0, /* @tp_setattr@ */
+ 0, /* @tp_compare@ */
+ 0, /* @tp_repr@ */
+ 0, /* @tp_as_number@ */
+ 0, /* @tp_as_sequence@ */
+ 0, /* @tp_as_mapping@ */
+ 0, /* @tp_hash@ */
+ 0, /* @tp_call@ */
+ 0, /* @tp_str@ */
+ 0, /* @tp_getattro@ */
+ 0, /* @tp_setattro@ */
+ 0, /* @tp_as_buffer@ */
+ Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
+ Py_TPFLAGS_BASETYPE,
+
+ /* @tp_doc@ */
+"Authenticated decryption operation.",
+
+ 0, /* @tp_traverse@ */
+ 0, /* @tp_clear@ */
+ 0, /* @tp_richcompare@ */
+ 0, /* @tp_weaklistoffset@ */
+ 0, /* @tp_iter@ */
+ 0, /* @tp_iternext@ */
+ gaeaddec_pymethods, /* @tp_methods@ */
+ 0, /* @tp_members@ */
+ gaeaddec_pygetset, /* @tp_getset@ */
+ 0, /* @tp_base@ */
+ 0, /* @tp_dict@ */
+ 0, /* @tp_descr_get@ */
+ 0, /* @tp_descr_set@ */
+ 0, /* @tp_dictoffset@ */
+ 0, /* @tp_init@ */
+ PyType_GenericAlloc, /* @tp_alloc@ */
+ abstract_pynew, /* @tp_new@ */
+ 0, /* @tp_free@ */
+ 0 /* @tp_is_gc@ */
+};
+
+/*----- Hash functions ----------------------------------------------------*/
+
+PyTypeObject *gchash_pytype, *ghash_pytype;
+
+CONVFUNC(gchash, gchash *, GCHASH_CH)
+CONVFUNC(ghash, ghash *, GHASH_H)
+
+static PyObject *ghash_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
+{
+ static const char *const kwlist[] = { 0 };
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, ":new", KWLIST))
+ goto end;
+ return (ghash_pywrap((PyObject *)ty, GH_INIT(GCHASH_CH(ty))));
+end:
+ return (0);
+}
+
+PyObject *gchash_pywrap(gchash *ch)
+{
+ gchash_pyobj *g = newtype(gchash_pytype, 0, ch->name);
+ g->ch = ch;
+ g->ty.ht_type.tp_basicsize = sizeof(ghash_pyobj);
+ g->ty.ht_type.tp_base = ghash_pytype;
+ Py_INCREF(ghash_pytype);
+ g->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT |
+ Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_HEAPTYPE);
+ g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
+ g->ty.ht_type.tp_free = 0;
+ g->ty.ht_type.tp_new = ghash_pynew;
+ typeready(&g->ty.ht_type);
+ return ((PyObject *)g);
+}
+
+PyObject *ghash_pywrap(PyObject *cobj, ghash *h)
+{
+ ghash_pyobj *g;
+ if (!cobj) cobj = gchash_pywrap((/*unconst*/ gchash *)GH_CLASS(h));
+ else Py_INCREF(cobj);
+ g = PyObject_NEW(ghash_pyobj, (PyTypeObject *)cobj);
+ g->h = h;
+ return ((PyObject *)g);
+}
+
+static void ghash_pydealloc(PyObject *me)
+{
+ GH_DESTROY(GHASH_H(me));
+ Py_DECREF(me->ob_type);
+ FREEOBJ(me);
+}
+
+static PyObject *gchget_name(PyObject *me, void *hunoz)
+ { return (PyString_FromString(GCHASH_CH(me)->name)); }
+
+static PyObject *gchget_hashsz(PyObject *me, void *hunoz)
+ { return (PyInt_FromLong(GCHASH_CH(me)->hashsz)); }
+
+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;
+ Py_ssize_t sz;
+ if (!PyArg_ParseTuple(arg, "s#:hash", &p, &sz)) return (0);
+ GH_HASH(GHASH_H(me), p, sz);
+ RETURN_ME;
+}
+
+#define GHMETH_HASHU_(n, W, w) \
+ static PyObject *ghmeth_hashu##w(PyObject *me, PyObject *arg) \
+ { \
+ uint##n x; \
+ if (!PyArg_ParseTuple(arg, "O&:hashu" #w, convu##n, &x)) return (0); \
+ GH_HASHU##W(GHASH_H(me), x); \
+ RETURN_ME; \
+ }
+DOUINTCONV(GHMETH_HASHU_)
+
+#define GHMETH_HASHBUF_(n, W, w) \
+ static PyObject *ghmeth_hashbuf##w(PyObject *me, PyObject *arg) \
+ { \
+ char *p; \
+ Py_ssize_t sz; \
+ if (!PyArg_ParseTuple(arg, "s#:hashbuf" #w, &p, &sz)) goto end; \
+ if (sz > MASK##n) TYERR("string too long"); \
+ GH_HASHBUF##W(GHASH_H(me), p, sz); \
+ RETURN_ME; \
+ end: \
+ return (0); \
+ }
+DOUINTCONV(GHMETH_HASHBUF_)
+
+static PyObject *ghmeth_hashstrz(PyObject *me, PyObject *arg)
+{
+ char *p;
+ if (!PyArg_ParseTuple(arg, "s:hashstrz", &p)) return (0);
+ GH_HASHSTRZ(GHASH_H(me), p);
+ RETURN_ME;
+}
+
+static PyObject *ghmeth_done(PyObject *me, PyObject *arg)
+{
+ ghash *g;
+ PyObject *rc;
+ if (!PyArg_ParseTuple(arg, ":done")) return (0);
+ g = GH_COPY(GHASH_H(me));
+ rc = bytestring_pywrap(0, g->ops->c->hashsz);
+ GH_DONE(g, PyString_AS_STRING(rc));
+ GH_DESTROY(g);
+ return (rc);
+}
+
+static PyGetSetDef gchash_pygetset[] = {
+#define GETSETNAME(op, name) gch##op##_##name
+ GET (bufsz, "CH.bufsz -> hash buffer size, or zero")
+ GET (hashsz, "CH.hashsz -> hash output size")
+ GET (name, "CH.name -> name of this kind of hash")
+#undef GETSETNAME
+ { 0 }
+};
+
+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_)
+#undef METHU_
+#define METHBUF_(n, W, w) METH(hashbuf##w, "H.hashbuf" #w "(BYTES)")
+ DOUINTCONV(METHBUF_)
+#undef METHBUF_
+ METH (hashstrz, "H.hashstrz(STRING)")
+ METH (done, "H.done() -> HASH")
+#undef METHNAME
+ { 0 }
+};
+
+static PyTypeObject gchash_pytype_skel = {
+ PyObject_HEAD_INIT(0) 0, /* Header */
+ "GCHash", /* @tp_name@ */
+ sizeof(gchash_pyobj), /* @tp_basicsize@ */
+ 0, /* @tp_itemsize@ */
+
+ 0, /* @tp_dealloc@ */
+ 0, /* @tp_print@ */
+ 0, /* @tp_getattr@ */
+ 0, /* @tp_setattr@ */
+ 0, /* @tp_compare@ */
+ 0, /* @tp_repr@ */
+ 0, /* @tp_as_number@ */
+ 0, /* @tp_as_sequence@ */
+ 0, /* @tp_as_mapping@ */
+ 0, /* @tp_hash@ */
+ 0, /* @tp_call@ */
+ 0, /* @tp_str@ */
+ 0, /* @tp_getattro@ */
+ 0, /* @tp_setattro@ */
+ 0, /* @tp_as_buffer@ */
+ Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
+ Py_TPFLAGS_BASETYPE,
+
+ /* @tp_doc@ */
+"Hash function metaclass.",
+
+ 0, /* @tp_traverse@ */
+ 0, /* @tp_clear@ */
+ 0, /* @tp_richcompare@ */
+ 0, /* @tp_weaklistoffset@ */
+ 0, /* @tp_iter@ */
+ 0, /* @tp_iternext@ */
+ 0, /* @tp_methods@ */
+ 0, /* @tp_members@ */
+ gchash_pygetset, /* @tp_getset@ */
+ 0, /* @tp_base@ */
+ 0, /* @tp_dict@ */
+ 0, /* @tp_descr_get@ */
+ 0, /* @tp_descr_set@ */
+ 0, /* @tp_dictoffset@ */
+ 0, /* @tp_init@ */
+ PyType_GenericAlloc, /* @tp_alloc@ */
+ abstract_pynew, /* @tp_new@ */
+ 0, /* @tp_free@ */
+ 0 /* @tp_is_gc@ */
+};
+
+static PyTypeObject ghash_pytype_skel = {
+ PyObject_HEAD_INIT(0) 0, /* Header */
+ "GHash", /* @tp_name@ */
+ sizeof(ghash_pyobj), /* @tp_basicsize@ */
+ 0, /* @tp_itemsize@ */
+
+ ghash_pydealloc, /* @tp_dealloc@ */
+ 0, /* @tp_print@ */
+ 0, /* @tp_getattr@ */
+ 0, /* @tp_setattr@ */
+ 0, /* @tp_compare@ */
+ 0, /* @tp_repr@ */
+ 0, /* @tp_as_number@ */
+ 0, /* @tp_as_sequence@ */
+ 0, /* @tp_as_mapping@ */
+ 0, /* @tp_hash@ */
+ 0, /* @tp_call@ */
+ 0, /* @tp_str@ */
+ 0, /* @tp_getattro@ */
+ 0, /* @tp_setattro@ */
+ 0, /* @tp_as_buffer@ */
+ Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
+ Py_TPFLAGS_BASETYPE,
+
+ /* @tp_doc@ */
+"Hash function, abstract base class.",
+
+ 0, /* @tp_traverse@ */
+ 0, /* @tp_clear@ */
+ 0, /* @tp_richcompare@ */
+ 0, /* @tp_weaklistoffset@ */
+ 0, /* @tp_iter@ */
+ 0, /* @tp_iternext@ */
+ ghash_pymethods, /* @tp_methods@ */
+ 0, /* @tp_members@ */
+ 0, /* @tp_getset@ */
+ 0, /* @tp_base@ */
+ 0, /* @tp_dict@ */
+ 0, /* @tp_descr_get@ */
+ 0, /* @tp_descr_set@ */
+ 0, /* @tp_dictoffset@ */
+ 0, /* @tp_init@ */
+ PyType_GenericAlloc, /* @tp_alloc@ */
+ abstract_pynew, /* @tp_new@ */
+ 0, /* @tp_free@ */
+ 0 /* @tp_is_gc@ */
+};
+
+/*----- Message authentication --------------------------------------------*/
+
+PyTypeObject *gcmac_pytype, *gmac_pytype, *gmhash_pytype;
+
+CONVFUNC(gcmac, gcmac *, GCMAC_CM)
+CONVFUNC(gmac, gmac *, GMAC_M)
+CONVFUNC(gmhash, ghash *, GHASH_H)
+
+static PyObject *gmac_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
+{
+ static const char *const kwlist[] = { "k", 0 };
+ char *k;
+ Py_ssize_t sz;
+
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", KWLIST, &k, &sz))
+ goto end;
+ if (keysz(sz, GCMAC_CM(ty)->keysz) != sz) VALERR("bad key length");
+ return (gmac_pywrap((PyObject *)ty,
+ GM_KEY(GCMAC_CM(ty), k, sz)));
+end:
+ return (0);
+}
+
+static PyObject *gmhash_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
+{
+ static const char *const kwlist[] = { 0 };
+ ghash_pyobj *g;
+
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, ":new", KWLIST)) return (0);
+ g = PyObject_NEW(ghash_pyobj, ty);
+ g->h = GM_INIT(GMAC_M(ty));
+ Py_INCREF(ty);
+ return ((PyObject *)g);
+}
+
+PyObject *gcmac_pywrap(gcmac *cm)
+{
+ gcmac_pyobj *g = newtype(gcmac_pytype, 0, cm->name);
+ g->cm = cm;
+ g->ty.ht_type.tp_basicsize = sizeof(gmac_pyobj);
+ g->ty.ht_type.tp_base = gmac_pytype;
+ Py_INCREF(gmac_pytype);
+ g->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT |
+ Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_HEAPTYPE);
+ g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
+ g->ty.ht_type.tp_free = 0;
+ g->ty.ht_type.tp_new = gmac_pynew;
+ typeready(&g->ty.ht_type);
+ return ((PyObject *)g);
+}
+
+PyObject *gmac_pywrap(PyObject *cobj, gmac *m)
+{
+ gmac_pyobj *g;
+ if (!cobj) cobj = gcmac_pywrap((/*unconst*/ gcmac *)GM_CLASS(m));
+ else Py_INCREF(cobj);
+ g = newtype((PyTypeObject *)cobj, 0, 0);
+ g->ty.ht_type.tp_basicsize = sizeof(ghash_pyobj);
+ g->ty.ht_name = PyString_FromFormat("%s(keyed)", m->ops->c->name);
+ g->ty.ht_type.tp_name = PyString_AS_STRING(g->ty.ht_name);
+ g->ty.ht_type.tp_base = gmhash_pytype;
+ Py_INCREF(gmac_pytype);
+ g->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT |
+ Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_HEAPTYPE);
+ g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
+ g->ty.ht_type.tp_free = 0;
+ g->ty.ht_type.tp_new = gmhash_pynew;
+ typeready(&g->ty.ht_type);
+ g->m = m;
+ return ((PyObject *)g);
+}
+
+static void gmac_pydealloc(PyObject *me)
+{
+ GM_DESTROY(GMAC_M(me));
+ Py_DECREF(me->ob_type);
+ PyType_Type.tp_dealloc(me);
+}
+
+static PyObject *gcmget_name(PyObject *me, void *hunoz)
+ { return (PyString_FromString(GCMAC_CM(me)->name)); }
+
+static PyObject *gcmget_keysz(PyObject *me, void *hunoz)
+ { return (keysz_pywrap(GCMAC_CM(me)->keysz)); }
+
+static PyObject *gcmget_tagsz(PyObject *me, void *hunoz)
+ { return (PyInt_FromLong(GCMAC_CM(me)->hashsz)); }
+
+static PyGetSetDef gcmac_pygetset[] = {
+#define GETSETNAME(op, name) gcm##op##_##name
+ GET (keysz, "CM.keysz -> acceptable key sizes")
+ GET (tagsz, "CM.tagsz -> MAC output size")
+ GET (name, "CM.name -> name of this kind of MAC")
+#undef GETSETNAME
+ { 0 }
+};
+
+static PyTypeObject gcmac_pytype_skel = {
+ PyObject_HEAD_INIT(0) 0, /* Header */
+ "GCMAC", /* @tp_name@ */
+ sizeof(gchash_pyobj), /* @tp_basicsize@ */
+ 0, /* @tp_itemsize@ */
+
+ 0, /* @tp_dealloc@ */
+ 0, /* @tp_print@ */
+ 0, /* @tp_getattr@ */
+ 0, /* @tp_setattr@ */
+ 0, /* @tp_compare@ */
+ 0, /* @tp_repr@ */
+ 0, /* @tp_as_number@ */
+ 0, /* @tp_as_sequence@ */
+ 0, /* @tp_as_mapping@ */
+ 0, /* @tp_hash@ */
+ 0, /* @tp_call@ */
+ 0, /* @tp_str@ */
+ 0, /* @tp_getattro@ */
+ 0, /* @tp_setattro@ */
+ 0, /* @tp_as_buffer@ */
+ Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
+ Py_TPFLAGS_BASETYPE,
+
+ /* @tp_doc@ */
+"Message authentication code metametaclass.",
+
+ 0, /* @tp_traverse@ */
+ 0, /* @tp_clear@ */
+ 0, /* @tp_richcompare@ */
+ 0, /* @tp_weaklistoffset@ */
+ 0, /* @tp_iter@ */
+ 0, /* @tp_iternext@ */
+ 0, /* @tp_methods@ */
+ 0, /* @tp_members@ */
+ gcmac_pygetset, /* @tp_getset@ */
+ 0, /* @tp_base@ */
+ 0, /* @tp_dict@ */
+ 0, /* @tp_descr_get@ */
+ 0, /* @tp_descr_set@ */
+ 0, /* @tp_dictoffset@ */
+ 0, /* @tp_init@ */
+ PyType_GenericAlloc, /* @tp_alloc@ */
+ abstract_pynew, /* @tp_new@ */
+ 0, /* @tp_free@ */
+ 0 /* @tp_is_gc@ */
+};
+
+static PyTypeObject gmac_pytype_skel = {
+ PyObject_HEAD_INIT(0) 0, /* Header */
+ "GMAC", /* @tp_name@ */
+ sizeof(gmac_pyobj), /* @tp_basicsize@ */
+ 0, /* @tp_itemsize@ */
+
+ gmac_pydealloc, /* @tp_dealloc@ */
+ 0, /* @tp_print@ */
+ 0, /* @tp_getattr@ */
+ 0, /* @tp_setattr@ */
+ 0, /* @tp_compare@ */
+ 0, /* @tp_repr@ */
+ 0, /* @tp_as_number@ */
+ 0, /* @tp_as_sequence@ */
+ 0, /* @tp_as_mapping@ */
+ 0, /* @tp_hash@ */
+ 0, /* @tp_call@ */
+ 0, /* @tp_str@ */
+ 0, /* @tp_getattro@ */
+ 0, /* @tp_setattro@ */
+ 0, /* @tp_as_buffer@ */
+ Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
+ Py_TPFLAGS_BASETYPE,
+
+ /* @tp_doc@ */
+"Message authentication code metaclass, abstract base class.",
+
+ 0, /* @tp_traverse@ */
+ 0, /* @tp_clear@ */
+ 0, /* @tp_richcompare@ */
+ 0, /* @tp_weaklistoffset@ */
+ 0, /* @tp_iter@ */
+ 0, /* @tp_iternext@ */
+ 0, /* @tp_methods@ */
+ 0, /* @tp_members@ */
+ 0, /* @tp_getset@ */
+ 0, /* @tp_base@ */
+ 0, /* @tp_dict@ */
+ 0, /* @tp_descr_get@ */
+ 0, /* @tp_descr_set@ */
+ 0, /* @tp_dictoffset@ */
+ 0, /* @tp_init@ */
+ PyType_GenericAlloc, /* @tp_alloc@ */
+ abstract_pynew, /* @tp_new@ */
+ 0, /* @tp_free@ */
+ 0 /* @tp_is_gc@ */
+};
+
+static PyTypeObject gmhash_pytype_skel = {
+ PyObject_HEAD_INIT(0) 0, /* Header */
+ "GMACHash", /* @tp_name@ */
+ sizeof(ghash_pyobj), /* @tp_basicsize@ */
+ 0, /* @tp_itemsize@ */
+
+ ghash_pydealloc, /* @tp_dealloc@ */
+ 0, /* @tp_print@ */
+ 0, /* @tp_getattr@ */
+ 0, /* @tp_setattr@ */
+ 0, /* @tp_compare@ */
+ 0, /* @tp_repr@ */
+ 0, /* @tp_as_number@ */
+ 0, /* @tp_as_sequence@ */
+ 0, /* @tp_as_mapping@ */
+ 0, /* @tp_hash@ */
+ 0, /* @tp_call@ */
+ 0, /* @tp_str@ */
+ 0, /* @tp_getattro@ */
+ 0, /* @tp_setattro@ */
+ 0, /* @tp_as_buffer@ */
+ Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
+ Py_TPFLAGS_BASETYPE,
+
+ /* @tp_doc@ */
+"Message authentication code, abstract base class.",
+
+ 0, /* @tp_traverse@ */
+ 0, /* @tp_clear@ */
+ 0, /* @tp_richcompare@ */
+ 0, /* @tp_weaklistoffset@ */
+ 0, /* @tp_iter@ */
+ 0, /* @tp_iternext@ */
+ 0, /* @tp_methods@ */
+ 0, /* @tp_members@ */
+ 0, /* @tp_getset@ */
+ 0, /* @tp_base@ */
+ 0, /* @tp_dict@ */
+ 0, /* @tp_descr_get@ */
+ 0, /* @tp_descr_set@ */
+ 0, /* @tp_dictoffset@ */
+ 0, /* @tp_init@ */
+ PyType_GenericAlloc, /* @tp_alloc@ */
+ abstract_pynew, /* @tp_new@ */
+ 0, /* @tp_free@ */
+ 0 /* @tp_is_gc@ */
+};
+
+/*----- Special snowflake for Poly1305 ------------------------------------*/
+
+PyTypeObject *poly1305cls_pytype, *poly1305key_pytype, *poly1305hash_pytype;
+
+typedef struct poly1305key_pyobj {
+ PyHeapTypeObject ty;
+ poly1305_key k;
+} poly1305key_pyobj;
+
+typedef struct poly1305hash_pyobj {
+ PyObject_HEAD
+ unsigned f;
+#define f_mask 1u
+ poly1305_ctx ctx;
+} poly1305hash_pyobj;
+
+#define P1305_F(o) (((poly1305hash_pyobj *)(o))->f)
+#define P1305_CTX(o) (&((poly1305hash_pyobj *)(o))->ctx)
+CONVFUNC(poly1305hash, poly1305_ctx *, P1305_CTX)
+
+static PyObject *poly1305hash_pynew(PyTypeObject *ty,
+ PyObject *arg, PyObject *kw)
+{
+ static const char *const kwlist[] = { "mask", 0 };
+ poly1305key_pyobj *pk = (poly1305key_pyobj *)ty;
+ poly1305hash_pyobj *ph;
+ char *m = 0;
+ Py_ssize_t sz;
+
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "|s#:new", KWLIST, &m, &sz))
+ return (0);
+ if (m && sz != POLY1305_MASKSZ) VALERR("bad mask length");
+ ph = PyObject_NEW(poly1305hash_pyobj, ty);
+ ph->f = 0;
+ if (m) ph->f |= f_mask;
+ poly1305_macinit(&ph->ctx, &pk->k, m);
+ Py_INCREF(ty);
+ return ((PyObject *)ph);
+end:
+ return (0);
+}
+
+static PyObject *poly1305key_pynew(PyTypeObject *ty,
+ PyObject *arg, PyObject *kw)
+{
+ static const char *const kwlist[] = { "k", 0 };
+ poly1305key_pyobj *pk;
+ char *k;
+ Py_ssize_t sz;
+
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", KWLIST, &k, &sz))
+ goto end;
+ if (keysz(sz, poly1305_keysz) != sz) VALERR("bad key length");
+
+ pk = newtype(ty, 0, 0);
+ pk->ty.ht_name = PyString_FromString("poly1305(keyed)");
+ pk->ty.ht_type.tp_basicsize = sizeof(poly1305hash_pyobj);
+ pk->ty.ht_type.tp_name = PyString_AS_STRING(pk->ty.ht_name);
+ pk->ty.ht_type.tp_base = poly1305hash_pytype;
+ Py_INCREF(poly1305key_pytype);
+ pk->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT |
+ Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_HEAPTYPE);
+ pk->ty.ht_type.tp_alloc = PyType_GenericAlloc;
+ pk->ty.ht_type.tp_free = 0;
+ pk->ty.ht_type.tp_new = poly1305hash_pynew;
+ typeready(&pk->ty.ht_type);
+
+ poly1305_keyinit(&pk->k, k, sz);
+ return ((PyObject *)pk);
+
+end:
+ return (0);
+}
+
+static PyObject *poly1305clsget_name(PyObject *me, void *hunoz)
+ { return (PyString_FromString("poly1305")); }
+
+static PyObject *poly1305clsget_keysz(PyObject *me, void *hunoz)
+ { return (keysz_pywrap(poly1305_keysz)); }
+
+static PyObject *poly1305clsget_masksz(PyObject *me, void *hunoz)
+ { return (PyInt_FromLong(POLY1305_MASKSZ)); }
+
+static PyObject *poly1305clsget_tagsz(PyObject *me, void *hunoz)
+ { return (PyInt_FromLong(POLY1305_TAGSZ)); }
+
+static PyObject *polymeth_copy(PyObject *me, PyObject *arg)
+{
+ poly1305hash_pyobj *ph;
+ if (!PyArg_ParseTuple(arg, ":copy")) return (0);
+ ph = PyObject_NEW(poly1305hash_pyobj, me->ob_type);
+ poly1305_copy(&ph->ctx, P1305_CTX(me));
+ Py_INCREF(me->ob_type);
+ return ((PyObject *)ph);
+}
+
+static PyObject *polymeth_hash(PyObject *me, PyObject *arg)
+{
+ char *p;
+ Py_ssize_t sz;
+ if (!PyArg_ParseTuple(arg, "s#:hash", &p, &sz)) return (0);
+ poly1305_hash(P1305_CTX(me), p, sz);
+ RETURN_ME;
+}
+
+#define POLYMETH_HASHU_(n, W, w) \
+ static PyObject *polymeth_hashu##w(PyObject *me, PyObject *arg) \
+ { \
+ uint##n x; \
+ octet b[SZ_##W]; \
+ if (!PyArg_ParseTuple(arg, "O&:hashu" #w, convu##n, &x)) return (0); \
+ STORE##W(b, x); poly1305_hash(P1305_CTX(me), b, sizeof(b)); \
+ RETURN_ME; \
+ }
+DOUINTCONV(POLYMETH_HASHU_)
+
+#define POLYMETH_HASHBUF_(n, W, w) \
+ static PyObject *polymeth_hashbuf##w(PyObject *me, PyObject *arg) \
+ { \
+ char *p; \
+ Py_ssize_t sz; \
+ octet b[SZ_##W]; \
+ if (!PyArg_ParseTuple(arg, "s#:hashbuf" #w, &p, &sz)) goto end; \
+ if (sz > MASK##n) TYERR("string too long"); \
+ STORE##W(b, sz); poly1305_hash(P1305_CTX(me), b, sizeof(b)); \
+ poly1305_hash(P1305_CTX(me), p, sz); \
+ RETURN_ME; \
+ end: \
+ return (0); \
+ }
+DOUINTCONV(POLYMETH_HASHBUF_)
+
+static PyObject *polymeth_hashstrz(PyObject *me, PyObject *arg)
+{
+ char *p;
+ if (!PyArg_ParseTuple(arg, "s:hashstrz", &p)) return (0);
+ poly1305_hash(P1305_CTX(me), p, strlen(p) + 1);
+ RETURN_ME;
+}
+
+static PyObject *polymeth_flush(PyObject *me, PyObject *arg)
+{
+ if (!PyArg_ParseTuple(arg, ":flush")) return (0);
+ poly1305_flush(P1305_CTX(me));
+ RETURN_ME;
+}
+
+static PyObject *polymeth_flushzero(PyObject *me, PyObject *arg)
+{
+ if (!PyArg_ParseTuple(arg, ":flushzero")) return (0);
+ poly1305_flushzero(P1305_CTX(me));
+ RETURN_ME;
+}
+
+static PyObject *polymeth_concat(PyObject *me, PyObject *arg)
+{
+ PyObject *pre, *suff;
+ if (!PyArg_ParseTuple(arg, "OO:concat", &pre, &suff)) return (0);
+ if (!PyObject_TypeCheck(pre, poly1305hash_pytype) ||
+ !PyObject_TypeCheck(suff, poly1305hash_pytype))
+ TYERR("wanted a poly1305hash");
+ if (me->ob_type != pre->ob_type || me->ob_type != suff->ob_type)
+ TYERR("key mismatch");
+ if (P1305_CTX(pre)->nbuf) VALERR("prefix is not block-aligned");
+ poly1305_concat(P1305_CTX(me), P1305_CTX(pre), P1305_CTX(suff));
+ RETURN_ME;
+end:
+ return (0);
+}
+
+static PyObject *polymeth_done(PyObject *me, PyObject *arg)
+{
+ PyObject *rc;
+ if (!PyArg_ParseTuple(arg, ":done")) return (0);
+ if (!(P1305_F(me) & f_mask)) VALERR("no mask");
+ rc = bytestring_pywrap(0, POLY1305_TAGSZ);
+ poly1305_done(P1305_CTX(me), PyString_AS_STRING(rc));
+ return (rc);
+end:
+ return (0);
+}
+
+static PyGetSetDef poly1305cls_pygetset[] = {
+#define GETSETNAME(op, name) poly1305cls##op##_##name
+ GET (keysz, "PC.keysz -> acceptable key sizes")
+ GET (masksz, "PC.masksz -> mask size")
+ GET (tagsz, "PC.tagsz -> MAC output size")
+ GET (name, "PC.name -> name of this kind of MAC")
+#undef GETSETNAME
+ { 0 }
+};
+
+static PyMethodDef poly1305hash_pymethods[] = {
+#define METHNAME(name) polymeth_##name
+ METH (copy, "P.copy() -> PP")
+ METH (hash, "P.hash(M)")
+#define METHU_(n, W, w) METH(hashu##w, "P.hashu" #w "(WORD)")
+ DOUINTCONV(METHU_)
+#undef METHU_
+#define METHBUF_(n, W, w) METH(hashbuf##w, "P.hashbuf" #w "(BYTES)")
+ DOUINTCONV(METHBUF_)
+#undef METHBUF_
+ METH (hashstrz, "P.hashstrz(STRING)")
+ METH (flush, "P.flush()")
+ METH (flushzero, "P.flushzero()")
+ METH (concat, "P.concat(PREFIX, SUFFIX)")
+ METH (done, "P.done() -> TAG")
+#undef METHNAME
+ { 0 }
+};
+
+static PyTypeObject poly1305cls_pytype_skel = {
+ PyObject_HEAD_INIT(0) 0, /* Header */
+ "Poly1305Class", /* @tp_name@ */
+ sizeof(PyHeapTypeObject), /* @tp_basicsize@ */
+ 0, /* @tp_itemsize@ */
+
+ 0, /* @tp_dealloc@ */
+ 0, /* @tp_print@ */
+ 0, /* @tp_getattr@ */
+ 0, /* @tp_setattr@ */
+ 0, /* @tp_compare@ */
+ 0, /* @tp_repr@ */
+ 0, /* @tp_as_number@ */
+ 0, /* @tp_as_sequence@ */
+ 0, /* @tp_as_mapping@ */
+ 0, /* @tp_hash@ */
+ 0, /* @tp_call@ */
+ 0, /* @tp_str@ */
+ 0, /* @tp_getattro@ */
+ 0, /* @tp_setattro@ */
+ 0, /* @tp_as_buffer@ */
+ Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
+ Py_TPFLAGS_BASETYPE,
+
+ /* @tp_doc@ */
+"Poly1305 metametaclass. Best not to ask.",
+
+ 0, /* @tp_traverse@ */
+ 0, /* @tp_clear@ */
+ 0, /* @tp_richcompare@ */
+ 0, /* @tp_weaklistoffset@ */
+ 0, /* @tp_iter@ */
+ 0, /* @tp_iternext@ */
+ 0, /* @tp_methods@ */
+ 0, /* @tp_members@ */
+ poly1305cls_pygetset, /* @tp_getset@ */
+ 0, /* @tp_base@ */
+ 0, /* @tp_dict@ */
+ 0, /* @tp_descr_get@ */
+ 0, /* @tp_descr_set@ */
+ 0, /* @tp_dictoffset@ */
+ 0, /* @tp_init@ */
+ PyType_GenericAlloc, /* @tp_alloc@ */
+ abstract_pynew, /* @tp_new@ */
+ 0, /* @tp_free@ */
+ 0 /* @tp_is_gc@ */
+};
+
+static PyTypeObject poly1305key_pytype_skel = {
+ PyObject_HEAD_INIT(0) 0, /* Header */
+ "poly1305", /* @tp_name@ */
+ sizeof(poly1305key_pyobj), /* @tp_basicsize@ */
+ 0, /* @tp_itemsize@ */
+
+ 0, /* @tp_dealloc@ */
+ 0, /* @tp_print@ */
+ 0, /* @tp_getattr@ */
+ 0, /* @tp_setattr@ */
+ 0, /* @tp_compare@ */
+ 0, /* @tp_repr@ */
+ 0, /* @tp_as_number@ */
+ 0, /* @tp_as_sequence@ */
+ 0, /* @tp_as_mapping@ */
+ 0, /* @tp_hash@ */
+ 0, /* @tp_call@ */
+ 0, /* @tp_str@ */
+ 0, /* @tp_getattro@ */
+ 0, /* @tp_setattro@ */
+ 0, /* @tp_as_buffer@ */
+ Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
+ Py_TPFLAGS_BASETYPE,
+
+ /* @tp_doc@ */
+"poly1305(K): Poly1305 key.",
+
+ 0, /* @tp_traverse@ */
+ 0, /* @tp_clear@ */
+ 0, /* @tp_richcompare@ */
+ 0, /* @tp_weaklistoffset@ */
+ 0, /* @tp_iter@ */
+ 0, /* @tp_iternext@ */
+ 0, /* @tp_methods@ */
+ 0, /* @tp_members@ */
+ 0, /* @tp_getset@ */
+ 0, /* @tp_base@ */
+ 0, /* @tp_dict@ */
+ 0, /* @tp_descr_get@ */
+ 0, /* @tp_descr_set@ */
+ 0, /* @tp_dictoffset@ */
+ 0, /* @tp_init@ */
+ PyType_GenericAlloc, /* @tp_alloc@ */
+ poly1305key_pynew, /* @tp_new@ */
+ 0, /* @tp_free@ */
+ 0 /* @tp_is_gc@ */
+};
+
+static PyTypeObject poly1305hash_pytype_skel = {
+ PyObject_HEAD_INIT(0) 0, /* Header */
+ "Poly1305Hash", /* @tp_name@ */
+ sizeof(poly1305hash_pyobj), /* @tp_basicsize@ */
+ 0, /* @tp_itemsize@ */
+
+ 0, /* @tp_dealloc@ */
+ 0, /* @tp_print@ */
+ 0, /* @tp_getattr@ */
+ 0, /* @tp_setattr@ */
+ 0, /* @tp_compare@ */
+ 0, /* @tp_repr@ */
+ 0, /* @tp_as_number@ */
+ 0, /* @tp_as_sequence@ */
+ 0, /* @tp_as_mapping@ */
+ 0, /* @tp_hash@ */
+ 0, /* @tp_call@ */
+ 0, /* @tp_str@ */
+ 0, /* @tp_getattro@ */
+ 0, /* @tp_setattro@ */
+ 0, /* @tp_as_buffer@ */
+ Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
+ Py_TPFLAGS_BASETYPE,
+
+ /* @tp_doc@ */
+"Poly1305 MAC context base class.",
+
+ 0, /* @tp_traverse@ */
+ 0, /* @tp_clear@ */
+ 0, /* @tp_richcompare@ */
+ 0, /* @tp_weaklistoffset@ */
+ 0, /* @tp_iter@ */
+ 0, /* @tp_iternext@ */
+ poly1305hash_pymethods, /* @tp_methods@ */
+ 0, /* @tp_members@ */
+ 0, /* @tp_getset@ */
+ 0, /* @tp_base@ */
+ 0, /* @tp_dict@ */
+ 0, /* @tp_descr_get@ */
+ 0, /* @tp_descr_set@ */
+ 0, /* @tp_dictoffset@ */
+ 0, /* @tp_init@ */
+ PyType_GenericAlloc, /* @tp_alloc@ */
+ abstract_pynew, /* @tp_new@ */
+ 0, /* @tp_free@ */
+ 0 /* @tp_is_gc@ */
+};
+
+/*----- Special snowflake for HSalsa and HChaCha --------------------------*/
+
+#define DEF_HDANCE(DANCE, HDANCE, dance, hdance) \
+ static PyObject *meth_##hdance##_prf(PyObject *me, PyObject *arg) \
+ { \
+ dance##_ctx dance; \
+ char *k, *n; \
+ Py_ssize_t ksz, nsz; \
+ PyObject *rc; \
+ if (!PyArg_ParseTuple(arg, "s#s#:" #hdance "_prf", \
+ &k, &ksz, &n, &nsz)) \
+ goto end; \
+ if (ksz != DANCE##_KEYSZ) VALERR("bad key length"); \
+ if (nsz != HDANCE##_INSZ) VALERR("bad input length"); \
+ rc = bytestring_pywrap(0, HSALSA20_OUTSZ); \
+ dance##_init(&dance, k, ksz, 0); \
+ hdance##_prf(&dance, n, PyString_AS_STRING(rc)); \
+ return (rc); \
+ end: \
+ return (0); \
+ }
+
+DEF_HDANCE(SALSA20, HSALSA20, salsa20, hsalsa20)
+DEF_HDANCE(SALSA20, HSALSA20, salsa20, hsalsa2012)
+DEF_HDANCE(SALSA20, HSALSA20, salsa20, hsalsa208)
+
+DEF_HDANCE(CHACHA, HCHACHA, chacha, hchacha20)
+DEF_HDANCE(CHACHA, HCHACHA, chacha, hchacha12)
+DEF_HDANCE(CHACHA, HCHACHA, chacha, hchacha8)
+
+/*----- Keccak-p[1600, n] -------------------------------------------------*/
+
+static PyTypeObject *kxvik_pytype;
+
+typedef struct kxvik_pyobj {
+ PyObject_HEAD
+ keccak1600_state s;
+ unsigned n;
+} kxvik_pyobj;
+
+static PyObject *kxvik_pynew(PyTypeObject *ty,
+ PyObject *arg, PyObject *kw)
+{
+ unsigned n = 24;
+ kxvik_pyobj *rc = 0;
+ static const char *const kwlist[] = { "nround", 0 };
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:new", KWLIST,
+ convuint, &n))
+ goto end;
+ rc = (kxvik_pyobj *)ty->tp_alloc(ty, 0);
+ rc->n = n;
+ keccak1600_init(&rc->s);
+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;
+ kludge64 t[25];
+ const octet *q;
+ octet buf[8];
+ unsigned i;
+ char *p; Py_ssize_t n;
+
+ if (!PyArg_ParseTuple(arg, "s#:mix", &p, &n)) goto end;
+ if (n > 200) VALERR("out of range");
+ q = (const octet *)p;
+ i = 0;
+ while (n > 8) { LOAD64_L_(t[i], q); i++; q += 8; n -= 8; }
+ if (n) {
+ memcpy(buf, q, n); memset(buf + n, 0, 8 - n);
+ LOAD64_L_(t[i], buf); i++;
+ }
+ keccak1600_mix(&k->s, t, i);
+ RETURN_ME;
+end:
+ return (0);
+}
+
+static PyObject *kxvikmeth_extract(PyObject *me, PyObject *arg)
+{
+ kxvik_pyobj *k = (kxvik_pyobj *)me;
+ PyObject *rc = 0;
+ kludge64 t[25];
+ octet *q, buf[8];
+ unsigned i;
+ unsigned n;
+
+ if (!PyArg_ParseTuple(arg, "O&:mix", convuint, &n)) goto end;
+ if (n > 200) VALERR("out of range");
+ rc = bytestring_pywrap(0, n);
+ q = (octet *)PyString_AS_STRING(rc);
+ keccak1600_extract(&k->s, t, (n + 7)/8);
+ i = 0;
+ while (n > 8) { STORE64_L_(q, t[i]); i++; q += 8; n -= 8; }
+ if (n) { STORE64_L_(buf, t[i]); memcpy(q, buf, n); }
+end:
+ return (rc);
+}
+
+static PyObject *kxvikmeth_step(PyObject *me, PyObject *arg)
+{
+ kxvik_pyobj *k = (kxvik_pyobj *)me;
+ if (!PyArg_ParseTuple(arg, ":step")) return (0);
+ keccak1600_p(&k->s, &k->s, k->n);
+ RETURN_ME;
+}