libswarm-ng

C implementation of BMT hasher, Swarmhash and Single Owner Chunk for swarm
git clone git://git.defalsify.org/libswarm-ng.git
Log | Files | Refs | Submodules | README

commit 4137f9d8d2694baf9ff81f1629c8fd771f57eaa8
parent 46cd971c36f164c73db91ce6f6e9713c3d3e2959
Author: nolash <dev@holbrook.no>
Date:   Fri,  1 Oct 2021 08:49:57 +0200

Add libcheck to aux

Diffstat:
M.gitmodules | 3+++
MMakefile.dev | 24++++++++++++++----------
Aaux/check | 1+
Mscripts/wasm/bmt.js | 8++++----
Msrc/wasm/wasm.c | 4+---
5 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/.gitmodules b/.gitmodules @@ -7,3 +7,6 @@ [submodule "aux/secp256k1"] path = aux/secp256k1 url = https://gitlab.com/nolash/secp256k1 +[submodule "aux/check"] + path = aux/check + url = https://github.com/libcheck/check diff --git a/Makefile.dev b/Makefile.dev @@ -1,8 +1,11 @@ KECCAK_DIR = ./aux/keccak-tiny -INCLUDE = -I./src -I$(KECCAK_DIR) -L./build/lib/ +SECP256K1_DIR = ./aux/secp256k1 +CHECK_DIR = ./aux/check +INCLUDE = -I./src -I$(KECCAK_DIR) -I$(SECP256K1_DIR)/include -I$(CHECK_DIR)/src LIBS += -L./build/ CFLAGS += $(INCLUDE) $(LIBS) CFLAGS_CHECK = $(CFLAGS) -L./build/test ./aux/secp256k1/.libs/libsecp256k1.a +LD_LIBRARY_PATH = ./build/:./build/test:./aux/secp256k1/.libs:./aux/check/src/.libs prefix = /usr/local includedir = $(prefix)/include libdir = $(prefix)/lib @@ -56,9 +59,10 @@ build_check_common: # TODO: should not be necessary to add -lsecp256k1 here build_check: build_base_malloc build_check_common - $(CC) -I./src -o build/test/check_bmt build/swarm.o build/bmt.o build/endian.o build/swarmfile.o test/check_bmt.c $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon -lsecp256k1 - $(CC) -I./src -o build/test/check_file build/swarm.o build/bmt.o build/endian.o build/swarmfile.o test/check_file.c $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon -lsecp256k1 - $(CC) -I./src -o build/test/check_chunk build/chunk.o build/swarm.o build/bmt.o build/endian.o build/swarmfile.o test/check_chunk.c $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon -lsecp256k1 + $(CC) -I./src -o build/test/check_bmt build/swarm.o build/bmt.o build/endian.o build/swarmfile.o test/check_bmt.c $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon + $(CC) -I./src -o build/test/check_bmt_malloc build/swarm.o build/bmt.o build/endian.o build/swarmfile.o test/check_bmt_malloc.c $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon + $(CC) -I./src -o build/test/check_file build/swarm.o build/bmt.o build/endian.o build/swarmfile.o test/check_file.c $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon + $(CC) -I./src -o build/test/check_chunk build/chunk.o build/swarm.o build/bmt.o build/endian.o build/swarmfile.o test/check_chunk.c $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon build_check_stack: build_base build_check_common $(CC) -I./src -o build/test/check_bmt build/swarm.o build/bmt.o build/endian.o build/swarmfile.o test/check_bmt.c $(CFLAGS_CHECK) -lcheck -lkeccak-tiny -ltestcommon -lsecp256k1 @@ -78,24 +82,24 @@ build_lib: build .PHONY: test clean check_bmt: build_check - LD_LIBRARY_PATH=./build/:./build/test CK_FORK=no CFLAGS=-DLIBSWARM_MALLOC build/test/check_bmt_malloc + LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CK_FORK=no CFLAGS=-DLIBSWARM_MALLOC build/test/check_bmt_malloc check_bmt_stack: build_check_stack - LD_LIBRARY_PATH=./build/:./build/test CK_FORK=no CFLAGS=-DLIBSWARM_MALLOC build/test/check_bmt + LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CK_FORK=no CFLAGS=-DLIBSWARM_MALLOC build/test/check_bmt check_chunk: build_check - LD_LIBRARY_PATH=./build/:./build/test CK_FORK=no build/test/check_chunk + LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CK_FORK=no build/test/check_chunk check_file: build_check - LD_LIBRARY_PATH=./build/:./build/test CK_FORK=no build/test/check_file + LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CK_FORK=no build/test/check_file check_base: check_bmt check_chunk check_file check_keystore: build_check_keystore - LD_LIBRARY_PATH=./build/:./build/test CK_FORK=no build/test/check_keystore + LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CK_FORK=no build/test/check_keystore check_soc: build_check_soc - LD_LIBRARY_PATH=./build/:./build/test CK_FORK=no build/test/check_soc + LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) CK_FORK=no build/test/check_soc # TODO: file test is flaky, check_base should be first instead check: check_keystore check_soc check_base diff --git a/aux/check b/aux/check @@ -0,0 +1 @@ +Subproject commit 11970a7e112dfe243a2e68773f014687df2900e8 diff --git a/scripts/wasm/bmt.js b/scripts/wasm/bmt.js @@ -5,10 +5,10 @@ const table = new WebAssembly.Table({initial: 10, element: 'anyfunc'}); const importsObj = { env: { memory: memory, - __linear_memory: memory, - __indirect_function_table: table, - dlog: function(prefix, value) { - console.debug(prefix, value); + dlog: function(prefix, l, value) { + const v = new Uint8Array(memory.buffer, prefix, l); + const s = new TextDecoder().decode(v); + console.log('log: ' + s, value); }, } } diff --git a/src/wasm/wasm.c b/src/wasm/wasm.c @@ -3,8 +3,6 @@ #include "bmt.h" -extern void dlog(int p, int v); - size_t keccak_hash_heap_init(size_t outLen, size_t inLen) { return (size_t)malloc(outLen + inLen); } @@ -15,7 +13,7 @@ void keccak_hash_heap_free(void *mem) { void *bmt_hash_heap(const unsigned char *input, const size_t input_length, const bmt_spansize_t data_length) { unsigned char *out; - + out = malloc(SWARM_WORD_SIZE + input_length); bmt_hash(out, input, input_length, data_length);