No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

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