pylibswarm

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

commit 1f739d34786f6881234f65bc0e8b8c060decdc16
parent 194f09387938d21467e22e1ea8434a248eaff9f4
Author: nolash <dev@holbrook.no>
Date:   Tue, 14 Sep 2021 07:43:24 +0200

Add submodule deps

Diffstat:
A.gitignore | 6++++++
A.gitmodules | 3+++
Aaux/libswarm-ng | 1+
Mpylibswarm/runnable/bmt.py | 3++-
Msetup.py | 20+++++++++++++++-----
Msrc/python_swarm.c | 2+-
6 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,6 @@ +__pycache__ +build/ +*.pyc +*.so +*.o +*.a diff --git a/.gitmodules b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "aux/libswarm-ng"] + path = aux/libswarm-ng + url = https://gitlab.com/smallswarm/libswarm-ng.git diff --git a/aux/libswarm-ng b/aux/libswarm-ng @@ -0,0 +1 @@ +Subproject commit 77cbcb59b3af47e96d2f87814df777ed616f13d7 diff --git a/pylibswarm/runnable/bmt.py b/pylibswarm/runnable/bmt.py @@ -3,6 +3,7 @@ import argparse import sys import logging import select +import copy logging.basicConfig(level=logging.WARNING) logg = logging.getLogger() @@ -56,7 +57,7 @@ logg.info('hashing {} bytes input with {} length prefix'.format(int(input_data_ def main(): - # TODO: why does this segfault just one line before? + # TODO: why does this segfault just one line before? - probably refcount related import swarm r = swarm.bmt(input_data, input_data_length, data_length) diff --git a/setup.py b/setup.py @@ -1,7 +1,9 @@ import os from distutils.core import setup, Extension -swarm_dir = "/home/lash/src/home/libswarm-ng/src" +#swarm_dir = "/home/lash/src/home/libswarm-ng" +root_dir = os.path.dirname(os.path.realpath(__file__)) +swarm_dir = os.path.join(root_dir, 'aux', 'libswarm-ng') def main(): setup( @@ -13,10 +15,18 @@ def main(): 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'), - ]), + os.path.join(swarm_dir, 'src/bmt.c'), + os.path.join(swarm_dir, 'src/endian.c'), + os.path.join(swarm_dir, 'aux/keccak-tiny/keccak-tiny.c'), + ], + include_dirs=[ + os.path.join(swarm_dir, 'src'), + os.path.join(swarm_dir, 'aux/keccak-tiny'), + ], + extra_compile_args=[ + '-Dmemset_s(W,WL,V,OL)=memset(W,V,OL)', + ], + ), ], ) diff --git a/src/python_swarm.c b/src/python_swarm.c @@ -18,7 +18,7 @@ static PyObject* method_bmt(PyObject *self, PyObject *args) { } bmt_init(&bmt_content, (char*)input, input_length, data_length); bmt_sum(&bmt_content); - return Py_BuildValue("y", &bmt_content.buf); + return Py_BuildValue("y#", &bmt_content.buf, _WORD_SIZE); }