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.
 
 
 
 
 

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