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