diff --git a/src/dkg.c b/src/dkg.c index 78618bd..5107fc8 100644 --- a/src/dkg.c +++ b/src/dkg.c @@ -2,7 +2,11 @@ #include #include #include // time +#ifdef __WIN32__ +#include +#else #include //htons +#endif #include "toprf.h" #include "utils.h" #include "dkg.h" diff --git a/src/makefile b/src/makefile index b2dd1d4..a0b6db7 100644 --- a/src/makefile +++ b/src/makefile @@ -22,15 +22,13 @@ else CFLAGS+=-Wl,-z,defs -Wl,-z,relro -Wl,-z,noexecstack -Wl,-z,now -Wtrampolines \ -fsanitize=signed-integer-overflow -fsanitize-undefined-trap-on-error #-fstrict-flex-arrays=3 -mbranch-protection=standard - SOEXT=so + SOEXT?=so SOFLAGS=-Wl,-soname,liboprf.$(SOEXT).$(SOVER) ifeq ($(ARCH),x86_64) CFLAGS+=-fcf-protection=full endif - ifeq ($(ARCH),parisc64) - else ifeq ($(ARCH),parisc64) - else + ifneq ($(ARCH),parisc64) CFLAGS+=-fstack-clash-protection endif endif @@ -47,6 +45,7 @@ CFLAGS+=$(INCLUDES) SOURCES=oprf.c toprf.c dkg.c dkg-vss.c utils.c tp-dkg.c mpmult.c stp-dkg.c $(EXTRA_SOURCES) OBJECTS=$(patsubst %.c,%.o,$(SOURCES)) +MAKETARGET=all all: liboprf.$(SOEXT) liboprf.$(STATICEXT) noise_xk/liboprf-noiseXK.$(SOEXT) @@ -54,7 +53,7 @@ debug: DEFINES=-DTRACE debug: all asan: - CFLAGS=-fsanitize=address -static-libasan -g -march=native -Wall -O2 -g -fstack-protector-strong -fpic -Werror=format-security -Werror=implicit-function-declaration -Wl, -z,noexecstack + CFLAGS=-fsanitize=address -static-libasan -g -march=native -Wall -O2 -g -fstack-protector-strong -fpic -Werror=format-security -Werror=implicit-function-declaration -Wl,-z,noexecstack $(DEFINES) ifeq ($(ARCH),x86_64) CFLAGS+=-fcf-protection=full endif @@ -66,6 +65,15 @@ asan: asan: LDFLAGS+= -fsanitize=address -static-libasan asan: all +mingw64: CC=x86_64-w64-mingw32-gcc +mingw64: LDFLAGS+=-L. -lws2_32 -Lwin/libsodium-win64/lib/ -Wl,-Bstatic -lsodium -Wl,-Bdynamic +mingw64: CFLAGS=-march=native -Wall -O2 -g -fstack-protector-strong -D_FORTIFY_SOURCE=2 -fasynchronous-unwind-tables -fpic -Werror=format-security -Werror=implicit-function-declaration -ftrapv $(DEFINES) $(INCLUDES) -Iwin/libsodium-win64/include/sodium -Iwin/libsodium-win64/include +mingw64: SOEXT=dll +mingw64: STATICEXT=dll +mingw64: EXT=.exe +mingw64: MAKETARGET=mingw64 +mingw64: win/libsodium-win64 noise_xk/liboprf-noiseXK.$(STATICEXT) liboprf.$(STATICEXT) + AR ?= ar liboprf.$(SOEXT): $(SOURCES) noise_xk/liboprf-noiseXK.$(SOEXT) @@ -78,10 +86,10 @@ liboprf.$(STATICEXT): $(OBJECTS) $(AR) rcs $@ $^ noise_xk/liboprf-noiseXK.$(SOEXT): - make -C noise_xk all + make -C noise_xk $(MAKETARGET) noise_xk/liboprf-noiseXK.$(STATICEXT): - make -C noise_xk all + make -C noise_xk $(MAKETARGET) clean: rm -f *.o liboprf.$(SOEXT) liboprf.$(STATICEXT) liboprf-corrupt-dkg.$(SOEXT) @@ -143,4 +151,10 @@ test: liboprf-corrupt-dkg.$(SOEXT) liboprf.$(STATICEXT) noise_xk/liboprf-noiseXK make -C tests tests make -C noise_xk test +win/libsodium-win64: + @echo 'win/libsodium-win64 not found.' + @echo 'download and unpack latest libsodium-*-mingw.tar.gz and unpack into win/' + @echo 'https://download.libsodium.org/libsodium/releases/' + @false + PHONY: clean diff --git a/src/noise_xk/makefile b/src/noise_xk/makefile index fccbf88..8cdd230 100644 --- a/src/noise_xk/makefile +++ b/src/noise_xk/makefile @@ -1,16 +1,15 @@ PREFIX?=/usr/local LDFLAGS=-lsodium SOURCES=src/Noise_XK.c src/XK.c - -CFLAGS ?= -Iinclude -I include/karmel -I include/karmel/minimal \ - -Wall -Wextra -Werror -std=c11 -Wno-unused-variable \ +INCLUDES=-Iinclude -I include/karmel -I include/karmel/minimal +CFLAGS ?= -Wall -Wextra -Werror -std=c11 -Wno-unused-variable \ -Wno-unknown-warning-option -Wno-unused-but-set-variable \ -Wno-unused-parameter -Wno-infinite-recursion -fpic \ -g -fwrapv -D_BSD_SOURCE -D_DEFAULT_SOURCE -DWITH_SODIUM \ -O2 -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 \ -fasynchronous-unwind-tables -fpic \ -Werror=format-security -Werror=implicit-function-declaration \ - -ftrapv + -ftrapv $(INCLUDES) CC?=gcc SOEXT?=so @@ -38,6 +37,18 @@ else endif endif +mingw64: CC=x86_64-w64-mingw32-gcc +mingw64: SOEXT=dll +mingw64: STATICEXT=lib +mingw64: EXT=.exe +mingw64: MAKETARGET=mingw +mingw64: CFLAGS=-march=native -Wall -O2 -g -fstack-protector-strong -D_FORTIFY_SOURCE=2 \ + -fasynchronous-unwind-tables -fpic -Werror=format-security \ + -Werror=implicit-function-declaration -ftrapv $(DEFINES) $(INCLUDES) \ + -I../win/libsodium-win64/include/sodium -I../win/libsodium-win64/include +mingw64: LDFLAGS+=-L. -L.. -L../win/libsodium-win64/lib/ -Wl,-Bstatic -lsodium +mingw64: liboprf-noiseXK.$(STATICEXT) + OBJS += $(patsubst %.c,%.o,$(SOURCES)) all: liboprf-noiseXK.$(STATICEXT) liboprf-noiseXK.$(SOEXT) diff --git a/src/oprf.c b/src/oprf.c index 2e4de71..14a89b3 100644 --- a/src/oprf.c +++ b/src/oprf.c @@ -19,7 +19,11 @@ #include #include #include +#ifdef __WIN32__ +#include +#else #include +#endif #include "oprf.h" #include "utils.h" #include "toprf.h" diff --git a/src/stp-dkg.c b/src/stp-dkg.c index 4445e21..4eed0b7 100644 --- a/src/stp-dkg.c +++ b/src/stp-dkg.c @@ -1,4 +1,8 @@ +#ifdef __WIN32__ +#include +#else #include //htons +#endif #include "utils.h" #include "stp-dkg.h" #include "dkg-vss.h" diff --git a/src/toprf-update.c b/src/toprf-update.c index 7f21016..785b2e0 100644 --- a/src/toprf-update.c +++ b/src/toprf-update.c @@ -1,4 +1,8 @@ +#ifdef __WIN32__ +#include +#else #include //htons +#endif #include "utils.h" #include "toprf-update.h" #include "dkg-vss.h" diff --git a/src/toprf.c b/src/toprf.c index 4c0ac40..9773c9f 100644 --- a/src/toprf.c +++ b/src/toprf.c @@ -1,7 +1,11 @@ #include #include "oprf.h" #include "toprf.h" +#ifdef __WIN32__ +#include +#else #include +#endif #ifdef UNIT_TEST #include "utils.h" #endif diff --git a/src/tp-dkg.c b/src/tp-dkg.c index 0cbc1c9..feff23e 100644 --- a/src/tp-dkg.c +++ b/src/tp-dkg.c @@ -1,7 +1,11 @@ #include #include #include +#ifdef __WIN32__ +#include +#else #include //htons +#endif #include // __BYTE_ORDER __BIG_ENDIAN #include // memcpy #include // va_{start|end} diff --git a/src/utils.c b/src/utils.c index 41a03eb..d25f3f5 100644 --- a/src/utils.c +++ b/src/utils.c @@ -51,7 +51,11 @@ void fail(const char* msg, ...) { } #ifndef htonll +#ifdef __WIN32__ +#include +#else #include +#endif uint64_t htonll(uint64_t n) { #if __BYTE_ORDER == __BIG_ENDIAN return n;