Skip to content

Commit 20c5ee7

Browse files
committed
chore(core, crypto): remove unused monero hasher
[no changelog]
1 parent 993dbad commit 20c5ee7

6 files changed

Lines changed: 0 additions & 200 deletions

File tree

core/embed/upymod/modtrezorcrypto/modtrezorcrypto-monero.h

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -218,56 +218,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(
218218
mod_trezorcrypto_monero_bignum256modm___del___obj,
219219
mod_trezorcrypto_monero_bignum256modm___del__);
220220

221-
/// class Hasher:
222-
/// """
223-
/// XMR hasher
224-
/// """
225-
226-
/// def __init__(self, x: AnyBytes | None = None):
227-
/// """
228-
/// Constructor
229-
/// """
230-
231-
/// def update(self, buffer: AnyBytes) -> None:
232-
/// """
233-
/// Update hasher
234-
/// """
235-
236-
/// def digest(self) -> bytes:
237-
/// """
238-
/// Computes digest
239-
/// """
240-
241-
/// def copy(self) -> Hasher:
242-
/// """
243-
/// Creates copy of the hasher, preserving the state
244-
/// """
245-
246-
STATIC mp_obj_t mod_trezorcrypto_monero_hasher_make_new(
247-
const mp_obj_type_t *type, size_t n_args, size_t n_kw,
248-
const mp_obj_t *args) {
249-
mp_arg_check_num(n_args, n_kw, 0, 1, false);
250-
mp_obj_hasher_t *o = m_new_obj_with_finaliser(mp_obj_hasher_t);
251-
o->base.type = type;
252-
xmr_hasher_init(&(o->h));
253-
254-
if (n_args == 1 && MP_OBJ_IS_STR_OR_BYTES(args[0])) {
255-
mp_buffer_info_t buff = {0};
256-
mp_get_buffer_raise(args[0], &buff, MP_BUFFER_READ);
257-
xmr_hasher_update(&o->h, buff.buf, buff.len);
258-
}
259-
260-
return MP_OBJ_FROM_PTR(o);
261-
}
262-
263-
STATIC mp_obj_t mod_trezorcrypto_monero_hasher___del__(mp_obj_t self) {
264-
mp_obj_hasher_t *o = MP_OBJ_TO_PTR(self);
265-
memzero(&(o->h), sizeof(Hasher));
266-
return mp_const_none;
267-
}
268-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_hasher___del___obj,
269-
mod_trezorcrypto_monero_hasher___del__);
270-
271221
//
272222
// Scalar defs
273223
//
@@ -1129,60 +1079,6 @@ STATIC mp_obj_t mod_trezorcrypto_ct_equals(const mp_obj_t a, const mp_obj_t b) {
11291079
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_ct_equals_obj,
11301080
mod_trezorcrypto_ct_equals);
11311081

