chore(core): remove sha1 from regular FW
What changed, and why it matters
This commit removes the SHA-1 hashing function from the regular Trezor firmware. SHA-1 is an old, weak hash algorithm that is no longer considered secure for sensitive uses. The change deletes the code that exposes SHA-1 to apps running on the device, along with related tests and benchmarks. It is a hardening/cleanup change rather than a fix for an active bug or exploit.
Treat as a positive hardening change. Verify that no remaining firmware code paths still require SHA-1 (e.g., legacy protocols, HMAC-SHA1, PBKDF2-HMAC-SHA1, or bootloader/recovery flows) and that the underlying C SHA-1 implementation is also excluded from regular firmware builds if intended. Review downstream apps for any dependency on hashlib.sha1.
Security signals we found
Removal of a deprecated cryptographic primitive (SHA-1) from the firmware API surface
Reduction of attack surface and prevention of future misuse of a collision-vulnerable hash
No direct vulnerability patch or memory-safety bug is present in the diff
Evidence from the diff
The commit deletes the MicroPython binding for SHA-1 (modtrezorcrypto-sha1.h), removes sha1 from the trezorcrypto module’s globals table, drops it from the Python hashlib wrapper, and removes the benchmark and unit tests. The C library implementation (sha2.h / sha1_*) is not shown being removed here, only the firmware-facing Python API. The commit message frames this as ‘remove sha1 from regular FW’ with no changelog entry.
Changed components
core/embed/upymod/modtrezorcryptocore/src/trezor/crypto/hashlib.pycore/src/apps/benchmark/benchmarks.pycore/tests/test_trezor.crypto.hashlib.sha1.pyInspect captured patch +0 / −200
diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha1.h b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha1.h
deleted file mode 100644
index c3104d80..00000000
--- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto-sha1.h
+++ /dev/null
@@ -1,116 +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 "memzero.h"
-#include "sha2.h"
-
-/// package: trezorcrypto.__init__
-
-/// class sha1:
-/// """
-/// SHA1 context.
-/// """
-/// block_size: int
-/// digest_size: int
-typedef struct _mp_obj_Sha1_t {
- mp_obj_base_t base;
- SHA1_CTX ctx;
-} mp_obj_Sha1_t;
-
-static mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data);
-
-/// def __init__(self, __data: StrOrBytes | None = None) -> None:
-/// """
-/// Creates a hash context object.
-/// """
-static mp_obj_t mod_trezorcrypto_Sha1_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_Sha1_t *o = mp_obj_malloc_with_finaliser(mp_obj_Sha1_t, type);
- sha1_Init(&(o->ctx));
- // constructor called with bytes/str as first parameter
- if (n_args == 1) {
- mod_trezorcrypto_Sha1_update(MP_OBJ_FROM_PTR(o), args[0]);
- }
- return MP_OBJ_FROM_PTR(o);
-}
-
-/// def update(self, __data: StrOrBytes) -> None:
-/// """
-/// Update the hash context with hashed data.
-/// """
-static mp_obj_t mod_trezorcrypto_Sha1_update(mp_obj_t self, mp_obj_t data) {
- mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self);
- mp_buffer_info_t msg = {0};
- mp_get_buffer_raise(data, &msg, MP_BUFFER_READ);
- if (msg.len > 0) {
- sha1_Update(&(o->ctx), msg.buf, msg.len);
- }
- return mp_const_none;
-}
-static MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_Sha1_update_obj,
- mod_trezorcrypto_Sha1_update);
-
-/// def digest(self) -> bytes:
-/// """
-/// Returns the digest of hashed data.
-/// """
-static mp_obj_t mod_trezorcrypto_Sha1_digest(mp_obj_t self) {
- mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self);
- vstr_t hash = {0};
- vstr_init_len(&hash, SHA1_DIGEST_LENGTH);
- SHA1_CTX ctx = {0};
- memcpy(&ctx, &(o->ctx), sizeof(SHA1_CTX));
- sha1_Final(&ctx, (uint8_t *)hash.buf);
- memzero(&ctx, sizeof(SHA1_CTX));
- return mp_obj_new_bytes_from_vstr(&hash);
-}
-static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha1_digest_obj,
- mod_trezorcrypto_Sha1_digest);
-
-static mp_obj_t mod_trezorcrypto_Sha1___del__(mp_obj_t self) {
- mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self);
- memzero(&(o->ctx), sizeof(SHA1_CTX));
- return mp_const_none;
-}
-static MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha1___del___obj,
- mod_trezorcrypto_Sha1___del__);
-
-static const mp_rom_map_elem_t mod_trezorcrypto_Sha1_locals_dict_table[] = {
- {MP_ROM_QSTR(MP_QSTR_update),
- MP_ROM_PTR(&mod_trezorcrypto_Sha1_update_obj)},
- {MP_ROM_QSTR(MP_QSTR_digest),
- MP_ROM_PTR(&mod_trezorcrypto_Sha1_digest_obj)},
- {MP_ROM_QSTR(MP_QSTR___del__),
- MP_ROM_PTR(&mod_trezorcrypto_Sha1___del___obj)},
- {MP_ROM_QSTR(MP_QSTR_block_size), MP_ROM_INT(SHA1_BLOCK_LENGTH)},
- {MP_ROM_QSTR(MP_QSTR_digest_size), MP_ROM_INT(SHA1_DIGEST_LENGTH)},
-};
-static MP_DEFINE_CONST_DICT(mod_trezorcrypto_Sha1_locals_dict,
- mod_trezorcrypto_Sha1_locals_dict_table);
-
-// clang-format off
-static MP_DEFINE_CONST_OBJ_TYPE(mod_trezorcrypto_Sha1_type,
- MP_QSTR_Sha1, MP_TYPE_FLAG_NONE,
- make_new, mod_trezorcrypto_Sha1_make_new,
- locals_dict, &mod_trezorcrypto_Sha1_locals_dict);
-// clang-format on
diff --git a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto.c b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto.c
index 82edf4e8..ceb7f1b9 100644
--- a/core/embed/upymod/modtrezorcrypto/modtrezorcrypto.c
+++ b/core/embed/upymod/modtrezorcrypto/modtrezorcrypto.c
@@ -59,7 +59,6 @@ static void wrapped_ui_wait_callback(uint32_t current, uint32_t total) {
#include "modtrezorcrypto-random.h"
#include "modtrezorcrypto-ripemd160.h"
#include "modtrezorcrypto-secp256k1.h"
-#include "modtrezorcrypto-sha1.h"
#include "modtrezorcrypto-sha256.h"
#include "modtrezorcrypto-sha3-256.h"
#include "modtrezorcrypto-sha3-512.h"
@@ -138,7 +137,6 @@ static const mp_rom_map_elem_t mp_module_trezorcrypto_globals_table[] = {
#if USE_SECP256K1_ZKP
{MP_ROM_QSTR(MP_QSTR_bip340), MP_ROM_PTR(&mod_trezorcrypto_bip340_module)},
#endif
- {MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&mod_trezorcrypto_Sha1_type)},
{MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&mod_trezorcrypto_Sha256_type)},
{MP_ROM_QSTR(MP_QSTR_sha512), MP_ROM_PTR(&mod_trezorcrypto_Sha512_type)},
{MP_ROM_QSTR(MP_QSTR_sha3_256),
diff --git a/core/mocks/generated/trezorcrypto/__init__.pyi b/core/mocks/generated/trezorcrypto/__init__.pyi
index 4d408118..72758871 100644
--- a/core/mocks/generated/trezorcrypto/__init__.pyi
+++ b/core/mocks/generated/trezorcrypto/__init__.pyi
@@ -373,30 +373,6 @@ class ripemd160:
"""
-# upymod/modtrezorcrypto/modtrezorcrypto-sha1.h
-class sha1:
- """
- SHA1 context.
- """
- block_size: int
- digest_size: int
-
- def __init__(self, __data: StrOrBytes | None = None) -> None:
- """
- Creates a hash context object.
- """
-
- def update(self, __data: StrOrBytes) -> None:
- """
- Update the hash context with hashed data.
- """
-
- def digest(self) -> bytes:
- """
- Returns the digest of hashed data.
- """
-
-
# upymod/modtrezorcrypto/modtrezorcrypto-sha256.h
class sha256:
"""
diff --git a/core/src/apps/benchmark/benchmarks.py b/core/src/apps/benchmark/benchmarks.py
index a7ceb5d6..6c76855f 100644
--- a/core/src/apps/benchmark/benchmarks.py
+++ b/core/src/apps/benchmark/benchmarks.py
@@ -12,7 +12,6 @@ from trezor.crypto.hashlib import (
blake256,
groestl512,
ripemd160,
- sha1,
sha3_256,
sha3_512,
sha256,
@@ -57,7 +56,6 @@ benchmarks = {
"crypto/hash/blake256": HashBenchmark(lambda: blake256()),
"crypto/hash/groestl512": HashBenchmark(lambda: groestl512()),
"crypto/hash/ripemd160": HashBenchmark(lambda: ripemd160()),
- "crypto/hash/sha1": HashBenchmark(lambda: sha1()),
"crypto/hash/sha3_256": HashBenchmark(lambda: sha3_256()),
"crypto/hash/sha3_512": HashBenchmark(lambda: sha3_512()),
"crypto/hash/sha256": HashBenchmark(lambda: sha256()),
diff --git a/core/src/trezor/crypto/hashlib.py b/core/src/trezor/crypto/hashlib.py
index 388c004d..84a373d9 100644
--- a/core/src/trezor/crypto/hashlib.py
+++ b/core/src/trezor/crypto/hashlib.py
@@ -4,7 +4,6 @@ from trezorcrypto import ( # noqa: F401
blake256,
groestl512,
ripemd160,
- sha1,
sha3_256,
sha3_512,
sha256,
diff --git a/core/tests/test_trezor.crypto.hashlib.sha1.py b/core/tests/test_trezor.crypto.hashlib.sha1.py
deleted file mode 100644
index 5a290cbc..00000000
--- a/core/tests/test_trezor.crypto.hashlib.sha1.py
+++ /dev/null
@@ -1,55 +0,0 @@
-# flake8: noqa: F403,F405
-from common import * # isort:skip
-
-from trezor.crypto import hashlib
-
-
-class TestCryptoSha1(unittest.TestCase):
-
- # vectors from https://www.di-mgt.com.au/sha_testvectors.html
- vectors = [
- (b"", "da39a3ee5e6b4b0d3255bfef95601890afd80709"),
- (b"abc", "a9993e364706816aba3e25717850c26c9cd0d89d"),
- (
- b"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
- ),
- (
- b"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
- "a49b2446a02c645bf419f995b67091253a04a259",
- ),
- ]
-
- def test_digest(self):
- for b, d in self.vectors:
- self.assertEqual(hashlib.sha1(b).digest(), bytes.fromhex(d))
-
- def test_update(self):
- for b, d in self.vectors:
- x = hashlib.sha1()
- x.update(b)
- self.assertEqual(x.digest(), bytes.fromhex(d))
-
- x = hashlib.sha1()
- for _ in range(1000000):
- x.update(b"a")
- self.assertEqual(
- x.digest(), bytes.fromhex("34aa973cd4c4daa4f61eeb2bdbad27316534016f")
- )
-
- # x = hashlib.sha1()
- # for i in range(16777216):
- # x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno')
- # self.assertEqual(x.digest(), bytes.fromhex('7789f0c9ef7bfc40d93311143dfbe69e2017f592'))
-
- def test_digest_multi(self):
- x = hashlib.sha1()
- d0 = x.digest()
- d1 = x.digest()
- d2 = x.digest()
- self.assertEqual(d0, d1)
- self.assertEqual(d0, d2)
-
-
-if __name__ == "__main__":
- unittest.main()
Why this scored 18/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.