pylibswarm

Python3 wrapper for libswarm-ng
git clone git://git.defalsify.org/pylibswarm.git
Log | Files | Refs | Submodules | README | LICENSE

commit 79508bafa85d206bb0989d0a869c9ff40c2abbfd
Author: nolash <dev@holbrook.no>
Date:   Mon, 13 Sep 2021 20:16:31 +0200

WIP interface bmt_init with local linking and reference

Diffstat:
Asetup.py | 24++++++++++++++++++++++++
Asrc/python_swarm.c | 41+++++++++++++++++++++++++++++++++++++++++
Atest.py | 6++++++
3 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/setup.py b/setup.py @@ -0,0 +1,24 @@ +import os +from distutils.core import setup, Extension + +swarm_dir = "/home/lash/src/home/libswarm-ng/src" + +def main(): + setup( + name="swarm", + version="0.0.1a1", + description="Swarm tooling", + author="Louis Holbrook", + author_email="dev@holbrook.no", + ext_modules=[ + Extension("swarm", [ + "src/python_swarm.c", + os.path.join(swarm_dir, 'bmt.c'), + os.path.join(swarm_dir, 'endian.c'), + os.path.join(swarm_dir, '../aux/keccak-tiny/keccak-tiny.c'), + ]), + ], + ) + +if __name__ == '__main__': + main() diff --git a/src/python_swarm.c b/src/python_swarm.c @@ -0,0 +1,41 @@ +#define PY_SSIZE_T_CLEAN +#include <Python.h> +#include <stdio.h> + +#include "bmt.h" + +static PyObject* method_bmt(PyObject *self, PyObject *args) { + bmt_t bmt_content; + const char *input; + //Py_ssize_t *input_length; + int input_length; + long long data_length; + int r; + + r = PyArg_ParseTuple(args, "yIL", &input, &input_length, &data_length); + if (r != 1) { + return NULL; + } + int foo = 0; + bmt_init(&bmt_content, (char*)input, (size_t)foo, data_length); + bmt_sum(&bmt_content); + //return PyLong_FromLong(0); + return Py_BuildValue("y", &bmt_content.buf); +} + +static PyMethodDef SwarmMethods[] = { + {"bmt", method_bmt, METH_VARARGS, "Calculate the BMT hash of the given data"}, + {NULL, NULL, 0, NULL}, +}; + +static struct PyModuleDef bmtmodule = { + PyModuleDef_HEAD_INIT, + "swarm", + NULL, + -1, + SwarmMethods, +}; + +PyMODINIT_FUNC PyInit_swarm(void) { + return PyModule_Create(&bmtmodule); +} diff --git a/test.py b/test.py @@ -0,0 +1,6 @@ +import swarm + +print('swaaarm {}'.format(swarm)) + +b = swarm.bmt(b'foo', 3, 3) +print('%x', b[:32])