Skip to content

Conversation

@benma
Copy link
Collaborator

@benma benma commented Dec 18, 2025

All functions in it are unrelated to the keystore.

@benma benma requested review from cedwies and removed request for cedwies December 18, 2025 15:42
@benma benma marked this pull request as draft December 18, 2025 15:50
@benma benma requested a review from cedwies December 18, 2025 16:15
@benma benma marked this pull request as ready for review December 18, 2025 16:15
let mut signer_commitment = [0u8; EC_PUBLIC_KEY_LEN];
match unsafe {
bitbox02_sys::keystore_secp256k1_nonce_commit(
let mut signer_commitment = MaybeUninit::<bitbox02_sys::secp256k1_ecdsa_s2c_opening>::uninit();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you prefer uninitialized bytes here instead of zeroed() (like earlier)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's transferred from the C impl, where there was a = {0} in the C version for this one and not the other. I don't think it matters, should I change the other to uninit() as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the other to uninit()

src/keystore.h Outdated
#define KEYSTORE_U2F_SEED_LENGTH SHA256_LEN

// Max. length of an xpub string, including the null terminator.
#define XPUB_ENCODED_LEN 113
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XPUB_ENCODED_LEN is only used in rust, migrate as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, can be removed, it's unused. Will do.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, removed it and keystore.h

src/keystore.h Outdated

#include <secp256k1.h>

#define KEYSTORE_U2F_SEED_LENGTH SHA256_LEN
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move KEYSTORE_U2F_SEED_LENGTH to rust or u2f.c?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit confusing, SHA256_LEN is defined in u2f.c, so shouldn't be available here? 🤔

I'll delete it anyway, the only use is in SHA256 functions, so we can just use 32 (like we often do in hashing), or SHA256_LEN in u2f.c.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, removed keystore.h

benma's agent and others added 6 commits December 20, 2025 21:09
Fix undefined secp256k1_* symbols when linking firmware. These errors
would happen if keystore.c stops referencing the secp256k1
symbols (see later commit).

We link libsecp256k1 as a static archive and the linker resolves
static libs left-to-right, only pulling in objects that satisfy
currently-unresolved symbols. Since the Rust archive introduces the
secp256k1_* references, it must appear before the secp256k1 library on
the link line (otherwise the linker scans secp256k1 too early and
doesn't pull the needed objects).
They are not related to the keystore. The keystore.c functions they
use will be dealt with in the next commit.
The two remaning functions are unrelated to keystore, and inlined into
the Rust C wrappers of secp256k1.
Copy link
Collaborator

@cedwies cedwies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found no major issues. Nice refactoring. Please consider my comments.

}

/// Length of a compressed secp256k1 pubkey.
const EC_PUBLIC_KEY_LEN: usize = 33;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you not using bitbox02::secp256k1::EC_PUBLIC_KEY_LEN here? Why did you choose the duplicate value?

///
/// # Returns
/// * `Ok(SignResult)` containing signature in compact format and recoverable id on success
/// * `Err(())` if the keystore is locked
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc was moved, but I think this line is incorrect. Does this fn even look at "keystore locked"? Isn't this checked before this fn runs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants