From 6b81d24b5c3ed2722f2bdab2aa881c5e6d023f59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Vejpustek?= Date: Wed, 10 Apr 2024 15:11:12 +0200 Subject: [PATCH] chore(core): separate crypto sources in build scripts [no changelog] --- core/SConscript.boardloader | 8 ++++++-- core/SConscript.bootloader | 8 ++++++-- core/SConscript.bootloader_ci | 10 +++++++--- core/SConscript.bootloader_emu | 6 ++++-- core/SConscript.firmware | 12 ++++++++---- core/SConscript.prodtest | 8 ++++++-- core/SConscript.reflash | 6 ++++-- core/SConscript.unix | 12 ++++++++---- 8 files changed, 49 insertions(+), 21 deletions(-) diff --git a/core/SConscript.boardloader b/core/SConscript.boardloader index 03a7b731b1..4cf682d849 100644 --- a/core/SConscript.boardloader +++ b/core/SConscript.boardloader @@ -24,6 +24,7 @@ CCFLAGS_MOD = '' CPPPATH_MOD = [] CPPDEFINES_MOD = ["BOARDLOADER"] SOURCE_MOD = [] +SOURCE_MOD_CRYPTO = [] CPPDEFINES_HAL = [] SOURCE_HAL = [] PATH_HAL = [] @@ -41,6 +42,9 @@ CPPDEFINES_MOD += [ 'ED25519_NO_PRECOMP', ] SOURCE_MOD += [ + 'vendor/trezor-storage/flash_area.c', +] +SOURCE_MOD_CRYPTO += [ 'vendor/trezor-crypto/blake2s.c', 'vendor/trezor-crypto/ed25519-donna/curve25519-donna-32bit.c', 'vendor/trezor-crypto/ed25519-donna/curve25519-donna-helpers.c', @@ -50,7 +54,6 @@ SOURCE_MOD += [ 'vendor/trezor-crypto/ed25519-donna/modm-donna-32bit.c', 'vendor/trezor-crypto/memzero.c', 'vendor/trezor-crypto/sha2.c', - 'vendor/trezor-storage/flash_area.c', ] # modtrezorui @@ -130,7 +133,7 @@ env.Replace( ) env.Replace( - ALLSOURCES=SOURCE_MOD + SOURCE_BOARDLOADER + SOURCE_HAL, + ALLSOURCES=SOURCE_MOD + SOURCE_MOD_CRYPTO + SOURCE_BOARDLOADER + SOURCE_HAL, ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT'])) cmake_gen = env.Command( @@ -145,6 +148,7 @@ cmake_gen = env.Command( obj_program = [] obj_program += env.Object(source=SOURCE_MOD) +obj_program += env.Object(source=SOURCE_MOD_CRYPTO) obj_program += env.Object(source=SOURCE_BOARDLOADER) obj_program += env.Object(source=SOURCE_HAL) diff --git a/core/SConscript.bootloader b/core/SConscript.bootloader index 3a5ec2afe8..12baa0b6f6 100644 --- a/core/SConscript.bootloader +++ b/core/SConscript.bootloader @@ -26,6 +26,7 @@ CCFLAGS_MOD = '' CPPPATH_MOD = [] CPPDEFINES_MOD = [] SOURCE_MOD = [] +SOURCE_MOD_CRYPTO = [] CPPDEFINES_HAL = [] SOURCE_HAL = [] PATH_HAL = [] @@ -71,6 +72,9 @@ CPPDEFINES_MOD += [ ] SOURCE_MOD += [ + 'vendor/trezor-storage/flash_area.c', +] +SOURCE_MOD_CRYPTO = [ 'vendor/trezor-crypto/blake2s.c', 'vendor/trezor-crypto/chacha_drbg.c', 'vendor/trezor-crypto/chacha20poly1305/chacha_merged.c', @@ -83,7 +87,6 @@ SOURCE_MOD += [ 'vendor/trezor-crypto/memzero.c', 'vendor/trezor-crypto/rand.c', 'vendor/trezor-crypto/sha2.c', - 'vendor/trezor-storage/flash_area.c', ] # modtrezorui @@ -201,7 +204,7 @@ env.Replace( ) env.Replace( - ALLSOURCES=SOURCE_MOD + SOURCE_BOOTLOADER + SOURCE_NANOPB + SOURCE_HAL, + ALLSOURCES=SOURCE_MOD + SOURCE_MOD_CRYPTO + SOURCE_BOOTLOADER + SOURCE_NANOPB + SOURCE_HAL, ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT'] + [f"PRODUCTION={int(PRODUCTION)}", f"BOOTLOADER_QA={int(BOOTLOADER_QA)}"])) cmake_gen = env.Command( @@ -265,6 +268,7 @@ env.Append(LINKFLAGS=f' -l{RUST_LIB}') obj_program = [] obj_program += env.Object(source=SOURCE_MOD) +obj_program += env.Object(source=SOURCE_MOD_CRYPTO) obj_program += env.Object(source=SOURCE_BOOTLOADER) obj_program += env.Object(source=SOURCE_NANOPB) obj_program += env.Object(source=SOURCE_HAL) diff --git a/core/SConscript.bootloader_ci b/core/SConscript.bootloader_ci index e5c41fd60b..861744a5a6 100644 --- a/core/SConscript.bootloader_ci +++ b/core/SConscript.bootloader_ci @@ -24,6 +24,7 @@ CCFLAGS_MOD = '' CPPPATH_MOD = [] CPPDEFINES_MOD = [] SOURCE_MOD = [] +SOURCE_MOD_CRYPTO = [] CPPDEFINES_HAL = [] SOURCE_HAL = [] PATH_HAL = [] @@ -66,6 +67,9 @@ CPPDEFINES_MOD += [ 'ED25519_NO_PRECOMP', ] SOURCE_MOD += [ + 'vendor/trezor-storage/flash_area.c', +] +SOURCE_MOD_CRYPTO += [ 'vendor/trezor-crypto/blake2s.c', 'vendor/trezor-crypto/chacha_drbg.c', 'vendor/trezor-crypto/chacha20poly1305/chacha_merged.c', @@ -78,7 +82,6 @@ SOURCE_MOD += [ 'vendor/trezor-crypto/memzero.c', 'vendor/trezor-crypto/rand.c', 'vendor/trezor-crypto/sha2.c', - 'vendor/trezor-storage/flash_area.c', ] # modtrezorui @@ -181,14 +184,14 @@ env.Replace( ] + CPPDEFINES_MOD + CPPDEFINES_HAL, ASFLAGS=env.get('ENV')['CPU_ASFLAGS'], ASPPFLAGS='$CFLAGS $CCFLAGS', - ALLSOURCES=SOURCE_MOD + SOURCE_BOOTLOADER + SOURCE_HAL+ SOURCE_NANOPB, ) + ALLSOURCES=SOURCE_MOD + SOURCE_MOD_CRYPTO + SOURCE_BOOTLOADER + SOURCE_HAL+ SOURCE_NANOPB, ) env.Replace( HEADERTOOL='tools/headertool.py', ) env.Replace( - ALLSOURCES=SOURCE_MOD + SOURCE_BOOTLOADER + SOURCE_NANOPB + SOURCE_HAL, + ALLSOURCES=SOURCE_MOD + SOURCE_MOD_CRYPTO + SOURCE_BOOTLOADER + SOURCE_NANOPB + SOURCE_HAL, ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT'])) cmake_gen = env.Command( @@ -204,6 +207,7 @@ cmake_gen = env.Command( obj_program = [] obj_program += env.Object(source=SOURCE_MOD) +obj_program += env.Object(source=SOURCE_MOD_CRYPTO) obj_program += env.Object(source=SOURCE_BOOTLOADER) obj_program += env.Object(source=SOURCE_NANOPB) obj_program += env.Object(source=SOURCE_HAL) diff --git a/core/SConscript.bootloader_emu b/core/SConscript.bootloader_emu index 1506c4197c..290faa2c07 100644 --- a/core/SConscript.bootloader_emu +++ b/core/SConscript.bootloader_emu @@ -26,6 +26,7 @@ CCFLAGS_MOD = '' CPPPATH_MOD = [] CPPDEFINES_MOD = [] SOURCE_MOD = [] +SOURCE_MOD_CRYPTO = [] if TREZOR_MODEL in ('1', 'R'): FONT_NORMAL='Font_PixelOperator_Regular_8' @@ -66,7 +67,7 @@ CPPDEFINES_MOD += [ 'TREZOR_UI2', 'FANCY_FATAL_ERROR' ] -SOURCE_MOD += [ +SOURCE_MOD_CRYPTO += [ 'vendor/trezor-crypto/blake2s.c', 'vendor/trezor-crypto/chacha_drbg.c', 'vendor/trezor-crypto/chacha20poly1305/chacha_merged.c', @@ -254,7 +255,7 @@ except OSError: env.Replace( - ALLSOURCES=SOURCE_MOD + SOURCE_BOOTLOADER + SOURCE_NANOPB + SOURCE_TREZORHAL + SOURCE_UNIX, + ALLSOURCES=SOURCE_MOD + SOURCE_MOD_CRYPTO + SOURCE_BOOTLOADER + SOURCE_NANOPB + SOURCE_TREZORHAL + SOURCE_UNIX, ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'])) cmake_gen = env.Command( @@ -328,6 +329,7 @@ env.Append(LINKFLAGS='-lm') obj_program = [] obj_program += env.Object(source=SOURCE_MOD) +obj_program += env.Object(source=SOURCE_MOD_CRYPTO) obj_program += env.Object(source=SOURCE_BOOTLOADER) obj_program += env.Object(source=SOURCE_NANOPB) obj_program += env.Object(source=SOURCE_TREZORHAL) diff --git a/core/SConscript.firmware b/core/SConscript.firmware index 887419c6d2..e46a296667 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -31,6 +31,7 @@ CCFLAGS_MOD = '' CPPPATH_MOD = [] CPPDEFINES_MOD = [] SOURCE_MOD = [] +SOURCE_MOD_CRYPTO = [] CPPDEFINES_HAL = [] SOURCE_HAL = [] PATH_HAL = [] @@ -88,6 +89,8 @@ SOURCE_MOD += [ 'embed/extmod/modtrezorcrypto/crc.c', 'embed/extmod/modtrezorcrypto/modtrezorcrypto.c', 'embed/extmod/modtrezorcrypto/rand.c', +] +SOURCE_MOD_CRYPTO += [ 'vendor/trezor-crypto/address.c', 'vendor/trezor-crypto/aes/aes_modes.c', 'vendor/trezor-crypto/aes/aesccm.c', @@ -143,7 +146,7 @@ SOURCE_MOD += [ 'vendor/trezor-crypto/tls_prf.c', ] if EVERYTHING: - SOURCE_MOD += [ + SOURCE_MOD_CRYPTO += [ 'vendor/trezor-crypto/cardano.c', 'vendor/trezor-crypto/monero/base58.c', 'vendor/trezor-crypto/monero/serialize.c', @@ -177,7 +180,7 @@ if FEATURE_FLAGS["SECP256K1_ZKP"]: 'vendor/secp256k1-zkp/src/precomputed_ecmult_gen.c', 'vendor/secp256k1-zkp/src/asm/field_10x26_arm.s' ] - SOURCE_MOD += [ + SOURCE_MOD_CRYPTO += [ 'vendor/trezor-crypto/zkp_context.c', 'vendor/trezor-crypto/zkp_ecdsa.c', 'vendor/trezor-crypto/zkp_bip340.c', @@ -189,7 +192,7 @@ if FEATURE_FLAGS["AES_GCM"]: 'USE_AES_GCM', 'AES_VAR', ] - SOURCE_MOD += [ + SOURCE_MOD_CRYPTO += [ 'vendor/trezor-crypto/aes/gf128mul.c', 'vendor/trezor-crypto/aes/aesgcm.c', ] @@ -731,9 +734,10 @@ if FROZEN: # Program objects # -source_files = SOURCE_MOD + SOURCE_FIRMWARE + SOURCE_MICROPYTHON + SOURCE_MICROPYTHON_SPEED + SOURCE_HAL +source_files = SOURCE_MOD + SOURCE_MOD_CRYPTO + SOURCE_FIRMWARE + SOURCE_MICROPYTHON + SOURCE_MICROPYTHON_SPEED + SOURCE_HAL obj_program = [] obj_program.extend(env.Object(source=SOURCE_MOD)) +obj_program.extend(env.Object(source=SOURCE_MOD_CRYPTO)) if FEATURE_FLAGS["SECP256K1_ZKP"]: obj_program.extend(env.Object(source=SOURCE_MOD_SECP256K1_ZKP, CCFLAGS='$CCFLAGS -Wno-unused-function')) source_files.extend(SOURCE_MOD_SECP256K1_ZKP) diff --git a/core/SConscript.prodtest b/core/SConscript.prodtest index 481a1a48ef..476ff7b5b4 100644 --- a/core/SConscript.prodtest +++ b/core/SConscript.prodtest @@ -28,6 +28,7 @@ CPPDEFINES_MOD = [ 'USE_INSECURE_PRNG', ] SOURCE_MOD = [] +SOURCE_MOD_CRYPTO = [] CPPDEFINES_HAL = [] SOURCE_HAL = [] PATH_HAL = [] @@ -55,6 +56,9 @@ CPPPATH_MOD += [ 'vendor/trezor-storage', ] SOURCE_MOD += [ + 'vendor/trezor-storage/flash_area.c', +] +SOURCE_MOD_CRYPTO += [ 'vendor/trezor-crypto/aes/aes_modes.c', 'vendor/trezor-crypto/aes/aesccm.c', 'vendor/trezor-crypto/aes/aescrypt.c', @@ -75,7 +79,6 @@ SOURCE_MOD += [ 'vendor/trezor-crypto/secp256k1.c', 'vendor/trezor-crypto/sha2.c', 'vendor/trezor-crypto/tls_prf.c', - 'vendor/trezor-storage/flash_area.c', ] # modtrezorui @@ -180,7 +183,7 @@ env.Replace( env.Replace( - ALLSOURCES=SOURCE_MOD + SOURCE_PRODTEST + SOURCE_HAL, + ALLSOURCES=SOURCE_MOD + SOURCE_MOD_CRYPTO + SOURCE_PRODTEST + SOURCE_HAL, ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT'])) cmake_gen = env.Command( @@ -196,6 +199,7 @@ cmake_gen = env.Command( obj_program = [] obj_program.extend(env.Object(source=SOURCE_MOD)) +obj_program.extend(env.Object(source=SOURCE_MOD_CRYPTO)) obj_program.extend(env.Object(source=SOURCE_PRODTEST)) obj_program.extend(env.Object(source=SOURCE_HAL)) diff --git a/core/SConscript.reflash b/core/SConscript.reflash index 7259a28653..657c9581fe 100644 --- a/core/SConscript.reflash +++ b/core/SConscript.reflash @@ -23,6 +23,7 @@ CCFLAGS_MOD = '' CPPPATH_MOD = [] CPPDEFINES_MOD = [] SOURCE_MOD = [] +SOURCE_MOD_CRYPTO = [] CPPDEFINES_HAL = [] SOURCE_HAL = [] PATH_HAL = [] @@ -49,7 +50,7 @@ CPPPATH_MOD += [ 'vendor/trezor-crypto', 'vendor/trezor-storage', ] -SOURCE_MOD += [ +SOURCE_MOD_CRYPTO += [ 'vendor/trezor-crypto/memzero.c', ] @@ -146,7 +147,7 @@ env.Replace( ) env.Replace( - ALLSOURCES=SOURCE_MOD + SOURCE_REFLASH + SOURCE_HAL, + ALLSOURCES=SOURCE_MOD + SOURCE_MOD_CRYPTO + SOURCE_REFLASH + SOURCE_HAL, ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES'] + env['CPPDEFINES_IMPLICIT'])) cmake_gen = env.Command( @@ -161,6 +162,7 @@ cmake_gen = env.Command( obj_program = [] obj_program += env.Object(source=SOURCE_MOD) +obj_program += env.Object(source=SOURCE_MOD_CRYPTO) obj_program += env.Object(source=SOURCE_REFLASH) obj_program += env.Object(source=SOURCE_HAL) diff --git a/core/SConscript.unix b/core/SConscript.unix index 5ef09e5142..ec93317266 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -34,6 +34,7 @@ CPPDEFINES_MOD = [] SOURCE_MOD = [ 'vendor/micropython/extmod/vfs_posix_file.c', ] +SOURCE_MOD_CRYPTO = [] PYOPT = ARGUMENTS.get('PYOPT', '1') FROZEN = ARGUMENTS.get('TREZOR_EMULATOR_FROZEN', 0) @@ -90,6 +91,8 @@ SOURCE_MOD += [ 'embed/extmod/trezorobj.c', 'embed/extmod/modtrezorcrypto/crc.c', 'embed/extmod/modtrezorcrypto/modtrezorcrypto.c', +] +SOURCE_MOD_CRYPTO += [ 'vendor/trezor-crypto/address.c', 'vendor/trezor-crypto/aes/aes_modes.c', 'vendor/trezor-crypto/aes/aescrypt.c', @@ -143,7 +146,7 @@ SOURCE_MOD += [ 'vendor/trezor-crypto/slip39_english.c', ] if EVERYTHING: - SOURCE_MOD += [ + SOURCE_MOD_CRYPTO += [ 'vendor/trezor-crypto/cardano.c', 'vendor/trezor-crypto/monero/base58.c', 'vendor/trezor-crypto/monero/serialize.c', @@ -174,7 +177,7 @@ if FEATURE_FLAGS["SECP256K1_ZKP"]: 'vendor/secp256k1-zkp/src/precomputed_ecmult.c', 'vendor/secp256k1-zkp/src/precomputed_ecmult_gen.c', ] - SOURCE_MOD += [ + SOURCE_MOD_CRYPTO += [ 'vendor/trezor-crypto/zkp_context.c', 'vendor/trezor-crypto/zkp_ecdsa.c', 'vendor/trezor-crypto/zkp_bip340.c', @@ -186,7 +189,7 @@ if FEATURE_FLAGS["AES_GCM"]: 'USE_AES_GCM', 'AES_VAR', ] - SOURCE_MOD += [ + SOURCE_MOD_CRYPTO += [ 'vendor/trezor-crypto/aes/gf128mul.c', 'vendor/trezor-crypto/aes/aesgcm.c', ] @@ -819,8 +822,9 @@ if FROZEN: # obj_program = [] -source_files = SOURCE_MOD + SOURCE_MICROPYTHON + SOURCE_UNIX +source_files = SOURCE_MOD + SOURCE_MOD_CRYPTO + SOURCE_MICROPYTHON + SOURCE_UNIX obj_program.extend(env.Object(source=SOURCE_MOD)) +obj_program.extend(env.Object(source=SOURCE_MOD_CRYPTO)) if FEATURE_FLAGS["SECP256K1_ZKP"]: obj_program.extend(env.Object(source=SOURCE_MOD_SECP256K1_ZKP, CCFLAGS='$CCFLAGS -Wno-unused-function')) source_files.extend(SOURCE_MOD_SECP256K1_ZKP)