From aa52fc3903f8d7c69012321334342db1f7bd3c6d Mon Sep 17 00:00:00 2001 From: matejcik Date: Fri, 15 May 2020 12:38:31 +0200 Subject: [PATCH] core/extmod: drop unused rfc6979 module --- .../modtrezorcrypto/modtrezorcrypto-rfc6979.h | 82 ------------------- .../extmod/modtrezorcrypto/modtrezorcrypto.c | 2 - .../mocks/generated/trezorcrypto/__init__.pyi | 17 ---- core/src/trezor/crypto/__init__.py | 1 - core/tests/test_trezor.crypto.rfc6979.py | 40 --------- 5 files changed, 142 deletions(-) delete mode 100644 core/embed/extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h delete mode 100644 core/tests/test_trezor.crypto.rfc6979.py diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h deleted file mode 100644 index de14be4610..0000000000 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This file is part of the Trezor project, https://trezor.io/ - * - * Copyright (c) SatoshiLabs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "py/objstr.h" - -#include "rfc6979.h" - -/// package: trezorcrypto.__init__ - -/// class rfc6979: -/// """ -/// RFC6979 context. -/// """ -typedef struct _mp_obj_Rfc6979_t { - mp_obj_base_t base; - rfc6979_state rng; -} mp_obj_Rfc6979_t; - -/// def __init__(self, secret_key: bytes, hash: bytes) -> None: -/// """ -/// Initialize RFC6979 context from secret key and a hash. -/// """ -STATIC mp_obj_t mod_trezorcrypto_Rfc6979_make_new(const mp_obj_type_t *type, - size_t n_args, size_t n_kw, - const mp_obj_t *args) { - mp_arg_check_num(n_args, n_kw, 2, 2, false); - mp_obj_Rfc6979_t *o = m_new_obj_with_finaliser(mp_obj_Rfc6979_t); - o->base.type = type; - mp_buffer_info_t pkey, hash; - mp_get_buffer_raise(args[0], &pkey, MP_BUFFER_READ); - mp_get_buffer_raise(args[1], &hash, MP_BUFFER_READ); - if (pkey.len != 32) { - mp_raise_ValueError("Secret key has to be 32 bytes long"); - } - if (hash.len != 32) { - mp_raise_ValueError("Hash has to be 32 bytes long"); - } - init_rfc6979((const uint8_t *)pkey.buf, (const uint8_t *)hash.buf, &(o->rng)); - return MP_OBJ_FROM_PTR(o); -} - -/// def next(self) -> bytes: -/// """ -/// Compute next 32-bytes of pseudorandom data. -/// """ -STATIC mp_obj_t mod_trezorcrypto_Rfc6979_next(mp_obj_t self) { - mp_obj_Rfc6979_t *o = MP_OBJ_TO_PTR(self); - uint8_t out[32]; - generate_rfc6979(out, &(o->rng)); - return mp_obj_new_bytes(out, sizeof(out)); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Rfc6979_next_obj, - mod_trezorcrypto_Rfc6979_next); - -STATIC const mp_rom_map_elem_t mod_trezorcrypto_Rfc6979_locals_dict_table[] = { - {MP_ROM_QSTR(MP_QSTR_next), MP_ROM_PTR(&mod_trezorcrypto_Rfc6979_next_obj)}, -}; -STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_Rfc6979_locals_dict, - mod_trezorcrypto_Rfc6979_locals_dict_table); - -STATIC const mp_obj_type_t mod_trezorcrypto_Rfc6979_type = { - {&mp_type_type}, - .name = MP_QSTR_Rfc6979, - .make_new = mod_trezorcrypto_Rfc6979_make_new, - .locals_dict = (void *)&mod_trezorcrypto_Rfc6979_locals_dict, -}; diff --git a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto.c b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto.c index e3a2d20333..37b09f1f7c 100644 --- a/core/embed/extmod/modtrezorcrypto/modtrezorcrypto.c +++ b/core/embed/extmod/modtrezorcrypto/modtrezorcrypto.c @@ -39,7 +39,6 @@ #include "modtrezorcrypto-nist256p1.h" #include "modtrezorcrypto-pbkdf2.h" #include "modtrezorcrypto-random.h" -#include "modtrezorcrypto-rfc6979.h" #include "modtrezorcrypto-ripemd160.h" #include "modtrezorcrypto-secp256k1.h" #include "modtrezorcrypto-sha1.h" @@ -83,7 +82,6 @@ STATIC const mp_rom_map_elem_t mp_module_trezorcrypto_globals_table[] = { #endif {MP_ROM_QSTR(MP_QSTR_pbkdf2), MP_ROM_PTR(&mod_trezorcrypto_Pbkdf2_type)}, {MP_ROM_QSTR(MP_QSTR_random), MP_ROM_PTR(&mod_trezorcrypto_random_module)}, - {MP_ROM_QSTR(MP_QSTR_rfc6979), MP_ROM_PTR(&mod_trezorcrypto_Rfc6979_type)}, {MP_ROM_QSTR(MP_QSTR_ripemd160), MP_ROM_PTR(&mod_trezorcrypto_Ripemd160_type)}, {MP_ROM_QSTR(MP_QSTR_secp256k1), diff --git a/core/mocks/generated/trezorcrypto/__init__.pyi b/core/mocks/generated/trezorcrypto/__init__.pyi index f7b2c0b395..3a847e7d0e 100644 --- a/core/mocks/generated/trezorcrypto/__init__.pyi +++ b/core/mocks/generated/trezorcrypto/__init__.pyi @@ -204,23 +204,6 @@ class pbkdf2: """ -# extmod/modtrezorcrypto/modtrezorcrypto-rfc6979.h -class rfc6979: - """ - RFC6979 context. - """ - - def __init__(self, secret_key: bytes, hash: bytes) -> None: - """ - Initialize RFC6979 context from secret key and a hash. - """ - - def next(self) -> bytes: - """ - Compute next 32-bytes of pseudorandom data. - """ - - # extmod/modtrezorcrypto/modtrezorcrypto-ripemd160.h class ripemd160: """ diff --git a/core/src/trezor/crypto/__init__.py b/core/src/trezor/crypto/__init__.py index 32879eeb1b..aee9b2c90e 100644 --- a/core/src/trezor/crypto/__init__.py +++ b/core/src/trezor/crypto/__init__.py @@ -7,7 +7,6 @@ from trezorcrypto import ( # noqa: F401 crc, pbkdf2, random, - rfc6979, ) if not utils.BITCOIN_ONLY: diff --git a/core/tests/test_trezor.crypto.rfc6979.py b/core/tests/test_trezor.crypto.rfc6979.py deleted file mode 100644 index b303231d16..0000000000 --- a/core/tests/test_trezor.crypto.rfc6979.py +++ /dev/null @@ -1,40 +0,0 @@ -from common import * - -from trezor.crypto import rfc6979 -from trezor.crypto.hashlib import sha256 - - -class TestCryptoRfc6979(unittest.TestCase): - - def test_vectors(self): - - vectors = [ - ("c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721", - "sample", - "a6e3c57dd01abe90086538398355dd4c3b17aa873382b0f24d6129493d8aad60"), - ("cca9fbcc1b41e5a95d369eaa6ddcff73b61a4efaa279cfc6567e8daa39cbaf50", - "sample", - "2df40ca70e639d89528a6b670d9d48d9165fdc0febc0974056bdce192b8e16a3"), - ("0000000000000000000000000000000000000000000000000000000000000001", - "Satoshi Nakamoto", - "8f8a276c19f4149656b280621e358cce24f5f52542772691ee69063b74f15d15"), - ("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140", - "Satoshi Nakamoto", - "33a19b60e25fb6f4435af53a3d42d493644827367e6453928554f43e49aa6f90"), - ("f8b8af8ce3c7cca5e300d33939540c10d45ce001b8f252bfbc57ba0342904181", - "Alan Turing", "525a82b70e67874398067543fd84c83d30c175fdc45fdeee082fe13b1d7cfdf1"), - ("0000000000000000000000000000000000000000000000000000000000000001", - "All those moments will be lost in time, like tears in rain. Time to die...", - "38aa22d72376b4dbc472e06c3ba403ee0a394da63fc58d88686c611aba98d6b3"), - ("e91671c46231f833a6406ccbea0e3e392c76c167bac1cb013f6f1013980455c2", - "There is a computer disease that anybody who works with computers knows about. It's a very serious disease and it interferes completely with the work. The trouble with computers is that you 'play' with them!", - "1f4b84c23a86a221d233f2521be018d9318639d5b8bbd6374a8a59232d16ad3d"), - ] - - for key, msg, k in vectors: - rng = rfc6979(unhexlify(key), sha256(msg).digest()) - self.assertEqual(rng.next(), unhexlify(k)) - - -if __name__ == '__main__': - unittest.main()