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.
 
 
 
 
 

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