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.
 
 
 
 
 

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