keystore: move keystore_get_bip39_word_stack out of keystore.c
What changed, and why it matters
This commit simply moves a helper function that looks up a BIP39 word by its index from one source file to another. The function's behavior and the callers' logic are unchanged; it is a code cleanup with no security impact.
No action required; this is a benign refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change removes keystore_get_bip39_word_stack() from src/keystore.c/keystore.h and adds an equivalent static helper _get_bip39_word_stack() in src/ui/components/trinary_input_string.c, which is the only consumer. The implementation still delegates to rust_get_bip39_word() with the same rust_util_bytes_mut() wrapping. No functional, interface, or security boundary changes are present.
Changed components
src/keystore.csrc/keystore.hsrc/ui/components/trinary_input_string.cInspect captured patch +12 / −19
diff --git a/src/keystore.c b/src/keystore.c
index 2f10fd5..1ca9557 100644
--- a/src/keystore.c
+++ b/src/keystore.c
@@ -24,14 +24,8 @@
#include "util.h"
#include <usb/usb_processing.h>
-#include <rust/rust.h>
#include <secp256k1_ecdsa_s2c.h>
-bool keystore_get_bip39_word_stack(uint16_t idx, char* word_out, size_t word_out_size)
-{
- return rust_get_bip39_word(idx, rust_util_bytes_mut((uint8_t*)word_out, word_out_size));
-}
-
bool keystore_secp256k1_nonce_commit(
const secp256k1_context* ctx,
const uint8_t* private_key,
diff --git a/src/keystore.h b/src/keystore.h
index 99a4a29..4773062 100644
--- a/src/keystore.h
+++ b/src/keystore.h
@@ -28,11 +28,6 @@
// Max. length of an xpub string, including the null terminator.
#define XPUB_ENCODED_LEN 113
-/**
- * Retrieves the BIP39 word by index. `word_out` should be of at least 9 bytes long.
- */
-USE_RESULT bool keystore_get_bip39_word_stack(uint16_t idx, char* word_out, size_t word_out_size);
-
/**
* Get a commitment to the original nonce before tweaking it with the host nonce. This is part of
* the ECDSA Anti-Klepto Protocol. For more details, check the docs of
diff --git a/src/ui/components/trinary_input_string.c b/src/ui/components/trinary_input_string.c
index 43de3fd..297d1d5 100644
--- a/src/ui/components/trinary_input_string.c
+++ b/src/ui/components/trinary_input_string.c
@@ -21,7 +21,7 @@
#include "trinary_input_char.h"
#include <hardfault.h>
-#include <keystore.h>
+#include <rust/rust.h>
#include <screen.h>
#include <touch/gestures.h>
#include <ui/event.h>
@@ -61,6 +61,11 @@ static char _special_chars[] = " !\"#$%&'()*+,-./:;<=>?^[\\]@_{|}";
static const UG_FONT* _font = &font_password_11X12;
+static bool _get_bip39_word_stack(uint16_t idx, char* word_out, size_t word_out_size)
+{
+ return rust_get_bip39_word(idx, rust_util_bytes_mut((uint8_t*)word_out, word_out_size));
+}
+
typedef struct {
// Can be NULL.
const uint16_t* wordlist;
@@ -289,8 +294,8 @@ static void _set_alphabet(component_t* trinary_input_string, bool maybe_autocomp
char charset[27] = {0};
for (size_t word_idx = 0; word_idx < data->wordlist_size; word_idx++) {
char word[10];
- if (!keystore_get_bip39_word_stack(data->wordlist[word_idx], word, sizeof(word))) {
- Abort("keystore_get_bip39_word_stack");
+ if (!_get_bip39_word_stack(data->wordlist[word_idx], word, sizeof(word))) {
+ Abort("_get_bip39_word_stack");
}
if (STREQ(word, data->string)) {
@@ -317,9 +322,8 @@ static void _set_alphabet(component_t* trinary_input_string, bool maybe_autocomp
if (maybe_autocomplete && !found_word_not_unique && found_word_idx != data->wordlist_size) {
char word[10];
- if (!keystore_get_bip39_word_stack(
- data->wordlist[found_word_idx], word, sizeof(word))) {
- Abort("keystore_get_bip39_word_stack");
+ if (!_get_bip39_word_stack(data->wordlist[found_word_idx], word, sizeof(word))) {
+ Abort("_get_bip39_word_stack");
}
data->string_index = snprintf(data->string, sizeof(data->string), "%s", word);
@@ -523,8 +527,8 @@ void trinary_input_string_set_input(component_t* trinary_input_string, const cha
}
for (size_t i = 0; i < data->wordlist_size; i++) {
char bip39_word[10];
- if (!keystore_get_bip39_word_stack(data->wordlist[i], bip39_word, sizeof(bip39_word))) {
- Abort("keystore_get_bip39_word_stack");
+ if (!_get_bip39_word_stack(data->wordlist[i], bip39_word, sizeof(bip39_word))) {
+ Abort("_get_bip39_word_stack");
}
if (STREQ(bip39_word, word)) {
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.