1132-
// Hasher
1133-
STATIC mp_obj_t mod_trezorcrypto_monero_hasher_update(mp_obj_t self,
1134-
const mp_obj_t arg) {
1135-
mp_obj_hasher_t *o = MP_OBJ_TO_PTR(self);
1136-
mp_buffer_info_t buff = {0};
1137-
mp_get_buffer_raise(arg, &buff, MP_BUFFER_READ);
1138-
if (buff.len > 0) {
1139-
xmr_hasher_update(&o->h, buff.buf, buff.len);
1140-
}
1141-
return mp_const_none;
1142-
}
1143-
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_monero_hasher_update_obj,
1144-
mod_trezorcrypto_monero_hasher_update);
1145-
1146-
STATIC mp_obj_t mod_trezorcrypto_monero_hasher_digest(size_t n_args,
1147-
const mp_obj_t *args) {
1148-
mp_obj_hasher_t *o = MP_OBJ_TO_PTR(args[0]);
1149-
1150-
Hasher ctx = {0};
1151-
memcpy(&ctx, &(o->h), sizeof(Hasher));
1152-
1153-
if (n_args == 1 || args[1] == mp_const_none) {
1154-
vstr_t hash = {0};
1155-
vstr_init_len(&hash, SHA3_256_DIGEST_LENGTH);
1156-
xmr_hasher_final(&ctx, (uint8_t *)hash.buf);
1157-
memzero(&ctx, sizeof(SHA3_CTX));
1158-
return mp_obj_new_str_from_vstr(&mp_type_bytes, &hash);
1159-
} else {
1160-
mp_buffer_info_t bufm = {0};
1161-
mp_get_buffer_raise(args[1], &bufm, MP_BUFFER_WRITE);
1162-
const mp_int_t offset = n_args >= 3 ? mp_obj_get_int(args[2]) : 0;
1163-
if (bufm.len < SHA3_256_DIGEST_LENGTH + offset) {
1164-
mp_raise_ValueError(MP_ERROR_TEXT("Buffer too small"));
1165-
}
1166-
1167-
xmr_hasher_final(&ctx, (uint8_t *)bufm.buf + offset);
1168-
memzero(&ctx, sizeof(SHA3_CTX));
1169-
return args[1];
1170-
}
1171-
}
1172-
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
1173-
mod_trezorcrypto_monero_hasher_digest_obj, 1, 3,
1174-
mod_trezorcrypto_monero_hasher_digest);
1175-
1176-
STATIC mp_obj_t mod_trezorcrypto_monero_hasher_copy(mp_obj_t self) {
1177-
mp_obj_hasher_t *o = MP_OBJ_TO_PTR(self);
1178-
mp_obj_hasher_t *cp = m_new_obj_with_finaliser(mp_obj_hasher_t);
1179-
cp->base.type = o->base.type;
1180-
memcpy(&(cp->h), &(o->h), sizeof(Hasher));
1181-
return MP_OBJ_FROM_PTR(o);
1182-
}
1183-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_monero_hasher_copy_obj,
1184-
mod_trezorcrypto_monero_hasher_copy);
1185-
11861082
//
11871083
// Type defs
11881084
//
@@ -1218,29 +1114,6 @@ STATIC const mp_obj_type_t mod_trezorcrypto_monero_bignum256modm_type = {
12181114
.locals_dict = (void *)&mod_trezorcrypto_monero_bignum256modm_locals_dict,
12191115
};
12201116

