From b9d5af8c1999573435be267f717ef1d67c0efa5e Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 2 Jan 2018 14:13:25 +0100 Subject: [PATCH] modtrezorcrypto: remove ssss (different implementation will be re-added later) --- SConscript.firmware | 1 - SConscript.unix | 1 - .../modtrezorcrypto/modtrezorcrypto-ssss.h | 90 ------------------- .../extmod/modtrezorcrypto/modtrezorcrypto.c | 2 - embed/extmod/modtrezorcrypto/ssss.c | 21 ----- embed/extmod/modtrezorcrypto/ssss.h | 17 ---- 6 files changed, 132 deletions(-) delete mode 100644 embed/extmod/modtrezorcrypto/modtrezorcrypto-ssss.h delete mode 100644 embed/extmod/modtrezorcrypto/ssss.c delete mode 100644 embed/extmod/modtrezorcrypto/ssss.h diff --git a/SConscript.firmware b/SConscript.firmware index 49e79befdc..4ea5f7db69 100644 --- a/SConscript.firmware +++ b/SConscript.firmware @@ -31,7 +31,6 @@ SOURCE_MOD += [ 'embed/extmod/modtrezorcrypto/modtrezorcrypto.c', 'embed/extmod/modtrezorcrypto/crc.c', 'embed/extmod/modtrezorcrypto/rand.c', - 'embed/extmod/modtrezorcrypto/ssss.c', 'vendor/trezor-crypto/address.c', 'vendor/trezor-crypto/aes/aescrypt.c', 'vendor/trezor-crypto/aes/aeskey.c', diff --git a/SConscript.unix b/SConscript.unix index e312e3712d..87fefff92f 100644 --- a/SConscript.unix +++ b/SConscript.unix @@ -32,7 +32,6 @@ SOURCE_MOD += [ 'embed/extmod/modtrezorcrypto/modtrezorcrypto.c', 'embed/extmod/modtrezorcrypto/crc.c', 'embed/extmod/modtrezorcrypto/rand.c', - 'embed/extmod/modtrezorcrypto/ssss.c', 'vendor/trezor-crypto/address.c', 'vendor/trezor-crypto/aes/aescrypt.c', 'vendor/trezor-crypto/aes/aeskey.c', diff --git a/embed/extmod/modtrezorcrypto/modtrezorcrypto-ssss.h b/embed/extmod/modtrezorcrypto/modtrezorcrypto-ssss.h deleted file mode 100644 index d1cdd3d08e..0000000000 --- a/embed/extmod/modtrezorcrypto/modtrezorcrypto-ssss.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) Pavol Rusnak, SatoshiLabs - * - * Licensed under TREZOR License - * see LICENSE file for details - */ - -#include "py/objstr.h" - -#include "bignum.h" -#include "ssss.h" - -/// def split(m: int, n: int, secret: bytes) -> tuple: -/// ''' -/// Split secret to (M of N) shares using Shamir's Secret Sharing Scheme. -/// ''' -STATIC mp_obj_t mod_trezorcrypto_ssss_split(mp_obj_t m_obj, mp_obj_t n_obj, mp_obj_t secret_obj) { - mp_int_t m = mp_obj_get_int(m_obj); - mp_int_t n = mp_obj_get_int(n_obj); - mp_buffer_info_t secret; - mp_get_buffer_raise(secret_obj, &secret, MP_BUFFER_READ); - if (secret.len != 32) { - mp_raise_ValueError("Length of the secret has to be 256 bits"); - } - if (m < 1 || n < 1 || m > 15 || n > 15 || m > n) { - mp_raise_ValueError("Invalid number of shares"); - } - bignum256 sk; - bignum256 shares[n]; - bn_read_be(secret.buf, &sk); - if (!ssss_split(&sk, m, n, shares)) { - mp_raise_ValueError("Error splitting secret"); - } - mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(n, NULL)); - vstr_t vstr[n]; - for (int i = 0; i < n; i++) { - vstr_init_len(&vstr[i], secret.len); - bn_write_be(&shares[i], secret.buf); - tuple->items[i] = mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr[i]); - } - return MP_OBJ_FROM_PTR(tuple); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorcrypto_ssss_split_obj, mod_trezorcrypto_ssss_split); - -/// def combine(shares: tuple) -> bytes: -/// ''' -/// Combine M shares of Shamir's Secret Sharing Scheme into secret. -/// ''' -STATIC mp_obj_t mod_trezorcrypto_ssss_combine(mp_obj_t shares_obj) { - size_t n; - mp_obj_t *share; - mp_obj_get_array(shares_obj, &n, &share); - if (n < 1 || n > 15) { - mp_raise_ValueError("Invalid number of shares"); - } - bignum256 bnshares[n]; - for (size_t i = 0; i < n; i++) { - if (MP_OBJ_IS_TYPE(share[i], &mp_type_bytes)) { - mp_buffer_info_t s; - mp_get_buffer_raise(share[i], &s, MP_BUFFER_READ); - if (s.len != 32) { - mp_raise_ValueError("Length of share has to be 256 bits"); - } - bn_read_be(s.buf, &bnshares[n]); - } else { - memset(&bnshares[i], 0, sizeof(bignum256)); - } - } - bignum256 sk; - if (!ssss_combine(bnshares, n, &sk)) { - mp_raise_ValueError("Error combining secret"); - } - vstr_t vstr; - vstr_init_len(&vstr, 32); - bn_write_be(&sk, (uint8_t *)vstr.buf); - return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_ssss_combine_obj, mod_trezorcrypto_ssss_combine); - -STATIC const mp_rom_map_elem_t mod_trezorcrypto_ssss_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ssss) }, - { MP_ROM_QSTR(MP_QSTR_split), MP_ROM_PTR(&mod_trezorcrypto_ssss_split_obj) }, - { MP_ROM_QSTR(MP_QSTR_combine), MP_ROM_PTR(&mod_trezorcrypto_ssss_combine_obj) }, -}; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_ssss_globals, mod_trezorcrypto_ssss_globals_table); - -STATIC const mp_obj_module_t mod_trezorcrypto_ssss_module = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&mod_trezorcrypto_ssss_globals, -}; diff --git a/embed/extmod/modtrezorcrypto/modtrezorcrypto.c b/embed/extmod/modtrezorcrypto/modtrezorcrypto.c index 959e62102e..b796e4059b 100644 --- a/embed/extmod/modtrezorcrypto/modtrezorcrypto.c +++ b/embed/extmod/modtrezorcrypto/modtrezorcrypto.c @@ -33,7 +33,6 @@ #include "modtrezorcrypto-sha512.h" #include "modtrezorcrypto-sha3-256.h" #include "modtrezorcrypto-sha3-512.h" -#include "modtrezorcrypto-ssss.h" STATIC const mp_rom_map_elem_t mp_module_trezorcrypto_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorcrypto) }, @@ -57,7 +56,6 @@ STATIC const mp_rom_map_elem_t mp_module_trezorcrypto_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_sha512), MP_ROM_PTR(&mod_trezorcrypto_Sha512_type) }, { MP_ROM_QSTR(MP_QSTR_sha3_256), MP_ROM_PTR(&mod_trezorcrypto_Sha3_256_type) }, { MP_ROM_QSTR(MP_QSTR_sha3_512), MP_ROM_PTR(&mod_trezorcrypto_Sha3_512_type) }, - { MP_ROM_QSTR(MP_QSTR_ssss), MP_ROM_PTR(&mod_trezorcrypto_ssss_module) }, }; STATIC MP_DEFINE_CONST_DICT(mp_module_trezorcrypto_globals, mp_module_trezorcrypto_globals_table); diff --git a/embed/extmod/modtrezorcrypto/ssss.c b/embed/extmod/modtrezorcrypto/ssss.c deleted file mode 100644 index 518893176f..0000000000 --- a/embed/extmod/modtrezorcrypto/ssss.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) Pavol Rusnak, SatoshiLabs - * - * Licensed under TREZOR License - * see LICENSE file for details - */ - -#include "ssss.h" - -bool ssss_split(const bignum256 *secret, int m, int n, bignum256 *shares) -{ - if (m < 1 || n < 1 || m > 15 || n > 15 || m > n) { - return false; - } - return true; -} - -bool ssss_combine(const bignum256 *shares, int n, bignum256 *secret) -{ - return true; -} diff --git a/embed/extmod/modtrezorcrypto/ssss.h b/embed/extmod/modtrezorcrypto/ssss.h deleted file mode 100644 index 5b5d5a2f6d..0000000000 --- a/embed/extmod/modtrezorcrypto/ssss.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) Pavol Rusnak, SatoshiLabs - * - * Licensed under TREZOR License - * see LICENSE file for details - */ - -#ifndef __SSSS_H__ -#define __SSSS_H__ - -#include -#include "bignum.h" - -bool ssss_split(const bignum256 *secret, int m, int n, bignum256 *shares); -bool ssss_combine(const bignum256 *shares, int n, bignum256 *secret); - -#endif