mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-25 07:48:10 +00:00
refactor(core): turn SECP256K1_ZKP into a firmware feature flag
This commit is contained in:
parent
6508d0a3c7
commit
f3d5de15ef
@ -8,14 +8,13 @@ TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
|
||||
|
||||
FEATURE_FLAGS = {
|
||||
"RDI": True,
|
||||
"SECP256K1_ZKP": True,
|
||||
}
|
||||
|
||||
CCFLAGS_MOD = ''
|
||||
CPPPATH_MOD = []
|
||||
CPPDEFINES_MOD = []
|
||||
SOURCE_MOD = []
|
||||
if EVERYTHING:
|
||||
SOURCE_MOD_SECP256K1_ZKP = []
|
||||
|
||||
PYOPT = ARGUMENTS.get('PYOPT', '1')
|
||||
FROZEN = True
|
||||
@ -107,7 +106,7 @@ if EVERYTHING:
|
||||
]
|
||||
|
||||
# libsecp256k1-zkp
|
||||
if EVERYTHING:
|
||||
if EVERYTHING and FEATURE_FLAGS["SECP256K1_ZKP"]:
|
||||
CPPPATH_MOD += [
|
||||
'vendor/secp256k1-zkp',
|
||||
'vendor/secp256k1-zkp/src',
|
||||
@ -130,7 +129,7 @@ if EVERYTHING:
|
||||
'ENABLE_MODULE_RECOVERY',
|
||||
'ENABLE_MODULE_ECDH',
|
||||
]
|
||||
SOURCE_MOD_SECP256K1_ZKP += [
|
||||
SOURCE_MOD_SECP256K1_ZKP = [
|
||||
'vendor/secp256k1-zkp/src/secp256k1.c',
|
||||
'vendor/secp256k1-zkp/src/asm/field_10x26_arm.s'
|
||||
]
|
||||
@ -565,8 +564,7 @@ if FROZEN:
|
||||
#
|
||||
# static secp256-zkp ecmult context
|
||||
#
|
||||
|
||||
if EVERYTHING:
|
||||
if EVERYTHING and FEATURE_FLAGS["SECP256K1_ZKP"]:
|
||||
host_env = Environment(ENV=os.environ)
|
||||
host_env.Replace(
|
||||
CC=os.getenv('CC_FOR_BUILD') or 'gcc',
|
||||
@ -589,7 +587,7 @@ if EVERYTHING:
|
||||
|
||||
obj_program = []
|
||||
obj_program.extend(env.Object(source=SOURCE_MOD))
|
||||
if EVERYTHING:
|
||||
if EVERYTHING and FEATURE_FLAGS["SECP256K1_ZKP"]:
|
||||
obj_program.extend(env.Object(source=SOURCE_MOD_SECP256K1_ZKP, CCFLAGS='$CCFLAGS -Wno-unused-function'))
|
||||
obj_program.extend(env.Object(source=SOURCE_FIRMWARE))
|
||||
obj_program.extend(env.Object(source=SOURCE_MICROPYTHON))
|
||||
@ -618,7 +616,7 @@ obj_program.extend(
|
||||
' $SOURCE $TARGET', ))
|
||||
|
||||
env.Depends(obj_program, qstr_generated)
|
||||
if EVERYTHING:
|
||||
if EVERYTHING and FEATURE_FLAGS["SECP256K1_ZKP"]:
|
||||
env.Depends(obj_program, secp256k1_zkp_ecmult_static_context)
|
||||
|
||||
program_elf = env.Command(
|
||||
|
@ -6,14 +6,16 @@ BITCOIN_ONLY = ARGUMENTS.get('BITCOIN_ONLY', '0')
|
||||
EVERYTHING = BITCOIN_ONLY != '1'
|
||||
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
|
||||
|
||||
FEATURE_FLAGS = {
|
||||
"SECP256K1_ZKP": True,
|
||||
}
|
||||
|
||||
CCFLAGS_MOD = ''
|
||||
CPPPATH_MOD = []
|
||||
CPPDEFINES_MOD = []
|
||||
SOURCE_MOD = [
|
||||
'vendor/micropython/extmod/vfs_posix_file.c',
|
||||
]
|
||||
if EVERYTHING:
|
||||
SOURCE_MOD_SECP256K1_ZKP = []
|
||||
|
||||
PYOPT = ARGUMENTS.get('PYOPT', '1')
|
||||
FROZEN = ARGUMENTS.get('TREZOR_EMULATOR_FROZEN', 0)
|
||||
@ -103,7 +105,7 @@ if EVERYTHING:
|
||||
]
|
||||
|
||||
# libsecp256k1-zkp
|
||||
if EVERYTHING:
|
||||
if EVERYTHING and FEATURE_FLAGS["SECP256K1_ZKP"]:
|
||||
CPPPATH_MOD += [
|
||||
'vendor/secp256k1-zkp',
|
||||
'vendor/secp256k1-zkp/src',
|
||||
@ -124,7 +126,7 @@ if EVERYTHING:
|
||||
'ENABLE_MODULE_RECOVERY',
|
||||
'ENABLE_MODULE_ECDH',
|
||||
]
|
||||
SOURCE_MOD_SECP256K1_ZKP += [
|
||||
SOURCE_MOD_SECP256K1_ZKP = [
|
||||
'vendor/secp256k1-zkp/src/secp256k1.c',
|
||||
]
|
||||
|
||||
@ -532,8 +534,7 @@ if FROZEN:
|
||||
#
|
||||
# static secp256-zkp ecmult context
|
||||
#
|
||||
|
||||
if EVERYTHING:
|
||||
if EVERYTHING and FEATURE_FLAGS["SECP256K1_ZKP"]:
|
||||
host_env = Environment(ENV=os.environ)
|
||||
host_env.Replace(
|
||||
CC=os.getenv('CC_FOR_BUILD') or 'gcc',
|
||||
@ -556,7 +557,7 @@ if EVERYTHING:
|
||||
|
||||
obj_program = []
|
||||
obj_program.extend(env.Object(source=SOURCE_MOD))
|
||||
if EVERYTHING:
|
||||
if EVERYTHING and FEATURE_FLAGS["SECP256K1_ZKP"]:
|
||||
obj_program.extend(env.Object(source=SOURCE_MOD_SECP256K1_ZKP, CCFLAGS='$CCFLAGS -Wno-unused-function'))
|
||||
obj_program.extend(env.Object(source=SOURCE_MICROPYTHON))
|
||||
obj_program.extend(env.Object(source=SOURCE_UNIX))
|
||||
@ -564,7 +565,7 @@ if FROZEN:
|
||||
obj_program.extend(env.Object(source=source_mpyc))
|
||||
|
||||
env.Depends(obj_program, qstr_generated)
|
||||
if EVERYTHING:
|
||||
if EVERYTHING and FEATURE_FLAGS["SECP256K1_ZKP"]:
|
||||
env.Depends(obj_program, secp256k1_zkp_ecmult_static_context)
|
||||
|
||||
program = env.Command(
|
||||
|
@ -52,8 +52,10 @@
|
||||
#if !BITCOIN_ONLY
|
||||
#include "modtrezorcrypto-monero.h"
|
||||
#include "modtrezorcrypto-nem.h"
|
||||
#ifdef SECP256K1_BUILD
|
||||
#include "modtrezorcrypto-secp256k1_zkp.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_trezorcrypto_globals_table[] = {
|
||||
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorcrypto)},
|
||||
@ -89,8 +91,10 @@ STATIC const mp_rom_map_elem_t mp_module_trezorcrypto_globals_table[] = {
|
||||
{MP_ROM_QSTR(MP_QSTR_secp256k1),
|
||||
MP_ROM_PTR(&mod_trezorcrypto_secp256k1_module)},
|
||||
#if !BITCOIN_ONLY
|
||||
#ifdef SECP256K1_BUILD
|
||||
{MP_ROM_QSTR(MP_QSTR_secp256k1_zkp),
|
||||
MP_ROM_PTR(&mod_trezorcrypto_secp256k1_zkp_module)},
|
||||
#endif
|
||||
#endif
|
||||
{MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&mod_trezorcrypto_Sha1_type)},
|
||||
{MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&mod_trezorcrypto_Sha256_type)},
|
||||
|
@ -3,4 +3,7 @@ from trezorcrypto import curve25519, ed25519, nist256p1, secp256k1 # noqa: F401
|
||||
from trezor import utils
|
||||
|
||||
if not utils.BITCOIN_ONLY:
|
||||
from trezorcrypto import secp256k1_zkp # noqa: F401
|
||||
try:
|
||||
from trezorcrypto import secp256k1_zkp # noqa: F401
|
||||
except ImportError:
|
||||
pass
|
||||
|
@ -4,7 +4,10 @@ from trezor.crypto import random
|
||||
from trezor.crypto.curve import secp256k1
|
||||
|
||||
if not utils.BITCOIN_ONLY:
|
||||
from trezor.crypto.curve import secp256k1_zkp
|
||||
try:
|
||||
from trezor.crypto.curve import secp256k1_zkp
|
||||
except ImportError:
|
||||
secp256k1_zkp = None
|
||||
|
||||
|
||||
class Secp256k1Common(object):
|
||||
@ -141,7 +144,7 @@ class TestCryptoSecp256k1(Secp256k1Common, unittest.TestCase):
|
||||
def __init__(self):
|
||||
self.impl = secp256k1
|
||||
|
||||
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
|
||||
@unittest.skipUnless(secp256k1_zkp is not None, "altcoin")
|
||||
class TestCryptoSecp256k1Zkp(Secp256k1Common, unittest.TestCase):
|
||||
def __init__(self):
|
||||
self.impl = secp256k1_zkp.Context()
|
||||
|
Loading…
Reference in New Issue
Block a user