1221-
STATIC const mp_rom_map_elem_t
1222-
mod_trezorcrypto_monero_hasher_locals_dict_table[] = {
1223-
{MP_ROM_QSTR(MP_QSTR_update),
1224-
MP_ROM_PTR(&mod_trezorcrypto_monero_hasher_update_obj)},
1225-
{MP_ROM_QSTR(MP_QSTR_digest),
1226-
MP_ROM_PTR(&mod_trezorcrypto_monero_hasher_digest_obj)},
1227-
{MP_ROM_QSTR(MP_QSTR_copy),
1228-
MP_ROM_PTR(&mod_trezorcrypto_monero_hasher_copy_obj)},
1229-
{MP_ROM_QSTR(MP_QSTR___del__),
1230-
MP_ROM_PTR(&mod_trezorcrypto_monero_hasher___del___obj)},
1231-
{MP_ROM_QSTR(MP_QSTR_block_size), MP_ROM_INT(SHA3_256_BLOCK_LENGTH)},
1232-
{MP_ROM_QSTR(MP_QSTR_digest_size), MP_ROM_INT(SHA3_256_DIGEST_LENGTH)},
1233-
};
1234-
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_monero_hasher_locals_dict,
1235-
mod_trezorcrypto_monero_hasher_locals_dict_table);
1236-
1237-
STATIC const mp_obj_type_t mod_trezorcrypto_monero_hasher_type = {
1238-
{&mp_type_type},
1239-
.name = MP_QSTR_hasher,
1240-
.make_new = mod_trezorcrypto_monero_hasher_make_new,
1241-
.locals_dict = (void *)&mod_trezorcrypto_monero_hasher_locals_dict,
1242-
};
1243-
12441117
/// BP_GI_PLUS_PRE: bytes
12451118
STATIC const mp_obj_str_t mod_trezorcrypto_monero_BP_PLUS_GI_PRE_obj = {{&mp_type_bytes}, 0, 8192, (const byte*)""
12461119
"\x38\xc5\xd4\xdb\x53\xae\xb8\x6f\x5a\x80\xde\xf9\xbe\x49\x53\xf2"

core/mocks/generated/trezorcrypto/monero.pyi

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,6 @@ class Scalar:
2424
"""
2525

2626

27-
# upymod/modtrezorcrypto/modtrezorcrypto-monero.h
28-
class Hasher:
29-
"""
30-
XMR hasher
31-
"""
32-
def __init__(self, x: AnyBytes | None = None):
33-
"""
34-
Constructor
35-
"""
36-
def update(self, buffer: AnyBytes) -> None:
37-
"""
38-
Update hasher
39-
"""
40-
def digest(self) -> bytes:
41-
"""
42-
Computes digest
43-
"""
44-
def copy(self) -> Hasher:
45-
"""
46-
Creates copy of the hasher, preserving the state
47-
"""
48-
49-
5027
# upymod/modtrezorcrypto/modtrezorcrypto-monero.h
5128
def sc_copy(
5229
dst: Scalar | None, val: int | bytes | Scalar

crypto/monero/xmr.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,6 @@ void xmr_fast_hash(uint8_t *hash, const void *data, size_t length) {
3030
hasher_Raw(HASHER_SHA3K, data, length, hash);
3131
}
3232

33-
void xmr_hasher_init(Hasher *hasher) { hasher_Init(hasher, HASHER_SHA3K); }
34-
35-
void xmr_hasher_update(Hasher *hasher, const void *data, size_t length) {
36-
hasher_Update(hasher, data, length);
37-
}
38-
39-
void xmr_hasher_final(Hasher *hasher, uint8_t *hash) {
40-
hasher_Final(hasher, hash);
41-
}
42-
43-
void xmr_hasher_copy(Hasher *dst, const Hasher *src) {
44-
memcpy(dst, src, sizeof(Hasher));
45-
}
46-
4733
void xmr_hash_to_scalar(bignum256modm r, const void *data, size_t length) {
4834
uint8_t hash[HASHER_DIGEST_LENGTH] = {0};
4935
hasher_Raw(HASHER_SHA3K, data, length, hash);

crypto/monero/xmr.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ void xmr_random_scalar(bignum256modm m);
2626
/* cn_fast_hash */
2727
void xmr_fast_hash(uint8_t *hash, const void *data, size_t length);
2828

29-
/* incremental hashing wrappers */
30-
void xmr_hasher_init(Hasher *hasher);
31-
void xmr_hasher_update(Hasher *hasher, const void *data, size_t length);
32-
void xmr_hasher_final(Hasher *hasher, uint8_t *hash);
33-
void xmr_hasher_copy(Hasher *dst, const Hasher *src);
34-
3529
/* H_s(buffer) */
3630
void xmr_hash_to_scalar(bignum256modm r, const void *data, size_t length);
3731

crypto/tests/test_check.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12045,7 +12045,6 @@ Suite *test_suite(void) {
1204512045
tcase_add_test(tc, test_xmr_check_point);
1204612046
tcase_add_test(tc, test_xmr_h);
1204712047
tcase_add_test(tc, test_xmr_fast_hash);
12048-
tcase_add_test(tc, test_xmr_hasher);
1204912048
tcase_add_test(tc, test_xmr_hash_to_scalar);
1205012049
tcase_add_test(tc, test_xmr_hash_to_ec);
1205112050
tcase_add_test(tc, test_xmr_derivation_to_scalar);

crypto/tests/test_check_monero.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -640,35 +640,6 @@ START_TEST(test_xmr_fast_hash) {
640640
}
641641
END_TEST
642642

643-
START_TEST(test_xmr_hasher) {
644-
Hasher hasher;
645-
uint8_t hash[32];
646-
647-
static const struct {
648-
char *chunk[3];
649-
char *hash;
650-
} tests[] = {
651-
{{"00", "01", "02"},
652-
"f84a97f1f0a956e738abd85c2e0a5026f8874e3ec09c8f012159dfeeaab2b156"},
653-
{{"001122334455667788", "00", ""},
654-
"72a228ee8d0d01c815f112ce315cfc215a0594abcec24162304ae0ffda139d9e"},
655-
{{"001000a93e0e6937b4feaf079e418a028ca85459aa39ac3871b94076f88ca608", "",
656-
"00112233445566"},
657-
"c3deafd96ff10cc190c6024548c344f6401cfe5151ab2fcd40df7cc501147e01"},
658-
};
659-
660-
for (size_t i = 0; i < (sizeof(tests) / sizeof(*tests)); i++) {
661-
xmr_hasher_init(&hasher);
662-
for (int j = 0; j < 3; j++) {
663-
xmr_hasher_update(&hasher, fromhex(tests[i].chunk[j]),
664-
strlen(tests[i].chunk[j]) / 2);
665-
}
666-
xmr_hasher_final(&hasher, hash);
667-
ck_assert_mem_eq(hash, fromhex(tests[i].hash), 32);
668-
}
669-
}
670-
END_TEST
671-
672643
START_TEST(test_xmr_hash_to_scalar) {
673644
bignum256modm a1;
674645
unsigned char out[32];

0 commit comments

Comments
 (0)