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.
 
 
 
 
 

197 lines
5.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. ifeq ($(UNAME),Darwin)
  6. CC = clang
  7. CXX = clang++
  8. else
  9. CC = gcc
  10. CXX = g++
  11. endif
  12. LD = $(CC)
  13. LDXX = $(CXX)
  14. ASM ?= $(CC)
  15. DECAF ?= decaf
  16. ifneq (,$(findstring x86_64,$(MACHINE)))
  17. ARCH ?= arch_x86_64
  18. else
  19. # no i386 port yet
  20. ARCH ?= arch_arm_32
  21. endif
  22. FIELD ?= p448
  23. WARNFLAGS = -pedantic -Wall -Wextra -Werror -Wunreachable-code \
  24. -Wmissing-declarations -Wunused-function $(EXWARN)
  25. INCFLAGS = -Isrc/include -Iinclude -Isrc/$(FIELD) -Isrc/$(FIELD)/$(ARCH)
  26. LANGFLAGS = -std=c99 -fno-strict-aliasing
  27. LANGXXFLAGS = -fno-strict-aliasing
  28. GENFLAGS = -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC
  29. OFLAGS = -O3
  30. TODAY = $(shell date "+%Y-%m-%d")
  31. ifneq (,$(findstring arm,$(MACHINE)))
  32. ifneq (,$(findstring neon,$(ARCH)))
  33. ARCHFLAGS += -mfpu=neon
  34. else
  35. ARCHFLAGS += -mfpu=vfpv3-d16
  36. endif
  37. ARCHFLAGS += -mcpu=cortex-a8 # FIXME
  38. GENFLAGS += -DN_TESTS_BASE=1000 # sooooo sloooooow
  39. else
  40. ARCHFLAGS += -maes -mavx2 -mbmi2 #TODO
  41. endif
  42. ifeq ($(CC),clang)
  43. WARNFLAGS += -Wgcc-compat
  44. endif
  45. ARCHFLAGS += $(XARCHFLAGS)
  46. CFLAGS = $(LANGFLAGS) $(WARNFLAGS) $(INCFLAGS) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCFLAGS)
  47. CXXFLAGS = $(LANGXXFLAGS) $(WARNFLAGS) $(INCFLAGS) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCXXFLAGS)
  48. LDFLAGS = $(ARCHFLAGS) $(XLDFLAGS)
  49. ASFLAGS = $(ARCHFLAGS) $(XASFLAGS)
  50. .PHONY: clean all test bench todo doc lib bat
  51. .PRECIOUS: build/%.s
  52. HEADERS= Makefile $(shell find . -name "*.h") $(shell find . -name "*.hxx") build/timestamp
  53. DECAFCOMPONENTS= build/$(DECAF).o build/shake.o build/decaf_crypto.o \
  54. build/$(FIELD).o build/f_arithmetic.o # TODO
  55. ifeq ($(DECAF),decaf_fast)
  56. DECAFCOMPONENTS += build/decaf_tables.o
  57. endif
  58. BENCHCOMPONENTS = build/bench.o build/shake.o
  59. BATBASE=ed448goldilocks-decaf-bats-$(TODAY)
  60. BATNAME=build/$(BATBASE)
  61. all: lib build/test build/bench build/shakesum
  62. scan: clean
  63. scan-build --use-analyzer=`which clang` \
  64. -enable-checker deadcode -enable-checker llvm \
  65. -enable-checker osx -enable-checker security -enable-checker unix \
  66. make build/bench build/test all
  67. build/test: build/test_decaf.o lib
  68. $(LDXX) $(LDFLAGS) -o $@ $< -Lbuild -ldecaf
  69. build/bench: build/bench_decaf.o lib
  70. $(LDXX) $(LDFLAGS) -o $@ $< -Lbuild -ldecaf
  71. build/shakesum: build/shakesum.o build/shake.o
  72. $(LD) $(LDFLAGS) -o $@ $^
  73. lib: build/libdecaf.so
  74. build/libdecaf.so: $(DECAFCOMPONENTS)
  75. rm -f $@
  76. ifeq ($(UNAME),Darwin)
  77. libtool -macosx_version_min 10.6 -dynamic -dead_strip -lc -x -o $@ \
  78. $(DECAFCOMPONENTS)
  79. else
  80. $(LD) $(LDFLAGS) -shared -Wl,-soname,libdecaf.so.1 -Wl,--gc-sections -o $@ $(DECAFCOMPONENTS)
  81. strip --discard-all $@
  82. ln -sf `basename $@` build/libdecaf.so.1
  83. endif
  84. build/timestamp:
  85. mkdir -p build
  86. touch $@
  87. build/%.o: build/%.s
  88. $(ASM) $(ASFLAGS) -c -o $@ $<
  89. build/decaf_gen_tables: build/decaf_gen_tables.o build/$(DECAF).o build/$(FIELD).o build/f_arithmetic.o
  90. $(LD) $(LDFLAGS) -o $@ $^
  91. build/decaf_tables.c: build/decaf_gen_tables
  92. ./$< > $@
  93. build/decaf_tables.s: build/decaf_tables.c $(HEADERS)
  94. $(CC) $(CFLAGS) -S -c -o $@ $<
  95. build/%.s: src/%.c $(HEADERS)
  96. $(CC) $(CFLAGS) -S -c -o $@ $<
  97. build/%.s: src/%.cxx $(HEADERS)
  98. $(CXX) $(CXXFLAGS) -S -c -o $@ $<
  99. build/%.s: test/%.c $(HEADERS)
  100. $(CC) $(CFLAGS) -S -c -o $@ $<
  101. build/%.s: test/%.cxx $(HEADERS)
  102. $(CXX) $(CXXFLAGS) -S -c -o $@ $<
  103. build/%.s: src/$(FIELD)/$(ARCH)/%.c $(HEADERS)
  104. $(CC) $(CFLAGS) -S -c -o $@ $<
  105. build/%.s: src/$(FIELD)/%.c $(HEADERS)
  106. $(CC) $(CFLAGS) -S -c -o $@ $<
  107. doc/timestamp:
  108. mkdir -p doc
  109. touch $@
  110. doc: Doxyfile doc/timestamp include/*.h src/*.c src/include/*.h src/$(FIELD)/$(ARCH)/*.c src/$(FIELD)/$(ARCH)/*.h
  111. doxygen > /dev/null
  112. bat: $(BATNAME)
  113. $(BATNAME): include/* src/* src/*/* test/batarch.map
  114. rm -fr $@
  115. for prim in dh sign; do \
  116. targ="$@/crypto_$$prim/ed448goldilocks-decaf"; \
  117. (while read arch where; do \
  118. mkdir -p $$targ/`basename $$arch`; \
  119. cp include/*.h src/*.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`; \
  120. cp src/bat/api_$$prim.h $$targ/`basename $$arch`/api.h; \
  121. perl -p -i -e 's/SYSNAME/'`basename $(BATNAME)`_`basename $$arch`'/g' $$targ/`basename $$arch`/api.h; \
  122. perl -p -i -e 's/__TODAY__/'$(TODAY)'/g' $$targ/`basename $$arch`/api.h; \
  123. done \
  124. ) < test/batarch.map; \
  125. echo 'Mike Hamburg' > $$targ/designers; \
  126. echo 'Ed448-Goldilocks Decaf sign and dh' > $$targ/description; \
  127. done
  128. (cd build && tar czf $(BATBASE).tgz $(BATBASE) )
  129. todo::
  130. @(find * -name '*.h'; find * -name '*.c') | xargs egrep --color=auto -w \
  131. 'HACK|TODO|FIXME|BUG|XXX|PERF|FUTURE|REMOVE|MAGIC'
  132. @echo '============================='
  133. @(for i in FIXME BUG XXX TODO HACK PERF FUTURE REMOVE MAGIC; do \
  134. (find * -name '*.h'; find * -name '*.c') | xargs egrep -w $$i > /dev/null || continue; \
  135. /bin/echo -n $$i' ' | head -c 10; \
  136. (find * -name '*.h'; find * -name '*.c') | xargs egrep -w $$i| wc -l; \
  137. done)
  138. @echo '============================='
  139. @echo -n 'Total '
  140. @(find * -name '*.h'; find * -name '*.c') | xargs egrep -w \
  141. 'HACK|TODO|FIXME|BUG|XXX|PERF|FUTURE|REMOVE|MAGIC' | wc -l
  142. bench: build/bench
  143. ./$<
  144. test: build/test
  145. build/test
  146. microbench: build/bench
  147. ./$< --micro
  148. clean:
  149. rm -fr build doc $(BATNAME)