chore(core, crypto): remove unused monero hasher
What changed, and why it matters
This commit simply removes an unused Monero hashing helper (the 'Hasher' class and related C functions) from the Trezor firmware codebase. It deletes dead code, tests, and type stubs. There is no indication this fixes or introduces a security vulnerability.
No security action needed; treat as routine code cleanup. Reviewers may verify that no remaining code references the removed Hasher type or xmr_hasher_* functions.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit deletes the Monero Hasher MicroPython binding, its generated .pyi stub, the underlying C wrapper functions (xmr_hasher_init/update/final/copy), their header declarations, and the associated unit test. The change is a pure code-cleanup/refactoring commit with no functional behavior change for used code paths. No security-relevant bug is patched or introduced in the diff.
Changed components
core/embed/upymod/modtrezorcrypto/modtrezorcrypto-monero.hcore/mocks/generated/trezorcrypto/monero.pyicrypto/monero/xmr.ccrypto/monero/xmr.hcrypto/tests/test_check.ccrypto/tests/test_check_monero.hInspect captured patch +0 / −200
diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-monero.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-monero.h
index 85fe7c0a..aa461e9a 100644
--- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-monero.h
+++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-monero.h
@@ -218,56 +218,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(
mod_trezorcrypto_monero_bignum256modm___del___obj,
mod_trezorcrypto_monero_bignum256modm___del__);
-/// class Hasher:
-/// """
-/// XMR hasher
-/// """
-
-/// def __init__(self, x: AnyBytes | None = None):
-/// """
-/// Constructor
-/// """
-
-/// def update(self, buffer: AnyBytes) -> None:
-/// """
-/// Update hasher
-/// """
-
-/// def digest(self) -> bytes:
-/// """
-/// Computes digest
-/// """
-
-/// def copy(self) -> Hasher:
-/// """
-/// Creates copy of the hasher, preserving the state
-/// """
-
-STATIC mp_obj_t mod_trezorcrypto_monero_hasher_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, 0, 1, false);
- mp_obj_hasher_t *o = m_new_obj_with_finaliser(mp_obj_hasher_t);
- o->base.type = type;
- xmr_hasher_init(&(o->h));
-
- if (n_args == 1 && MP_OBJ_IS_STR_OR_BYTES(args[0])) {
- mp_buffer_info_t buff = {0};
- mp_get_buffer_raise(args[0], &buff, MP_BUFFER_READ);
- xmr_hasher_update(&o->h, buff.buf, buff.len);
- }
-
- return MP_OBJ_FROM_PTR(o);
-}
-
-STATIC mp_obj_t mod_trezorcrypto_monero_hasher___del__(mp_obj_t self) {
- mp_obj_hasher_t *o = MP_OBJ_TO_PTR(self);
- memzero(&(o->h), sizeof(Hasher));
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_hasher___del___obj,
- mod_trezorcrypto_monero_hasher___del__);
-
//
// Scalar defs
//
@@ -1129,60 +1079,6 @@ STATIC mp_obj_t mod_trezorcrypto_ct_equals(const mp_obj_t a, const mp_obj_t b) {
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ct_equals_obj,
mod_trezorcrypto_ct_equals);
-// Hasher
-STATIC mp_obj_t mod_trezorcrypto_monero_hasher_update(mp_obj_t self,
- const mp_obj_t arg) {
- mp_obj_hasher_t *o = MP_OBJ_TO_PTR(self);
- mp_buffer_info_t buff = {0};
- mp_get_buffer_raise(arg, &buff, MP_BUFFER_READ);
- if (buff.len > 0) {
- xmr_hasher_update(&o->h, buff.buf, buff.len);
- }
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_hasher_update_obj,
- mod_trezorcrypto_monero_hasher_update);
-
-STATIC mp_obj_t mod_trezorcrypto_monero_hasher_digest(size_t n_args,
- const mp_obj_t *args) {
- mp_obj_hasher_t *o = MP_OBJ_TO_PTR(args[0]);
-
- Hasher ctx = {0};
- memcpy(&ctx, &(o->h), sizeof(Hasher));
-
- if (n_args == 1 || args[1] == mp_const_none) {
- vstr_t hash = {0};
- vstr_init_len(&hash, SHA3_256_DIGEST_LENGTH);
- xmr_hasher_final(&ctx, (uint8_t *)hash.buf);
- memzero(&ctx, sizeof(SHA3_CTX));
- return mp_obj_new_str_from_vstr(&mp_type_bytes, &hash);
- } else {
- mp_buffer_info_t bufm = {0};
- mp_get_buffer_raise(args[1], &bufm, MP_BUFFER_WRITE);
- const mp_int_t offset = n_args >= 3 ? mp_obj_get_int(args[2]) : 0;
- if (bufm.len < SHA3_256_DIGEST_LENGTH + offset) {
- mp_raise_ValueError(MP_ERROR_TEXT("Buffer too small"));
- }
-
- xmr_hasher_final(&ctx, (uint8_t *)bufm.buf + offset);
- memzero(&ctx, sizeof(SHA3_CTX));
- return args[1];
- }
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
- mod_trezorcrypto_monero_hasher_digest_obj, 1, 3,
- mod_trezorcrypto_monero_hasher_digest);
-
-STATIC mp_obj_t mod_trezorcrypto_monero_hasher_copy(mp_obj_t self) {
- mp_obj_hasher_t *o = MP_OBJ_TO_PTR(self);
- mp_obj_hasher_t *cp = m_new_obj_with_finaliser(mp_obj_hasher_t);
- cp->base.type = o->base.type;
- memcpy(&(cp->h), &(o->h), sizeof(Hasher));
- return MP_OBJ_FROM_PTR(o);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_hasher_copy_obj,
- mod_trezorcrypto_monero_hasher_copy);
-
//
// Type defs
//
@@ -1218,29 +1114,6 @@ STATIC const mp_obj_type_t mod_trezorcrypto_monero_bignum256modm_type = {
.locals_dict = (void *)&mod_trezorcrypto_monero_bignum256modm_locals_dict,
};
-STATIC const mp_rom_map_elem_t
- mod_trezorcrypto_monero_hasher_locals_dict_table[] = {
- {MP_ROM_QSTR(MP_QSTR_update),
- MP_ROM_PTR(&mod_trezorcrypto_monero_hasher_update_obj)},
- {MP_ROM_QSTR(MP_QSTR_digest),
- MP_ROM_PTR(&mod_trezorcrypto_monero_hasher_digest_obj)},
- {MP_ROM_QSTR(MP_QSTR_copy),
- MP_ROM_PTR(&mod_trezorcrypto_monero_hasher_copy_obj)},
- {MP_ROM_QSTR(MP_QSTR___del__),
- MP_ROM_PTR(&mod_trezorcrypto_monero_hasher___del___obj)},
- {MP_ROM_QSTR(MP_QSTR_block_size), MP_ROM_INT(SHA3_256_BLOCK_LENGTH)},
- {MP_ROM_QSTR(MP_QSTR_digest_size), MP_ROM_INT(SHA3_256_DIGEST_LENGTH)},
-};
-STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_monero_hasher_locals_dict,
- mod_trezorcrypto_monero_hasher_locals_dict_table);
-
-STATIC const mp_obj_type_t mod_trezorcrypto_monero_hasher_type = {
- {&mp_type_type},
- .name = MP_QSTR_hasher,
- .make_new = mod_trezorcrypto_monero_hasher_make_new,
- .locals_dict = (void *)&mod_trezorcrypto_monero_hasher_locals_dict,
-};
-
/// BP_GI_PLUS_PRE: bytes
STATIC const mp_obj_str_t mod_trezorcrypto_monero_BP_PLUS_GI_PRE_obj = {{&mp_type_bytes}, 0, 8192, (const byte*)""
"\x38\xc5\xd4\xdb\x53\xae\xb8\x6f\x5a\x80\xde\xf9\xbe\x49\x53\xf2"
diff --git a/core/mocks/generated/trezorcrypto/monero.pyi b/core/mocks/generated/trezorcrypto/monero.pyi
index 98d8a702..4f6abcb6 100644
--- a/core/mocks/generated/trezorcrypto/monero.pyi
+++ b/core/mocks/generated/trezorcrypto/monero.pyi
@@ -24,29 +24,6 @@ class Scalar:
"""
-# upymod/modtrezorcrypto/modtrezorcrypto-monero.h
-class Hasher:
- """
- XMR hasher
- """
- def __init__(self, x: AnyBytes | None = None):
- """
- Constructor
- """
- def update(self, buffer: AnyBytes) -> None:
- """
- Update hasher
- """
- def digest(self) -> bytes:
- """
- Computes digest
- """
- def copy(self) -> Hasher:
- """
- Creates copy of the hasher, preserving the state
- """
-
-
# upymod/modtrezorcrypto/modtrezorcrypto-monero.h
def sc_copy(
dst: Scalar | None, val: int | bytes | Scalar
diff --git a/crypto/monero/xmr.c b/crypto/monero/xmr.c
index c2df6bf4..a2fe11c0 100644
--- a/crypto/monero/xmr.c
+++ b/crypto/monero/xmr.c
@@ -30,20 +30,6 @@ void xmr_fast_hash(uint8_t *hash, const void *data, size_t length) {
hasher_Raw(HASHER_SHA3K, data, length, hash);
}
-void xmr_hasher_init(Hasher *hasher) { hasher_Init(hasher, HASHER_SHA3K); }
-
-void xmr_hasher_update(Hasher *hasher, const void *data, size_t length) {
- hasher_Update(hasher, data, length);
-}
-
-void xmr_hasher_final(Hasher *hasher, uint8_t *hash) {
- hasher_Final(hasher, hash);
-}
-
-void xmr_hasher_copy(Hasher *dst, const Hasher *src) {
- memcpy(dst, src, sizeof(Hasher));
-}
-
void xmr_hash_to_scalar(bignum256modm r, const void *data, size_t length) {
uint8_t hash[HASHER_DIGEST_LENGTH] = {0};
hasher_Raw(HASHER_SHA3K, data, length, hash);
diff --git a/crypto/monero/xmr.h b/crypto/monero/xmr.h
index 4ef83a06..a0d76229 100644
--- a/crypto/monero/xmr.h
+++ b/crypto/monero/xmr.h
@@ -26,12 +26,6 @@ void xmr_random_scalar(bignum256modm m);
/* cn_fast_hash */
void xmr_fast_hash(uint8_t *hash, const void *data, size_t length);
-/* incremental hashing wrappers */
-void xmr_hasher_init(Hasher *hasher);
-void xmr_hasher_update(Hasher *hasher, const void *data, size_t length);
-void xmr_hasher_final(Hasher *hasher, uint8_t *hash);
-void xmr_hasher_copy(Hasher *dst, const Hasher *src);
-
/* H_s(buffer) */
void xmr_hash_to_scalar(bignum256modm r, const void *data, size_t length);
diff --git a/crypto/tests/test_check.c b/crypto/tests/test_check.c
index 0fa1d86b..9b9e0ddc 100644
--- a/crypto/tests/test_check.c
+++ b/crypto/tests/test_check.c
@@ -12045,7 +12045,6 @@ Suite *test_suite(void) {
tcase_add_test(tc, test_xmr_check_point);
tcase_add_test(tc, test_xmr_h);
tcase_add_test(tc, test_xmr_fast_hash);
- tcase_add_test(tc, test_xmr_hasher);
tcase_add_test(tc, test_xmr_hash_to_scalar);
tcase_add_test(tc, test_xmr_hash_to_ec);
tcase_add_test(tc, test_xmr_derivation_to_scalar);
diff --git a/crypto/tests/test_check_monero.h b/crypto/tests/test_check_monero.h
index 8d09396d..3ef462cb 100644
--- a/crypto/tests/test_check_monero.h
+++ b/crypto/tests/test_check_monero.h
@@ -640,35 +640,6 @@ START_TEST(test_xmr_fast_hash) {
}
END_TEST
-START_TEST(test_xmr_hasher) {
- Hasher hasher;
- uint8_t hash[32];
-
- static const struct {
- char *chunk[3];
- char *hash;
- } tests[] = {
- {{"00", "01", "02"},
- "f84a97f1f0a956e738abd85c2e0a5026f8874e3ec09c8f012159dfeeaab2b156"},
- {{"001122334455667788", "00", ""},
- "72a228ee8d0d01c815f112ce315cfc215a0594abcec24162304ae0ffda139d9e"},
- {{"001000a93e0e6937b4feaf079e418a028ca85459aa39ac3871b94076f88ca608", "",
- "00112233445566"},
- "c3deafd96ff10cc190c6024548c344f6401cfe5151ab2fcd40df7cc501147e01"},
- };
-
- for (size_t i = 0; i < (sizeof(tests) / sizeof(*tests)); i++) {
- xmr_hasher_init(&hasher);
- for (int j = 0; j < 3; j++) {
- xmr_hasher_update(&hasher, fromhex(tests[i].chunk[j]),
- strlen(tests[i].chunk[j]) / 2);
- }
- xmr_hasher_final(&hasher, hash);
- ck_assert_mem_eq(hash, fromhex(tests[i].hash), 32);
- }
-}
-END_TEST
-
START_TEST(test_xmr_hash_to_scalar) {
bignum256modm a1;
unsigned char out[32];
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.