Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

281 lignes
8.9 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. WARNFLAGS = -pedantic -Wall -Wextra -Werror -Wunreachable-code \
  36. -Wmissing-declarations -Wunused-function -Wno-overlength-strings $(EXWARN)
  37. INCFLAGS = -Isrc/include -Isrc/public_include
  38. LANGFLAGS = -std=c99 -fno-strict-aliasing
  39. LANGXXFLAGS = -fno-strict-aliasing
  40. GENFLAGS = -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC
  41. OFLAGS ?= -O2
  42. MACOSX_VERSION_MIN ?= 10.9
  43. ifeq ($(UNAME),Darwin)
  44. GENFLAGS += -mmacosx-version-min=$(MACOSX_VERSION_MIN)
  45. endif
  46. TODAY = $(shell date "+%Y-%m-%d")
  47. ifneq (,$(findstring arm,$(MACHINE)))
  48. ifneq (,$(findstring neon,$(ARCH)))
  49. ARCHFLAGS += -mfpu=neon
  50. else
  51. ARCHFLAGS += -mfpu=vfpv3-d16
  52. endif
  53. ARCHFLAGS += -mcpu=cortex-a8 # FIXME
  54. GENFLAGS += -DN_TESTS_BASE=1000 # sooooo sloooooow
  55. else
  56. ARCHFLAGS += -maes -mavx2 -mbmi2 #TODO
  57. endif
  58. ifeq ($(CC),clang)
  59. WARNFLAGS += -Wgcc-compat
  60. endif
  61. ARCHFLAGS += $(XARCHFLAGS)
  62. CFLAGS = $(LANGFLAGS) $(WARNFLAGS) $(INCFLAGS) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCFLAGS)
  63. CXXFLAGS = $(LANGXXFLAGS) $(WARNFLAGS) $(INCFLAGS) $(OFLAGS) $(ARCHFLAGS) $(GENFLAGS) $(XCXXFLAGS)
  64. LDFLAGS = $(XLDFLAGS)
  65. ASFLAGS = $(ARCHFLAGS) $(XASFLAGS)
  66. SAGE ?= sage
  67. SAGES= $(shell ls test/*.sage)
  68. BUILDPYS= $(SAGES:test/%.sage=$(BUILD_PY)/%.py)
  69. .PHONY: clean all test bench todo doc lib bat sage sagetest
  70. .PRECIOUS: $(BUILD_ASM)/%.s $(BUILD_C)/%.c $(BUILD_IBIN)/%
  71. HEADERS= Makefile $(shell find src test -name "*.h") $(BUILD_OBJ)/timestamp
  72. HEADERSXX = $(HEADERS) $(shell find . -name "*.hxx")
  73. # components needed by the lib
  74. LIBCOMPONENTS = $(BUILD_OBJ)/utils.o $(BUILD_OBJ)/shake.o $(BUILD_OBJ)/decaf_crypto.o # and per-field components
  75. BENCHCOMPONENTS = $(BUILD_OBJ)/bench.o $(BUILD_OBJ)/shake.o
  76. all: lib $(BUILD_IBIN)/test $(BUILD_IBIN)/bench $(BUILD_BIN)/shakesum
  77. scan: clean
  78. scan-build --use-analyzer=`which clang` \
  79. -enable-checker deadcode -enable-checker llvm \
  80. -enable-checker osx -enable-checker security -enable-checker unix \
  81. make all
  82. # Internal test programs, which are not part of the final build/bin directory.
  83. $(BUILD_IBIN)/test: $(BUILD_OBJ)/test_decaf.o lib
  84. ifeq ($(UNAME),Darwin)
  85. $(LDXX) $(LDFLAGS) -o $@ $< -L$(BUILD_LIB) -ldecaf
  86. else
  87. $(LDXX) $(LDFLAGS) -Wl,-rpath,`pwd`/$(BUILD_LIB) -o $@ $< -L$(BUILD_LIB) -ldecaf
  88. endif
  89. $(BUILD_IBIN)/bench: $(BUILD_OBJ)/bench_decaf.o lib
  90. ifeq ($(UNAME),Darwin)
  91. $(LDXX) $(LDFLAGS) -o $@ $< -L$(BUILD_LIB) -ldecaf
  92. else
  93. $(LDXX) $(LDFLAGS) -Wl,-rpath,`pwd`/$(BUILD_LIB) -o $@ $< -L$(BUILD_LIB) -ldecaf
  94. endif
  95. # Create all the build subdirectories
  96. $(BUILD_OBJ)/timestamp:
  97. mkdir -p $(BUILD_ASM) $(BUILD_OBJ) $(BUILD_C) $(BUILD_PY) \
  98. $(BUILD_LIB) $(BUILD_INC) $(BUILD_BIN) $(BUILD_IBIN) $(BUILD_INC)/decaf
  99. touch $@
  100. $(BUILD_OBJ)/%.o: $(BUILD_ASM)/%.s
  101. $(ASM) $(ASFLAGS) -c -o $@ $<
  102. ################################################################
  103. # Per-field code: call with field, arch
  104. ################################################################
  105. define define_field
  106. ARCH_FOR_$(1) = $(2)
  107. COMPONENTS_OF_$(1) = $$(BUILD_OBJ)/$(1)_impl.o $$(BUILD_OBJ)/$(1)_arithmetic.o
  108. LIBCOMPONENTS += $$(COMPONENTS_OF_$(1))
  109. $$(BUILD_ASM)/$(1)_arithmetic.s: src/$(1)/f_arithmetic.c $$(HEADERS)
  110. $$(CC) $$(CFLAGS) -I src/$(1) -I src/$(1)/$(2) -S -c -o $$@ $$<
  111. $$(BUILD_ASM)/$(1)_impl.s: src/$(1)/$(2)/f_impl.c $$(HEADERS)
  112. $$(CC) $$(CFLAGS) -I src/$(1) -I src/$(1)/$(2) -S -c -o $$@ $$<
  113. endef
  114. ################################################################
  115. # Per-field, per-curve code: call with curve, field
  116. ################################################################
  117. define define_curve
  118. $$(BUILD_IBIN)/decaf_gen_tables_$(1): $$(BUILD_OBJ)/decaf_gen_tables_$(1).o $$(BUILD_OBJ)/decaf_fast_$(1).o $$(BUILD_OBJ)/utils.o \
  119. $$(COMPONENTS_OF_$(2))
  120. $$(LD) $$(LDFLAGS) -o $$@ $$^
  121. $$(BUILD_C)/decaf_tables_$(1).c: $$(BUILD_IBIN)/decaf_gen_tables_$(1)
  122. ./$$< > $$@ || (rm $$@; exit 1)
  123. $$(BUILD_ASM)/decaf_tables_$(1).s: $$(BUILD_C)/decaf_tables_$(1).c $$(HEADERS)
  124. $$(CC) $$(CFLAGS) -S -c -o $$@ $$< \
  125. -I src/curve_$(1)/ -I src/$(2) -I src/$(2)/$$(ARCH_FOR_$(2)) \
  126. $$(BUILD_ASM)/decaf_gen_tables_$(1).s: src/decaf_gen_tables.c $$(HEADERS)
  127. $$(CC) $$(CFLAGS) \
  128. -I src/curve_$(1)/ -I src/$(2) -I src/$(2)/$$(ARCH_FOR_$(2)) \
  129. -S -c -o $$@ $$<
  130. $$(BUILD_ASM)/decaf_fast_$(1).s: src/decaf_fast.c $$(HEADERS)
  131. $$(CC) $$(CFLAGS) \
  132. -I src/curve_$(1)/ -I src/$(2) -I src/$(2)/$$(ARCH_FOR_$(2)) \
  133. -S -c -o $$@ $$<
  134. LIBCOMPONENTS += $$(BUILD_OBJ)/decaf_fast_$(1).o $$(BUILD_OBJ)/decaf_tables_$(1).o
  135. endef
  136. ################################################################
  137. # call code above to generate curves and fields
  138. $(eval $(call define_field,p25519,arch_x86_64))
  139. $(eval $(call define_curve,ed25519,p25519))
  140. $(eval $(call define_field,p448,arch_x86_64))
  141. $(eval $(call define_curve,ed448goldilocks,p448))
  142. # The shakesum utility is in the public bin directory.
  143. $(BUILD_BIN)/shakesum: $(BUILD_OBJ)/shakesum.o $(BUILD_OBJ)/shake.o $(BUILD_OBJ)/utils.o
  144. $(LD) $(LDFLAGS) -o $@ $^
  145. # The main decaf library, and its symlinks.
  146. lib: $(BUILD_LIB)/libdecaf.so
  147. $(BUILD_LIB)/libdecaf.so: $(BUILD_LIB)/libdecaf.so.1
  148. ln -sf `basename $^` $@
  149. $(BUILD_LIB)/libdecaf.so.1: $(LIBCOMPONENTS)
  150. rm -f $@
  151. ifeq ($(UNAME),Darwin)
  152. libtool -macosx_version_min $(MACOSX_VERSION_MIN) -dynamic -dead_strip -lc -x -o $@ \
  153. $(LIBCOMPONENTS)
  154. else
  155. $(LD) $(LDFLAGS) -shared -Wl,-soname,`basename $@` -Wl,--gc-sections -o $@ $(LIBCOMPONENTS)
  156. strip --discard-all $@
  157. endif
  158. $(BUILD_ASM)/%.s: src/%.c $(HEADERS)
  159. $(CC) $(CFLAGS) -S -c -o $@ $<
  160. $(BUILD_ASM)/%.s: test/%.c $(HEADERS)
  161. $(CC) $(CFLAGS) -S -c -o $@ $<
  162. $(BUILD_ASM)/%.s: test/%.cxx $(HEADERSXX)
  163. $(CXX) $(CXXFLAGS) -S -c -o $@ $<
  164. # The sage test scripts
  165. sage: $(BUILDPYS)
  166. sagetest: sage lib
  167. $(SAGE) $(BUILD_PY)/test_decaf.sage
  168. $(BUILDPYS): $(SAGES) $(BUILD_OBJ)/timestamp
  169. cp -f $(SAGES) $(BUILD_PY)/
  170. $(SAGE) --preparse $(SAGES:test/%.sage=$(BUILD_PY)/%.sage)
  171. # some sage versions compile to .sage.py
  172. for f in $(SAGES:test/%.sage=$(BUILD_PY)/%); do \
  173. if [ -e $$f.sage.py ]; then \
  174. mv $$f.sage.py $$f.py; \
  175. fi; \
  176. done
  177. # The documentation files
  178. $(BUILD_DOC)/timestamp:
  179. mkdir -p `dirname $@`
  180. touch $@
  181. #
  182. # doc: Doxyfile $(BUILD_OBJ)/timestamp $(HEADERS) src/*.c src/$(FIELD)/$(ARCH)/*.c src/$(FIELD)/$(ARCH)/*.h
  183. # doxygen > /dev/null
  184. # # The eBATS benchmarking script
  185. # bat: $(BATNAME)
  186. #
  187. # $(BATNAME): include/* src/* src/*/* test/batarch.map $(BUILD_C)/decaf_tables.c # TODO tables some other way
  188. # rm -fr $@
  189. # for prim in dh sign; do \
  190. # targ="$@/crypto_$$prim/ed448goldilocks_decaf"; \
  191. # (while read arch where; do \
  192. # mkdir -p $$targ/`basename $$arch`; \
  193. # 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`; \
  194. # cp src/bat/api_$$prim.h $$targ/`basename $$arch`/api.h; \
  195. # perl -p -i -e 's/SYSNAME/'`basename $(BATNAME)`_`basename $$arch`'/g' $$targ/`basename $$arch`/api.h; \
  196. # perl -p -i -e 's/__TODAY__/'$(TODAY)'/g' $$targ/`basename $$arch`/api.h; \
  197. # done \
  198. # ) < test/batarch.map; \
  199. # echo 'Mike Hamburg' > $$targ/designers; \
  200. # echo 'Ed448-Goldilocks Decaf sign and dh' > $$targ/description; \
  201. # done
  202. # (cd $(BATNAME)/.. && tar czf $(BATBASE).tgz $(BATBASE) )
  203. # Finds todo items in .h and .c files
  204. TODO_TYPES ?= HACK TODO FIXME BUG XXX PERF FUTURE REMOVE MAGIC
  205. todo::
  206. @(find * -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep --color=auto -w \
  207. `echo $(TODO_TYPES) | tr ' ' '|'`
  208. @echo '============================='
  209. @(for i in $(TODO_TYPES); do \
  210. (find * -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep -w $$i > /dev/null || continue; \
  211. /bin/echo -n $$i' ' | head -c 10; \
  212. (find * -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep -w $$i| wc -l; \
  213. done)
  214. @echo '============================='
  215. @echo -n 'Total '
  216. @(find * -name '*.h' -or -name '*.c' -or -name '*.cxx' -or -name '*.hxx') | xargs egrep -w \
  217. `echo $(TODO_TYPES) | tr ' ' '|'` | wc -l
  218. bench: $(BUILD_IBIN)/bench
  219. ./$<
  220. test: $(BUILD_IBIN)/test
  221. ./$<
  222. microbench: $(BUILD_IBIN)/bench
  223. ./$< --micro
  224. clean:
  225. rm -fr build $(BATNAME)