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.
 
 
 
 
 

269 lines
8.3 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
  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. # components needed by the table generators
  70. GENCOMPONENTS= \
  71. $(BUILD_OBJ)/$(DECAF)_ed25519.o $(BUILD_OBJ)/p25519_impl.o $(BUILD_OBJ)/p25519_arithmetic.o \
  72. $(BUILD_OBJ)/utils.o \
  73. #$(BUILD_OBJ)/p448_impl.o $(BUILD_OBJ)/p448_arithmetic.o
  74. # components needed by the lib
  75. DECAFCOMPONENTS= $(BUILD_OBJ)/shake.o $(BUILD_OBJ)/decaf_crypto.o $(GENCOMPONENTS)
  76. ifeq ($(DECAF),decaf_fast)
  77. DECAFCOMPONENTS += $(BUILD_OBJ)/decaf_tables_ed25519.o
  78. endif
  79. BENCHCOMPONENTS = $(BUILD_OBJ)/bench.o $(BUILD_OBJ)/shake.o
  80. all: lib $(BUILD_IBIN)/test $(BUILD_IBIN)/bench $(BUILD_BIN)/shakesum
  81. scan: clean
  82. scan-build --use-analyzer=`which clang` \
  83. -enable-checker deadcode -enable-checker llvm \
  84. -enable-checker osx -enable-checker security -enable-checker unix \
  85. make all
  86. # The shakesum utility is in the public bin directory.
  87. $(BUILD_BIN)/shakesum: $(BUILD_OBJ)/shakesum.o $(BUILD_OBJ)/shake.o $(BUILD_OBJ)/utils.o
  88. $(LD) $(LDFLAGS) -o $@ $^
  89. # The main decaf library, and its symlinks.
  90. lib: $(BUILD_LIB)/libdecaf.so
  91. $(BUILD_LIB)/libdecaf.so: $(BUILD_LIB)/libdecaf.so.1
  92. ln -sf `basename $^` $@
  93. $(BUILD_LIB)/libdecaf.so.1: $(DECAFCOMPONENTS)
  94. rm -f $@
  95. ifeq ($(UNAME),Darwin)
  96. libtool -macosx_version_min 10.6 -dynamic -dead_strip -lc -x -o $@ \
  97. $(DECAFCOMPONENTS)
  98. else
  99. $(LD) $(LDFLAGS) -shared -Wl,-soname,`basename $@` -Wl,--gc-sections -o $@ $(DECAFCOMPONENTS)
  100. strip --discard-all $@
  101. endif
  102. # Internal test programs, which are not part of the final build/bin directory.
  103. $(BUILD_IBIN)/test: $(BUILD_OBJ)/test_decaf.o lib
  104. ifeq ($(UNAME),Darwin)
  105. $(LDXX) $(LDFLAGS) -o $@ $< -L$(BUILD_LIB) -ldecaf
  106. else
  107. $(LDXX) $(LDFLAGS) -Wl,-rpath,`pwd`/$(BUILD_LIB) -o $@ $< -L$(BUILD_LIB) -ldecaf
  108. endif
  109. $(BUILD_IBIN)/bench: $(BUILD_OBJ)/bench_decaf.o lib
  110. ifeq ($(UNAME),Darwin)
  111. $(LDXX) $(LDFLAGS) -o $@ $< -L$(BUILD_LIB) -ldecaf
  112. else
  113. $(LDXX) $(LDFLAGS) -Wl,-rpath,`pwd`/$(BUILD_LIB) -o $@ $< -L$(BUILD_LIB) -ldecaf
  114. endif
  115. # Create all the build subdirectories
  116. $(BUILD_OBJ)/timestamp:
  117. mkdir -p $(BUILD_ASM) $(BUILD_OBJ) $(BUILD_C) $(BUILD_PY) \
  118. $(BUILD_LIB) $(BUILD_INC) $(BUILD_BIN) $(BUILD_IBIN) $(BUILD_INC)/decaf
  119. touch $@
  120. $(BUILD_OBJ)/%.o: $(BUILD_ASM)/%.s
  121. $(ASM) $(ASFLAGS) -c -o $@ $<
  122. # I don't know why this rule is necessary... bug in make, or obscure pattern matching rule?
  123. $(BUILD_OBJ)/decaf_gen_tables_%.o: $(BUILD_ASM)/decaf_gen_tables_%.s
  124. $(ASM) $(ASFLAGS) -c -o $@ $<
  125. $(BUILD_IBIN)/decaf_gen_tables_%: $(BUILD_OBJ)/decaf_gen_tables_%.o $(GENCOMPONENTS)
  126. $(LD) $(LDFLAGS) -o $@ $^
  127. $(BUILD_C)/decaf_tables_%.c: $(BUILD_IBIN)/decaf_gen_tables_%
  128. ./$< > $@
  129. $(BUILD_ASM)/decaf_tables_%.s: $(BUILD_C)/decaf_tables_%.c $(HEADERS)
  130. $(CC) $(CFLAGS) -S -c -o $@ $< \
  131. -I src/curve_$*/ -I src/curve_$*/field -I src/curve_$*/field/$(ARCH) \
  132. $(BUILD_ASM)/decaf_gen_tables_%.s: src/decaf_gen_tables.c $(HEADERS)
  133. $(CC) $(CFLAGS) \
  134. -I src/curve_$*/ -I src/curve_$*/field -I src/curve_$*/field/$(ARCH) \
  135. -S -c -o $@ $<
  136. $(BUILD_ASM)/decaf_fast_%.s: src/decaf_fast.c $(HEADERS)
  137. $(CC) $(CFLAGS) \
  138. -I src/curve_$*/ -I src/curve_$*/field -I src/curve_$*/field/$(ARCH) \
  139. -S -c -o $@ $<
  140. $(BUILD_ASM)/%_arithmetic.s: src/%/f_arithmetic.c $(HEADERS)
  141. $(CC) $(CFLAGS) \
  142. -I src/$* -I src/$*/$(ARCH) \
  143. -S -c -o $@ $<
  144. $(BUILD_ASM)/%_impl.s: src/%/$(ARCH)/f_impl.c $(HEADERS)
  145. $(CC) $(CFLAGS) \
  146. -I src/$* -I src/$*/$(ARCH) \
  147. -S -c -o $@ $<
  148. $(BUILD_ASM)/%.s: src/%.c $(HEADERS)
  149. $(CC) $(CFLAGS) -S -c -o $@ $<
  150. $(BUILD_ASM)/%.s: src/%.cxx $(HEADERS)
  151. $(CXX) $(CXXFLAGS) -S -c -o $@ $<
  152. $(BUILD_ASM)/%.s: test/%.c $(HEADERS)
  153. $(CC) $(CFLAGS) -S -c -o $@ $<
  154. $(BUILD_ASM)/%.s: test/%.cxx $(HEADERS)
  155. $(CXX) $(CXXFLAGS) -S -c -o $@ $<
  156. # The sage test scripts
  157. sage: $(BUILDPYS)
  158. sagetest: sage lib
  159. LD_LIBRARY_PATH=$(BUILD_LIB) sage $(BUILD_PY)/test_decaf.sage
  160. $(BUILDPYS): $(SAGES) $(BUILD_OBJ)/timestamp
  161. cp -f $(SAGES) $(BUILD_PY)/
  162. $(SAGE) --preparse $(SAGES:test/%.sage=$(BUILD_PY)/%.sage)
  163. # some sage versions compile to .sage.py
  164. for f in $(SAGES:test/%.sage=$(BUILD_PY)/%); do \
  165. if [ -e $$f.sage.py ]; then \
  166. mv $$f.sage.py $$f.py; \
  167. fi; \
  168. done
  169. # The documentation files
  170. $(BUILD_DOC)/timestamp:
  171. mkdir -p `dirname $@`
  172. touch $@
  173. #
  174. # doc: Doxyfile $(BUILD_OBJ)/timestamp $(HEADERS) src/*.c src/$(FIELD)/$(ARCH)/*.c src/$(FIELD)/$(ARCH)/*.h
  175. # doxygen > /dev/null
  176. # # The eBATS benchmarking script
  177. # bat: $(BATNAME)
  178. #
  179. # $(BATNAME): include/* src/* src/*/* test/batarch.map $(BUILD_C)/decaf_tables.c # TODO tables some other way
  180. # rm -fr $@
  181. # for prim in dh sign; do \
  182. # targ="$@/crypto_$$prim/ed448goldilocks_decaf"; \
  183. # (while read arch where; do \
  184. # mkdir -p $$targ/`basename $$arch`; \
  185. # 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`; \
  186. # cp src/bat/api_$$prim.h $$targ/`basename $$arch`/api.h; \
  187. # perl -p -i -e 's/SYSNAME/'`basename $(BATNAME)`_`basename $$arch`'/g' $$targ/`basename $$arch`/api.h; \
  188. # perl -p -i -e 's/__TODAY__/'$(TODAY)'/g' $$targ/`basename $$arch`/api.h; \
  189. # done \
  190. # ) < test/batarch.map; \
  191. # echo 'Mike Hamburg' > $$targ/designers; \
  192. # echo 'Ed448-Goldilocks Decaf sign and dh' > $$targ/description; \
  193. # done
  194. # (cd $(BATNAME)/.. && tar czf $(BATBASE).tgz $(BATBASE) )
  195. # Finds todo items in .h and .c files
  196. TODO_TYPES ?= HACK TODO FIXME BUG XXX PERF FUTURE REMOVE MAGIC
  197. todo::
  198. @(find * -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep --color=auto -w \
  199. `echo $(TODO_TYPES) | tr ' ' '|'`
  200. @echo '============================='
  201. @(for i in $(TODO_TYPES); do \
  202. (find * -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep -w $$i > /dev/null || continue; \
  203. /bin/echo -n $$i' ' | head -c 10; \
  204. (find * -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep -w $$i| wc -l; \
  205. done)
  206. @echo '============================='
  207. @echo -n 'Total '
  208. @(find * -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep -w \
  209. `echo $(TODO_TYPES) | tr ' ' '|'` | wc -l
  210. bench: $(BUILD_IBIN)/bench
  211. ./$<
  212. test: $(BUILD_IBIN)/test
  213. ./$<
  214. microbench: $(BUILD_IBIN)/bench
  215. ./$< --micro
  216. clean:
  217. rm -fr build $(BATNAME)