You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

245 lines
7.5 KiB

  1. # Copyright (c) 2014 Cryptography Research, Inc.
  2. # Released under the MIT License. See LICENSE.txt for license information.
  3. UNAME := $(shell uname)
  4. MACHINE := $(shell uname -m)
  5. # Subdirectories for objects etc.
  6. # Many of them are mapped to build/obj right now, but could be split later.
  7. # The non-build/obj directories are the public interface.
  8. BUILD_ASM = build/obj
  9. BUILD_OBJ = build/obj
  10. BUILD_C = build/obj
  11. BUILD_PY = build/obj
  12. BUILD_LIB = build/lib
  13. BUILD_INC = build/include
  14. BUILD_BIN = build/bin
  15. BUILD_IBIN = build/obj/bin
  16. BATBASE=ed448goldilocks_decaf_bats_$(TODAY)
  17. BATNAME=build/$(BATBASE)
  18. ifeq ($(UNAME),Darwin)
  19. CC = clang
  20. CXX = clang++
  21. else
  22. CC = gcc
  23. CXX = g++
  24. endif
  25. LD = $(CC)
  26. LDXX = $(CXX)
  27. ASM ?= $(CC)
  28. DECAF ?= decaf_fast
  29. ifneq (,$(findstring x86_64,$(MACHINE)))
  30. ARCH ?= arch_x86_64
  31. else
  32. # no i386 port yet
  33. ARCH ?= arch_ref32
  34. endif
  35. FIELD ?= p25519
  36. WARNFLAGS = -pedantic -Wall -Wextra -Werror -Wunreachable-code \
  37. -Wmissing-declarations -Wunused-function -Wno-overlength-strings $(EXWARN)
  38. INCFLAGS = -Isrc/include -Isrc/public_include -Isrc/$(FIELD) -Isrc/$(FIELD)/$(ARCH)
  39. LANGFLAGS = -std=c99 -fno-strict-aliasing
  40. LANGXXFLAGS = -fno-strict-aliasing
  41. GENFLAGS = -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC
  42. OFLAGS ?= -O2
  43. TODAY = $(shell date "+%Y-%m-%d")
  44. ifneq (,$(findstring arm,$(MACHINE)))
  45. ifneq (,$(findstring neon,$(ARCH)))
  46. ARCHFLAGS += -mfpu=neon
  47. else
  48. ARCHFLAGS += -mfpu=vfpv3-d16
  49. endif
  50. ARCHFLAGS += -mcpu=cortex-a8 # FIXME
  51. GENFLAGS += -DN_TESTS_BASE=1000 # sooooo sloooooow
  52. else
  53. ARCHFLAGS += -maes -mavx2 -mbmi2 #TODO
  54. endif
  55. ifeq ($(CC),clang)
  56. WARNFLAGS += -Wgcc-compat
  57. endif
  58. ARCHFLAGS += $(XARCHFLAGS)
  59. CFLAGS = $(LANGFLAGS) $(WARNFLAGS) $(INCFLAGS) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCFLAGS)
  60. CXXFLAGS = $(LANGXXFLAGS) $(WARNFLAGS) $(INCFLAGS) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCXXFLAGS)
  61. LDFLAGS = $(XLDFLAGS)
  62. ASFLAGS = $(ARCHFLAGS) $(XASFLAGS)
  63. SAGE ?= sage
  64. SAGES= $(shell ls test/*.sage)
  65. BUILDPYS= $(SAGES:test/%.sage=$(BUILD_PY)/%.py)
  66. .PHONY: clean all test bench todo doc lib bat sage sagetest
  67. .PRECIOUS: $(BUILD_ASM)/%.s
  68. HEADERS= Makefile $(shell find src test -name "*.h") $(shell find . -name "*.hxx") $(BUILD_OBJ)/timestamp
  69. DECAFCOMPONENTS= $(BUILD_OBJ)/$(DECAF).o $(BUILD_OBJ)/shake.o $(BUILD_OBJ)/decaf_crypto.o \
  70. $(BUILD_OBJ)/$(FIELD).o $(BUILD_OBJ)/f_arithmetic.o $(BUILD_OBJ)/utils.o
  71. ifeq ($(DECAF),decaf_fast)
  72. DECAFCOMPONENTS += $(BUILD_OBJ)/decaf_tables.o
  73. endif
  74. BENCHCOMPONENTS = $(BUILD_OBJ)/bench.o $(BUILD_OBJ)/shake.o
  75. all: lib $(BUILD_IBIN)/test $(BUILD_IBIN)/bench $(BUILD_BIN)/shakesum
  76. scan: clean
  77. scan-build --use-analyzer=`which clang` \
  78. -enable-checker deadcode -enable-checker llvm \
  79. -enable-checker osx -enable-checker security -enable-checker unix \
  80. make all
  81. # The shakesum utility is in the public bin directory.
  82. $(BUILD_BIN)/shakesum: $(BUILD_OBJ)/shakesum.o $(BUILD_OBJ)/shake.o $(BUILD_OBJ)/utils.o
  83. $(LD) $(LDFLAGS) -o $@ $^
  84. # The main decaf library, and its symlinks.
  85. lib: $(BUILD_LIB)/libdecaf.so
  86. $(BUILD_LIB)/libdecaf.so: $(BUILD_LIB)/libdecaf.so.1
  87. ln -sf `basename $^` $@
  88. $(BUILD_LIB)/libdecaf.so.1: $(DECAFCOMPONENTS)
  89. rm -f $@
  90. ifeq ($(UNAME),Darwin)
  91. libtool -macosx_version_min 10.6 -dynamic -dead_strip -lc -x -o $@ \
  92. $(DECAFCOMPONENTS)
  93. else
  94. $(LD) $(LDFLAGS) -shared -Wl,-soname,`basename $@` -Wl,--gc-sections -o $@ $(DECAFCOMPONENTS)
  95. strip --discard-all $@
  96. endif
  97. # Internal test programs, which are not part of the final build/bin directory.
  98. $(BUILD_IBIN)/test: $(BUILD_OBJ)/test_decaf.o lib
  99. ifeq ($(UNAME),Darwin)
  100. $(LDXX) $(LDFLAGS) -o $@ $< -L$(BUILD_LIB) -ldecaf
  101. else
  102. $(LDXX) $(LDFLAGS) -Wl,-rpath,`pwd`/$(BUILD_LIB) -o $@ $< -L$(BUILD_LIB) -ldecaf
  103. endif
  104. $(BUILD_IBIN)/bench: $(BUILD_OBJ)/bench_decaf.o lib
  105. ifeq ($(UNAME),Darwin)
  106. $(LDXX) $(LDFLAGS) -o $@ $< -L$(BUILD_LIB) -ldecaf
  107. else
  108. $(LDXX) $(LDFLAGS) -Wl,-rpath,`pwd`/$(BUILD_LIB) -o $@ $< -L$(BUILD_LIB) -ldecaf
  109. endif
  110. # Create all the build subdirectories
  111. $(BUILD_OBJ)/timestamp:
  112. mkdir -p $(BUILD_ASM) $(BUILD_OBJ) $(BUILD_C) $(BUILD_PY) \
  113. $(BUILD_LIB) $(BUILD_INC) $(BUILD_BIN) $(BUILD_IBIN) $(BUILD_INC)/decaf
  114. touch $@
  115. $(BUILD_OBJ)/%.o: $(BUILD_ASM)/%.s
  116. $(ASM) $(ASFLAGS) -c -o $@ $<
  117. $(BUILD_IBIN)/decaf_gen_tables: $(BUILD_OBJ)/decaf_gen_tables.o \
  118. $(BUILD_OBJ)/$(DECAF).o $(BUILD_OBJ)/$(FIELD).o $(BUILD_OBJ)/f_arithmetic.o $(BUILD_OBJ)/utils.o
  119. $(LD) $(LDFLAGS) -o $@ $^
  120. $(BUILD_C)/decaf_tables.c: $(BUILD_IBIN)/decaf_gen_tables
  121. ./$< > $@
  122. $(BUILD_ASM)/decaf_tables.s: $(BUILD_C)/decaf_tables.c $(HEADERS)
  123. $(CC) $(CFLAGS) -S -c -o $@ $<
  124. $(BUILD_ASM)/%.s: src/%.c $(HEADERS)
  125. $(CC) $(CFLAGS) -S -c -o $@ $<
  126. $(BUILD_ASM)/%.s: src/%.cxx $(HEADERS)
  127. $(CXX) $(CXXFLAGS) -S -c -o $@ $<
  128. $(BUILD_ASM)/%.s: test/%.c $(HEADERS)
  129. $(CC) $(CFLAGS) -S -c -o $@ $<
  130. $(BUILD_ASM)/%.s: test/%.cxx $(HEADERS)
  131. $(CXX) $(CXXFLAGS) -S -c -o $@ $<
  132. $(BUILD_ASM)/%.s: src/$(FIELD)/$(ARCH)/%.c $(HEADERS)
  133. $(CC) $(CFLAGS) -S -c -o $@ $<
  134. $(BUILD_ASM)/%.s: src/$(FIELD)/%.c $(HEADERS)
  135. $(CC) $(CFLAGS) -S -c -o $@ $<
  136. # The sage test scripts
  137. sage: $(BUILDPYS)
  138. sagetest: sage lib
  139. LD_LIBRARY_PATH=$(BUILD_LIB) sage $(BUILD_PY)/test_decaf.sage
  140. $(BUILDPYS): $(SAGES) $(BUILD_OBJ)/timestamp
  141. cp -f $(SAGES) $(BUILD_PY)/
  142. $(SAGE) --preparse $(SAGES:test/%.sage=$(BUILD_PY)/%.sage)
  143. # some sage versions compile to .sage.py
  144. for f in $(SAGES:test/%.sage=$(BUILD_PY)/%); do \
  145. if [ -e $$f.sage.py ]; then \
  146. mv $$f.sage.py $$f.py; \
  147. fi; \
  148. done
  149. # The documentation files
  150. $(BUILD_DOC)/timestamp:
  151. mkdir -p `dirname $@`
  152. touch $@
  153. doc: Doxyfile $(BUILD_OBJ)/timestamp $(HEADERS) src/*.c src/$(FIELD)/$(ARCH)/*.c src/$(FIELD)/$(ARCH)/*.h
  154. doxygen > /dev/null
  155. # The eBATS benchmarking script
  156. bat: $(BATNAME)
  157. $(BATNAME): include/* src/* src/*/* test/batarch.map $(BUILD_C)/decaf_tables.c # TODO tables some other way
  158. rm -fr $@
  159. for prim in dh sign; do \
  160. targ="$@/crypto_$$prim/ed448goldilocks_decaf"; \
  161. (while read arch where; do \
  162. mkdir -p $$targ/`basename $$arch`; \
  163. cp include/*.h $(BUILD_C)/decaf_tables.c src/decaf_fast.c src/decaf_crypto.c src/shake.c src/include/*.h src/bat/$$prim.c src/p448/$$where/*.c src/p448/$$where/*.h src/p448/*.c src/p448/*.h $$targ/`basename $$arch`; \
  164. cp src/bat/api_$$prim.h $$targ/`basename $$arch`/api.h; \
  165. perl -p -i -e 's/SYSNAME/'`basename $(BATNAME)`_`basename $$arch`'/g' $$targ/`basename $$arch`/api.h; \
  166. perl -p -i -e 's/__TODAY__/'$(TODAY)'/g' $$targ/`basename $$arch`/api.h; \
  167. done \
  168. ) < test/batarch.map; \
  169. echo 'Mike Hamburg' > $$targ/designers; \
  170. echo 'Ed448-Goldilocks Decaf sign and dh' > $$targ/description; \
  171. done
  172. (cd $(BATNAME)/.. && tar czf $(BATBASE).tgz $(BATBASE) )
  173. # Finds todo items in .h and .c files
  174. TODO_TYPES ?= HACK TODO FIXME BUG XXX PERF FUTURE REMOVE MAGIC
  175. todo::
  176. @(find * -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep --color=auto -w \
  177. `echo $(TODO_TYPES) | tr ' ' '|'`
  178. @echo '============================='
  179. @(for i in $(TODO_TYPES); do \
  180. (find * -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep -w $$i > /dev/null || continue; \
  181. /bin/echo -n $$i' ' | head -c 10; \
  182. (find * -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep -w $$i| wc -l; \
  183. done)
  184. @echo '============================='
  185. @echo -n 'Total '
  186. @(find * -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep -w \
  187. `echo $(TODO_TYPES) | tr ' ' '|'` | wc -l
  188. bench: $(BUILD_IBIN)/bench
  189. ./$<
  190. test: $(BUILD_IBIN)/test
  191. ./$<
  192. microbench: $(BUILD_IBIN)/bench
  193. ./$< --micro
  194. clean:
  195. rm -fr build $(BATNAME)