Makefile 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. # CLANG_VERSION is empty if the compiler is not clang-based
  2. CLANG_VERSION = $(shell $(CC) --version | sed -nr 's/^.*clang version ([0-9.]+).*$$/\1/p')
  3. CLANG_VERSION_MAJOR = $(shell echo $(CLANG_VERSION) | cut -f1 -d.)
  4. # determine specific version ranges
  5. ifneq ($(CLANG_VERSION),)
  6. $(if $(shell [ $(CLANG_VERSION_MAJOR) -ge 13 ] && echo "OK"), \
  7. $(eval CLANG_AT_LEAST_13 := true), \
  8. $(eval CLANG_AT_LEAST_13 := false))
  9. endif
  10. ifeq ($(FUZZER),1)
  11. CC ?= clang
  12. LD ?= $(CC)
  13. SANFLAGS += -fsanitize=fuzzer
  14. # only clang versions >= 13 support this feature
  15. ifeq ($(CLANG_AT_LEAST_13),true)
  16. $(info "info: using -fsanitize-ignorelist")
  17. SANFLAGS += -fsanitize-ignorelist=fuzzer/sanitizer_ignorelist.txt
  18. else
  19. $(info "info: not using -fsanitize-ignorelist")
  20. endif
  21. # TODO is there a better solution, for example by disabling a specific optimization technique?
  22. # there is a clang optimization issue in relation with the blake2 code at -fsanitize=undefined
  23. $(warning "warning: disabling optimization on blake2 code as workaround")
  24. blake2b.o: OPTFLAGS += -O0
  25. blake2s.o: OPTFLAGS += -O0
  26. else ifeq ($(ADDRESS_SANITIZER),1)
  27. SANFLAGS += -fsanitize=address,undefined
  28. endif
  29. CC ?= cc
  30. OPTFLAGS ?= -O3 -g
  31. CFLAGS += $(OPTFLAGS) \
  32. $(SANFLAGS) \
  33. -std=gnu99 \
  34. -W \
  35. -Wall \
  36. -Wextra \
  37. -Wimplicit-function-declaration \
  38. -Wredundant-decls \
  39. -Wstrict-prototypes \
  40. -Wundef \
  41. -Wshadow \
  42. -Wpointer-arith \
  43. -Wformat \
  44. -Wreturn-type \
  45. -Wsign-compare \
  46. -Wmultichar \
  47. -Wformat-nonliteral \
  48. -Winit-self \
  49. -Wuninitialized \
  50. -Wformat-security \
  51. -Wno-missing-braces \
  52. -Werror
  53. ZKP_CFLAGS = \
  54. -DECMULT_GEN_PREC_BITS=4 \
  55. -DECMULT_WINDOW_SIZE=8 \
  56. -DENABLE_MODULE_GENERATOR \
  57. -DENABLE_MODULE_RECOVERY \
  58. -DENABLE_MODULE_SCHNORRSIG \
  59. -DENABLE_MODULE_EXTRAKEYS
  60. ZKP_PATH = ../vendor/secp256k1-zkp
  61. # this is specific for 64-bit builds
  62. CFLAGS += -DSECP256K1_CONTEXT_SIZE=208
  63. VALGRIND ?= 1
  64. ifeq ($(VALGRIND),1)
  65. CFLAGS += -DVALGRIND
  66. endif
  67. CFLAGS += -I.
  68. CFLAGS += -I..
  69. CFLAGS += -DUSE_ETHEREUM=1
  70. CFLAGS += -DUSE_KECCAK=1
  71. CFLAGS += -DUSE_MONERO=1
  72. CFLAGS += -DUSE_NEM=1
  73. CFLAGS += -DUSE_CARDANO=1
  74. CFLAGS += $(shell pkg-config --cflags openssl)
  75. # disable certain optimizations and features when small footprint is required
  76. ifdef SMALL
  77. CFLAGS += -DUSE_PRECOMPUTED_CP=0
  78. endif
  79. SRCS = bignum.c ecdsa.c curves.c secp256k1.c nist256p1.c rand.c hmac.c bip32.c bip39.c bip39_english.c pbkdf2.c base58.c base32.c
  80. SRCS += address.c
  81. SRCS += script.c
  82. SRCS += ripemd160.c
  83. SRCS += sha2.c
  84. SRCS += sha3.c
  85. SRCS += hasher.c
  86. SRCS += aes/aescrypt.c aes/aeskey.c aes/aestab.c aes/aes_modes.c
  87. SRCS += ed25519_donna/curve25519_donna_32bit.c ed25519_donna/curve25519_donna_helpers.c ed25519_donna/modm_donna_32bit.c
  88. SRCS += ed25519_donna/ed25519_donna_basepoint_table.c ed25519_donna/ed25519_donna_32bit_tables.c ed25519_donna/ed25519_donna_impl_base.c
  89. SRCS += ed25519_donna/ed25519.c ed25519_donna/curve25519_donna_scalarmult_base.c ed25519_donna/ed25519_sha3.c ed25519_donna/ed25519_keccak.c
  90. SRCS += monero/base58.c
  91. SRCS += monero/serialize.c
  92. SRCS += monero/xmr.c
  93. SRCS += blake256.c
  94. SRCS += blake2b.c blake2s.c
  95. SRCS += chacha_drbg.c
  96. SRCS += groestl.c
  97. SRCS += chacha20poly1305/chacha20poly1305.c chacha20poly1305/chacha_merged.c chacha20poly1305/poly1305_donna.c chacha20poly1305/rfc7539.c
  98. SRCS += rc4.c
  99. SRCS += nem.c
  100. SRCS += segwit_addr.c cash_addr.c
  101. SRCS += memzero.c
  102. SRCS += shamir.c
  103. SRCS += hmac_drbg.c
  104. SRCS += rfc6979.c
  105. SRCS += slip39.c
  106. SRCS += zkp_context.c
  107. SRCS += zkp_ecdsa.c
  108. SRCS += zkp_bip340.c
  109. SRCS += cardano.c
  110. OBJS = $(SRCS:.c=.o)
  111. OBJS += secp256k1-zkp.o
  112. OBJS += precomputed_ecmult.o
  113. OBJS += precomputed_ecmult_gen.o
  114. TESTLIBS = $(shell pkg-config --libs check) -lpthread -lm
  115. TESTSSLLIBS = $(shell pkg-config --libs openssl)
  116. all: tools tests
  117. %.o: %.c %.h options.h
  118. $(CC) $(CFLAGS) -o $@ -c $<
  119. tests: tests/test_check tests/test_openssl tests/test_speed tests/libtrezor-crypto.so tests/aestst
  120. tests/aestst: aes/aestst.o aes/aescrypt.o aes/aeskey.o aes/aestab.o
  121. $(CC) $(CFLAGS) $^ -o $@
  122. tests/test_check.o: tests/test_check_cardano.h tests/test_check_monero.h tests/test_check_cashaddr.h tests/test_check_segwit.h
  123. tests/test_check: tests/test_check.o $(OBJS)
  124. $(CC) $(CFLAGS) tests/test_check.o $(OBJS) $(TESTLIBS) -o tests/test_check
  125. tests/test_speed: tests/test_speed.o $(OBJS)
  126. $(CC) $(CFLAGS) tests/test_speed.o $(OBJS) -o tests/test_speed
  127. tests/test_openssl: tests/test_openssl.o $(OBJS)
  128. $(CC) $(CFLAGS) tests/test_openssl.o $(OBJS) $(TESTSSLLIBS) -o tests/test_openssl
  129. tests/libtrezor-crypto.so: $(SRCS) secp256k1-zkp.o precomputed_ecmult.o precomputed_ecmult_gen.o
  130. $(CC) $(CFLAGS) -DAES_128 -DAES_192 -fPIC -shared $(SRCS) secp256k1-zkp.o precomputed_ecmult.o precomputed_ecmult_gen.o -o tests/libtrezor-crypto.so
  131. tools: tools/xpubaddrgen tools/mktable tools/bip39bruteforce
  132. tools/xpubaddrgen: tools/xpubaddrgen.o $(OBJS)
  133. $(CC) $(CFLAGS) tools/xpubaddrgen.o $(OBJS) -o tools/xpubaddrgen
  134. tools/mktable: tools/mktable.o $(OBJS)
  135. $(CC) $(CFLAGS) tools/mktable.o $(OBJS) -o tools/mktable
  136. tools/bip39bruteforce: tools/bip39bruteforce.o $(OBJS)
  137. $(CC) $(CFLAGS) tools/bip39bruteforce.o $(OBJS) -o tools/bip39bruteforce
  138. fuzzer: fuzzer/fuzzer.o $(OBJS)
  139. $(CC) $(CFLAGS) fuzzer/fuzzer.o $(OBJS) -o fuzzer/fuzzer
  140. precomputed_ecmult.o:
  141. $(CC) $(CFLAGS) -Wno-unused-function $(ZKP_CFLAGS) -fPIC -c $(ZKP_PATH)/src/precomputed_ecmult.c -o precomputed_ecmult.o
  142. precomputed_ecmult_gen.o:
  143. $(CC) $(CFLAGS) -Wno-unused-function $(ZKP_CFLAGS) -fPIC -c $(ZKP_PATH)/src/precomputed_ecmult_gen.c -o precomputed_ecmult_gen.o
  144. secp256k1-zkp.o:
  145. $(CC) $(CFLAGS) -Wno-unused-function $(ZKP_CFLAGS) -fPIC -I$(ZKP_PATH) -I$(ZKP_PATH)/src -c $(ZKP_PATH)/src/secp256k1.c -o secp256k1-zkp.o
  146. clean:
  147. rm -f *.o aes/*.o chacha20poly1305/*.o ed25519_donna/*.o monero/*.o
  148. rm -f tests/*.o tests/test_check tests/test_speed tests/test_openssl tests/libtrezor-crypto.so tests/aestst
  149. rm -f tools/*.o tools/xpubaddrgen tools/mktable tools/bip39bruteforce
  150. rm -f fuzzer/*.o fuzzer/fuzzer
  151. rm -f secp256k1-zkp.o precomputed_ecmult.o precomputed_ecmult_gen.o
  152. clean-fuzzer: clean
  153. rm -f crash-* fuzz-*.log slow-unit-* timeout-*