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.
 
 
 
 
 

196 lines
5.6 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
  56. TESTCOMPONENTS=build/test.o build/test_scalarmul.o build/test_sha512.o \
  57. build/test_pointops.o build/test_arithmetic.o build/test_goldilocks.o build/magic.o \
  58. build/shake.o
  59. BENCHCOMPONENTS = build/bench.o build/shake.o
  60. BATBASE=ed448goldilocks-bats-$(TODAY)
  61. BATNAME=build/$(BATBASE)
  62. all: lib decaf_lib build/test build/bench build/shakesum
  63. scan: clean
  64. scan-build --use-analyzer=`which clang` \
  65. -enable-checker deadcode -enable-checker llvm \
  66. -enable-checker osx -enable-checker security -enable-checker unix \
  67. make build/bench build/test build/goldilocks.so
  68. build/bench: $(LIBCOMPONENTS) $(BENCHCOMPONENTS) $(DECAFCOMPONENTS)
  69. $(LD) $(LDFLAGS) -o $@ $^
  70. build/test: $(LIBCOMPONENTS) $(TESTCOMPONENTS) $(DECAFCOMPONENTS)
  71. $(LD) $(LDFLAGS) -o $@ $^ -lgmp
  72. build/shakesum: build/shakesum.o build/shake.o
  73. $(LD) $(LDFLAGS) -o $@ $^
  74. lib: build/goldilocks.so
  75. decaf_lib: build/decaf.so
  76. build/goldilocks.so: $(LIBCOMPONENTS)
  77. rm -f $@
  78. ifeq ($(UNAME),Darwin)
  79. libtool -macosx_version_min 10.6 -dynamic -dead_strip -lc -x -o $@ \
  80. $(LIBCOMPONENTS)
  81. else
  82. $(LD) $(LDFLAGS) -shared -Wl,-soname,goldilocks.so.1 -Wl,--gc-sections -o $@ $(LIBCOMPONENTS)
  83. strip --discard-all $@
  84. ln -sf `basename $@` build/goldilocks.so.1
  85. endif
  86. build/decaf.so: $(DECAFCOMPONENTS)
  87. rm -f $@
  88. ifeq ($(UNAME),Darwin)
  89. libtool -macosx_version_min 10.6 -dynamic -dead_strip -lc -x -o $@ \
  90. $(DECAFCOMPONENTS)
  91. else
  92. $(LD) $(LDFLAGS) -shared -Wl,-soname,goldilocks.so.1 -Wl,--gc-sections -o $@ $(DECAFCOMPONENTS)
  93. strip --discard-all $@
  94. ln -sf `basename $@` build/goldilocks.so.1
  95. endif
  96. build/timestamp:
  97. mkdir -p build
  98. touch $@
  99. build/%.o: build/%.s
  100. $(ASM) $(ASFLAGS) -c -o $@ $<
  101. build/%.s: src/%.c $(HEADERS)
  102. $(CC) $(CFLAGS) -S -c -o $@ $<
  103. build/%.s: test/%.c $(HEADERS)
  104. $(CC) $(CFLAGS) -S -c -o $@ $<
  105. build/%.s: src/$(FIELD)/$(ARCH)/%.c $(HEADERS)
  106. $(CC) $(CFLAGS) -S -c -o $@ $<
  107. build/%.s: src/$(FIELD)/%.c $(HEADERS)
  108. $(CC) $(CFLAGS) -S -c -o $@ $<
  109. doc/timestamp:
  110. mkdir -p doc
  111. touch $@
  112. doc: Doxyfile doc/timestamp include/*.h src/*.c src/include/*.h src/$(FIELD)/$(ARCH)/*.c src/$(FIELD)/$(ARCH)/*.h
  113. doxygen
  114. bat: $(BATNAME)
  115. $(BATNAME): include/* src/* src/*/* test/batarch.map
  116. rm -fr $@
  117. for prim in dh sign; do \
  118. targ="$@/crypto_$$prim/ed448goldilocks"; \
  119. (while read arch where; do \
  120. mkdir -p $$targ/`basename $$arch`; \
  121. 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`; \
  122. cp src/bat/api_$$prim.h $$targ/`basename $$arch`/api.h; \
  123. perl -p -i -e 's/.*endif.*GOLDILOCKS_CONFIG_H/#define SUPERCOP_WONT_LET_ME_OPEN_FILES 1\n\n$$&/' $$targ/`basename $$arch`/config.h; \
  124. perl -p -i -e 's/SYSNAME/'`basename $(BATNAME)`_`basename $$arch`'/g' $$targ/`basename $$arch`/api.h; \
  125. perl -p -i -e 's/__TODAY__/'$(TODAY)'/g' $$targ/`basename $$arch`/api.h; \
  126. done \
  127. ) < test/batarch.map; \
  128. echo 'Mike Hamburg' > $$targ/designers; \
  129. echo 'Ed448-Goldilocks sign and dh' > $$targ/description; \
  130. done
  131. (cd build && tar czf $(BATBASE).tgz $(BATBASE) )
  132. todo::
  133. @(find * -name '*.h'; find * -name '*.c') | xargs egrep --color=auto -w \
  134. 'HACK|TODO|FIXME|BUG|XXX|PERF|FUTURE|REMOVE|MAGIC'
  135. @echo '============================='
  136. @(for i in FIXME BUG XXX TODO HACK PERF FUTURE REMOVE MAGIC; do \
  137. (find * -name '*.h'; find * -name '*.c') | xargs egrep -w $$i > /dev/null || continue; \
  138. /bin/echo -n $$i' ' | head -c 10; \
  139. (find * -name '*.h'; find * -name '*.c') | xargs egrep -w $$i| wc -l; \
  140. done)
  141. @echo '============================='
  142. @echo -n 'Total '
  143. @(find * -name '*.h'; find * -name '*.c') | xargs egrep -w \
  144. 'HACK|TODO|FIXME|BUG|XXX|PERF|FUTURE|REMOVE|MAGIC' | wc -l
  145. bench: build/bench
  146. ./$<
  147. test: build/test
  148. ./$<
  149. clean:
  150. rm -fr build doc $(BATNAME)