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.
 
 
 
 
 

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