Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OSX build support. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,9 @@ example
preprocessMatrices
*.exe

# OSX Executables and library output objects
sha3/libshake.dylib
create_test_vectors
libpicnic.dylib
libshake.dylib
unit_test
32 changes: 28 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@

ifeq ($(OS),Windows_NT)
UNAME_S=Windows
else
UNAME_S := $(shell uname -s)
endif
CC=gcc
WARNING_FLAGS=-Wall -Wextra -Wpedantic -Werror
CFLAGS= -O2 -march=native $(WARNING_FLAGS) -std=gnu99 -D__LINUX__ -D__X64__ -I./sha3
CFLAGS_DEBUG= -g -march=native $(WARNING_FLAGS) -std=gnu99 -fsanitize=address -D__LINUX__ -D__X64__ -I./sha3
SHA3LIB=libshake.a
ifeq ($(UNAME_S),Darwin)
SHA3LIB=libshake.dylib
else
SHA3LIB=libshake.a
endif

SHA3_PATH=sha3
LDFLAGS= $(SHA3_PATH)/$(SHA3LIB)
ifeq ($(UNAME_S),Darwin)
DYLIBFLAGS=-dynamiclib -undefined suppress -flat_namespace
LDFLAGS=$(SHA3LIB)
else
LDFLAGS=$(SHA3_PATH)/$(SHA3LIB)
endif

SOURCES= picnic_impl.c picnic.c lowmc_constants.c
PICNIC_OBJECTS= picnic_impl.o picnic.o lowmc_constants.o hash.o picnic_types.o
PICNIC_LIB= libpicnic.a
ifeq ($(UNAME_S),Darwin)
PICNIC_LIB=libpicnic.dylib
else
PICNIC_LIB=libpicnic.a
endif
EXECUTABLE_EXAMPLE=example
EXECUTABLE_TESTVECTORS=create_test_vectors
EXECUTABLE_UNITTEST=unit_test
Expand Down Expand Up @@ -41,7 +59,12 @@ $(EXECUTABLE_BENCHMARK): $(PICNIC_LIB)
$(CC) -c $(CFLAGS) $< -o $@

$(PICNIC_LIB): $(PICNIC_OBJECTS)
ifeq ($(UNAME_S),Darwin)
mv $(SHA3_PATH)/$(SHA3LIB) .
$(CC) $^ -o $@ $(LDFLAGS) $(DYLIBFLAGS)
else
ar rcs $@ $^
endif


clean:
Expand All @@ -52,5 +75,6 @@ clean:
rm $(EXECUTABLE_UNITTEST) 2>/dev/null || true
rm $(EXECUTABLE_TESTVECTORS) 2>/dev/null || true
rm $(EXECUTABLE_BENCHMARK) 2>/dev/null || true
rm $(SHA3LIB) 2>/dev/null || true
rm $(PICNIC_LIB) 2>/dev/null || true
$(MAKE) -C $(SHA3_PATH) clean
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,22 @@ Open the solution in `VisualStudio\picnic.sln`, and build the projects.
The project `libpicnic` creates a `.lib` file, containing the functions defined `in picnic.h`.
See the `example` project for a simple application that calls functions in

## OSX Build Instructions

Tested on OSX High Sierra with clang 9.

1. `make`
This will build the project. `make debug` will build with symbols and address sanitizer.

2. `./example`
Runs an example program that exercises the keygen, sign, verify and
serialization APIs. See [example.c](https://github.com/Microsoft/Picnic/blob/master/example.c).

### Acknowledgments
Thanks to Christian Paquin for providing feedback on picnic.h and for adding
support for a Windows build
support for a Windows build.

Thanks to Robert Krzyzanowski for adding support for an OSX build.

### Contributing

Expand Down
35 changes: 35 additions & 0 deletions osx/endian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// https://gist.github.com/yinyin/2027912
#ifndef __FINK_ENDIANDEV_PKG_ENDIAN_H__
#define __FINK_ENDIANDEV_PKG_ENDIAN_H__ 1

/** compatibility header for endian.h
* This is a simple compatibility shim to convert
* BSD/Linux endian macros to the Mac OS X equivalents.
* It is public domain.
* */

#ifndef __APPLE__
#warning "This header file (endian.h) is MacOS X specific.\n"
#endif /* __APPLE__ */


#include <libkern/OSByteOrder.h>

#define htobe16(x) OSSwapHostToBigInt16(x)
#define htole16(x) OSSwapHostToLittleInt16(x)
#define be16toh(x) OSSwapBigToHostInt16(x)
#define le16toh(x) OSSwapLittleToHostInt16(x)

#define htobe32(x) OSSwapHostToBigInt32(x)
#define htole32(x) OSSwapHostToLittleInt32(x)
#define be32toh(x) OSSwapBigToHostInt32(x)
#define le32toh(x) OSSwapLittleToHostInt32(x)

#define htobe64(x) OSSwapHostToBigInt64(x)
#define htole64(x) OSSwapHostToLittleInt64(x)
#define be64toh(x) OSSwapBigToHostInt64(x)
#define le64toh(x) OSSwapLittleToHostInt64(x)


#endif /* __FINK_ENDIANDEV_PKG_ENDIAN_H__ */

4 changes: 4 additions & 0 deletions picnic_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
#include <Windows.h>
#include <bcrypt.h>
#else
#if defined(__APPLE__)
#include "osx/endian.h"
#else
#include <endian.h>
#endif
#endif

#include "picnic_impl.h"
Expand Down
20 changes: 18 additions & 2 deletions sha3/Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
ifeq ($(OS),Windows_NT)
UNAME_S=Windows
else
UNAME_S := $(shell uname -s)
endif
CC=gcc
WARNING_FLAGS=-Wall -Wextra -Wpedantic -Werror -Wno-unused-function
CFLAGS= -O2 -march=native $(WARNING_FLAGS) -std=gnu99

SOURCES=$(wildcard *.c)
OBJECTS=$(patsubst %.c,%.o,$(wildcard *.c))
SHA3LIB=libshake.a
ifeq ($(UNAME_S),Darwin)
SHA3LIB=libshake.dylib
else
SHA3LIB=libshake.a
endif

ifeq ($(UNAME_S),Darwin)
DYLIBFLAGS=-dynamiclib -undefined suppress -flat_namespace
endif

all: $(SOURCES) $(SHA3LIB)

$(SHA3LIB): $(OBJECTS)
ifeq ($(UNAME_S),Darwin)
$(CC) $^ -o $@ $(LDFLAGS) $(DYLIBFLAGS)
else
ar rcs $@ $^
endif

#.c.o:
# $(CC) -c $(CFLAGS) $< -o $@ $(LDFLAGS)

clean:
rm *.o 2>/dev/null || true
rm libkeccak.a 2>/dev/null || true
rm $(SHA3LIB) 2>/dev/null || true