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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. # This -Wall was supported by the European Commission through the ERC Starting Grant 805031 (EPOQUE)
  2. CFLAGS=-Wall -Wextra -Wpedantic -Werror -std=c99 -g $(EXTRAFLAGS)
  3. ALL_SCHEMES=$(filter-out crypto_%.c, $(wildcard crypto_*/*))
  4. COMMON_FILES = common/fips202.c common/sha2.c
  5. RANDOM_IMPL = common/randombytes.c
  6. default: help
  7. .PHONY: require_scheme
  8. require_scheme:
  9. # assumes a SCHEME variable; e.g. make functest SCHEME=crypto_kem/kyber768
  10. ifndef SCHEME
  11. $(error The SCHEME variable is not set. Example: SCHEME=crypto_kem/kyber768)
  12. endif
  13. bin/functest_$(subst /,_,$(SCHEME)): test/$(dir $(SCHEME))functest.c $(wildcard $(SCHEME)/clean/*.c) $(wildcard $(SCHEME)/clean/*.h) | require_scheme
  14. mkdir -p bin
  15. $(CC) $(CFLAGS) \
  16. -DPQCLEAN_NAMESPACE=$(shell echo PQCLEAN_$(subst -,,$(notdir $(SCHEME))) | tr a-z A-Z) \
  17. -iquote "./common/" \
  18. -iquote "$(SCHEME)/clean/" \
  19. -o bin/functest_$(subst /,_,$(SCHEME)) \
  20. $(SCHEME)/clean/*.c \
  21. $(COMMON_FILES) \
  22. $(RANDOM_IMPL) \
  23. $<
  24. .PHONY: functest
  25. functest: bin/functest_$(subst /,_,$(SCHEME))
  26. .PHONY: run-functest
  27. run-functest: bin/functest_$(subst /,_,$(SCHEME))
  28. ./$<
  29. .PHONY: run-valgrind
  30. run-valgrind: bin/functest_$(subst /,_,$(SCHEME))
  31. ifeq ($(shell uname -s),Linux)
  32. valgrind --leak-check=full --error-exitcode=1 $<
  33. else
  34. @echo "Valgrind not supported on this platform."
  35. endif
  36. bin/sanitizer_$(subst /,_,$(SCHEME)): test/$(dir $(SCHEME))functest.c $(wildcard $(SCHEME)/clean/*.c) $(wildcard $(SCHEME)/clean/*.h) | require_scheme
  37. mkdir -p bin
  38. $(CC) $(CFLAGS) -fsanitize=address \
  39. -DPQCLEAN_NAMESPACE=$(shell echo PQCLEAN_$(subst -,,$(notdir $(SCHEME))) | tr a-z A-Z) \
  40. -iquote "./common/" \
  41. -iquote "$(SCHEME)/clean/" \
  42. -o bin/sanitizer_$(subst /,_,$(SCHEME)) \
  43. $(COMMON_FILES) \
  44. $(RANDOM_IMPL) \
  45. $(SCHEME)/clean/*.c \
  46. $<
  47. .PHONY: sanitizer
  48. sanitizer: bin/sanitizer_$(subst /,_,$(SCHEME))
  49. bin/testvectors_$(subst /,_,$(SCHEME)): test/$(dir $(SCHEME))testvectors.c $(wildcard $(SCHEME)/clean/*.c) $(wildcard $(SCHEME)/clean/*.h) | require_scheme
  50. mkdir -p bin
  51. $(CC) $(CFLAGS) \
  52. -DPQCLEAN_NAMESPACE=$(shell echo PQCLEAN_$(subst -,,$(notdir $(SCHEME))) | tr a-z A-Z) \
  53. -iquote "./common/" \
  54. -iquote "$(SCHEME)/clean/" \
  55. -o bin/testvectors_$(subst /,_,$(SCHEME)) \
  56. $(COMMON_FILES) \
  57. common/notrandombytes.c \
  58. $(SCHEME)/clean/*.c \
  59. $<
  60. .PHONY: testvectors
  61. testvectors: bin/testvectors_$(subst /,_,$(SCHEME))
  62. bin/shared_$(subst /,_,$(SCHEME))_clean.so: $(wildcard $(SCHEME)/clean/*.c) | require_scheme
  63. mkdir -p bin
  64. $(CC) $(CFLAGS) \
  65. -DPQCLEAN_NAMESPACE=$(shell echo PQCLEAN_$(subst -,,$(notdir $(SCHEME))) | tr a-z A-Z) \
  66. -nostdlib \
  67. -shared \
  68. -fPIC \
  69. -iquote "./common/" \
  70. -iquote "$(SCHEME)/clean/" \
  71. -o $@ \
  72. $^
  73. .PHONY: clean
  74. clean:
  75. rm -rf bin
  76. .PHONY: format
  77. format:
  78. find . -iname *.h -o -iname *.c | xargs clang-format -i -style=file
  79. .PHONY: check-format
  80. check-format:
  81. @for src in $(SOURCES) ; do \
  82. var=`clang-format "$(SRC_DIR)/$$src" | diff "$(SRC_DIR)/$$src" - | wc -l` ; \
  83. if [ $$var -ne 0 ] ; then \
  84. echo "$$src does not respect the coding style (diff: $$var lines)" ; \
  85. exit 1 ; \
  86. fi ; \
  87. done
  88. @echo "Style check passed"
  89. .PHONY: tidy
  90. tidy:
  91. $(MAKE) do-tidy
  92. do-tidy: require_scheme
  93. clang-tidy \
  94. -quiet $(.TIDY_FIX) \
  95. $(SCHEME)/clean/*.c \
  96. common/*.c \
  97. -- -iquote "common/" -iquote "$(SCHEME)/clean"
  98. .PHONY: apply-tidy
  99. apply-tidy:
  100. $(MAKE) do-tidy .TIDY_FIX=-fix
  101. # The below should be outlined with ts=8
  102. .PHONY: help
  103. help:
  104. @echo "make test-all Run all tests"
  105. @echo "make functest SCHEME=scheme Build functional tests for SCHEME"
  106. @echo "make functest-all Build functional tests for all schemes"
  107. @echo "make run-functest SCHEME=scheme Run functional tests for SCHEME"
  108. @echo "make run-functest-all Run all functests"
  109. @echo "make run-testvectors SCHEME=scheme Run testvector checks for SCHEME"
  110. @echo "make run-testvectors-all Run all testvector checks"
  111. @echo "make run-sanitizer-all Run address sanitizer for all schemes"
  112. @echo "make run-symbol-namespace SCHEME=scheme Run symbol namespace checks for SCHEME"
  113. @echo "make run-symbol-namespace-all Run all symbol namespace checks"
  114. @echo "make run-valgrind SCHEME=scheme Run valgrind checks for SCHEME"
  115. @echo "make run-valgrind-all Run valgrind checks all schemes"
  116. @echo "make clean Clean up the bin/ folder"
  117. @echo "make format Automatically formats all the source code"
  118. @echo "make tidy SCHEME=scheme Runs the clang-tidy linter against SCHEME"
  119. @echo "make apply-tidy SCHEME=scheme Tries to automatically fix the issues found by clang-tidy in SCHEME"
  120. @echo "make tidy-all Runs the clang-tidy linter against all schemes"
  121. @echo "make apply-tidy-all Tidy up all schemes"
  122. @echo "make help Displays this message"
  123. .PHONY: functest-all
  124. functest-all:
  125. @for scheme in $(ALL_SCHEMES); do \
  126. $(MAKE) functest SCHEME=$$scheme || exit 1; \
  127. done
  128. .PHONY: sanitizer-all
  129. sanitizer-all:
  130. @for scheme in $(ALL_SCHEMES); do \
  131. $(MAKE) sanitizer SCHEME=$$scheme || exit 1; \
  132. done
  133. .PHONY: run-valgrind-all
  134. run-valgrind-all:
  135. @for scheme in $(ALL_SCHEMES); do \
  136. $(MAKE) run-valgrind SCHEME=$$scheme || exit 1; \
  137. done
  138. .PHONY: run-testvectors
  139. run-testvectors: test/check_testvectors.py | require_scheme
  140. python3 test/check_testvectors.py $(SCHEME) || exit 1; \
  141. .PHONY: run-symbol-namespace
  142. run-symbol-namespace: test/check_symbol_namespace.py | require_scheme
  143. python3 test/check_symbol_namespace.py $(SCHEME) || exit 1; \
  144. .PHONY: run-testvectors-all
  145. run-testvectors-all: test/check_testvectors.py
  146. @for scheme in $(ALL_SCHEMES); do \
  147. python3 test/check_testvectors.py $$scheme || exit 1; \
  148. done
  149. .PHONY: run-symbol-namespace-all
  150. run-symbol-namespace-all:
  151. @for scheme in $(ALL_SCHEMES); do \
  152. python3 test/check_symbol_namespace.py $$scheme || exit 1; \
  153. done
  154. .PHONY: run-functest-all
  155. run-functest-all: functest-all
  156. @for functest in $$(find bin/ -maxdepth 1 -name 'functest_*' -not -type d) ; do \
  157. echo ./$$functest ; \
  158. ./$$functest || exit 1 ;\
  159. done
  160. @echo Tests completed
  161. .PHONY: run-sanitizer-all
  162. run-sanitizer-all: sanitizer-all
  163. @for sanitizer in $$(find bin/ -maxdepth 1 -name 'sanitizer_*' -not -type d) ; do \
  164. echo ./$$sanitizer ; \
  165. ./$$sanitizer || exit 1 ;\
  166. done
  167. @echo Tests completed
  168. .PHONY: check-license-files
  169. check-license-files:
  170. @echo Checking that LICENSE files exist
  171. @for scheme in $(ALL_SCHEMES); do \
  172. echo Checking for $$scheme/clean/LICENSE;\
  173. test -f $$scheme/clean/LICENSE || exit 1 ;\
  174. done
  175. .PHONY: test-all
  176. test-all: run-functest-all run-valgrind-all run-sanitizer-all run-testvectors-all run-symbol-namespace-all
  177. .PHONY: tidy-all
  178. tidy-all:
  179. @for scheme in $(ALL_SCHEMES); do \
  180. $(MAKE) tidy SCHEME=$$scheme || exit 1 ; \
  181. done
  182. .PHONY: apply-tidy-all
  183. apply-tidy-all:
  184. @for scheme in $(ALL_SCHEMES); do \
  185. $(MAKE) apply-tidy SCHEME=$$scheme; \
  186. done
  187. .PHONY: check-metadata
  188. check-metadata:
  189. python3 test/check_metadata.py