core/extmod: drop unused rfc6979 module

pull/1002/head
matejcik 4 years ago committed by matejcik
parent 050936d0d7
commit aa52fc3903

@ -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 <http://www.gnu.org/licenses/>.
*/
#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,
};

@ -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),

@ -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:
"""

@ -7,7 +7,6 @@ from trezorcrypto import ( # noqa: F401
crc,
pbkdf2,
random,
rfc6979,
)
if not utils.BITCOIN_ONLY:

@ -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()
Loading…
Cancel
Save