What changed, and why it matters
This commit is a routine code cleanup. It removes a locally defined constant for compressed secp256k1 public key size (33 bytes) and replaces it with an equivalent constant already provided by the upstream Rust bitcoin/secp256k1 library. The numeric value and behavior remain exactly the same.
No security action required. Review as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change removes the local EC_PUBLIC_KEY_LEN constant (value 33) and the corresponding C-bindgen allowlist entry, replacing usages with bitcoin::secp256k1::constants::PUBLIC_KEY_SIZE. The constant value is identical, so array sizes, serialization buffers, and return types are unchanged. No cryptographic logic, memory handling, or API behavior is modified.
Changed components
src/rust/bitbox02-rust/src/secp256k1.rssrc/rust/bitbox02-sys/build.rssrc/rust/bitbox02/src/secp256k1.rsInspect captured patch +7 / −11
diff --git a/src/rust/bitbox02-rust/src/secp256k1.rs b/src/rust/bitbox02-rust/src/secp256k1.rs
index 99be685..fc992d8 100644
--- a/src/rust/bitbox02-rust/src/secp256k1.rs
+++ b/src/rust/bitbox02-rust/src/secp256k1.rs
@@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+pub use bitcoin::secp256k1::constants::PUBLIC_KEY_SIZE;
use bitcoin::secp256k1::{All, Secp256k1};
+
use core::cell::OnceCell;
use core::ops::Deref;
@@ -46,9 +48,6 @@ impl Deref for GlobalContext {
}
}
-/// Length of a compressed secp256k1 pubkey.
-const EC_PUBLIC_KEY_LEN: usize = 33;
-
/// Sign message with private key using the given private key.
///
/// Details about `host_nonce`, the host nonce contribution. Instead of using plain rfc6979 to
@@ -91,13 +90,13 @@ pub fn secp256k1_sign(
/// host_nonce is passed to `secp256k1_sign()`. See `secp256k1_ecdsa_anti_exfil_host_commit()`.
///
/// # Returns
-/// * `Ok([u8; EC_PUBLIC_KEY_LEN])` - EC_PUBLIC_KEY_LEN bytes compressed signer nonce pubkey on success
+/// * `Ok([u8; PUBLIC_KEY_SIZE])` - PUBLIC_KEY_SIZE bytes compressed signer nonce pubkey on success
/// * `Err(())` on failure
pub fn secp256k1_nonce_commit(
private_key: &[u8; 32],
msg: &[u8; 32],
host_commitment: &[u8; 32],
-) -> Result<[u8; EC_PUBLIC_KEY_LEN], ()> {
+) -> Result<[u8; PUBLIC_KEY_SIZE], ()> {
bitbox02::secp256k1::_secp256k1_nonce_commit(SECP256K1, private_key, msg, host_commitment)
}
diff --git a/src/rust/bitbox02-sys/build.rs b/src/rust/bitbox02-sys/build.rs
index 1b95113..f80e02a 100644
--- a/src/rust/bitbox02-sys/build.rs
+++ b/src/rust/bitbox02-sys/build.rs
@@ -21,7 +21,6 @@ const ALLOWLIST_VARS: &[&str] = &[
"BASE58_CHECKSUM_LEN",
"BIP32_SERIALIZED_LEN",
"BIP39_WORDLIST_LEN",
- "EC_PUBLIC_KEY_LEN",
"font_font_a_11X10",
"font_font_a_9X9",
"font_monogram_5X9",
diff --git a/src/rust/bitbox02/src/secp256k1.rs b/src/rust/bitbox02/src/secp256k1.rs
index 5138961..8a151ba 100644
--- a/src/rust/bitbox02/src/secp256k1.rs
+++ b/src/rust/bitbox02/src/secp256k1.rs
@@ -14,14 +14,12 @@
use bitcoin::secp256k1::ffi::CPtr;
+pub use bitcoin::secp256k1::constants::PUBLIC_KEY_SIZE;
use bitcoin::secp256k1::{All, Secp256k1};
use alloc::vec::Vec;
use core::mem::MaybeUninit;
-/// Length of a compressed secp256k1 pubkey.
-pub const EC_PUBLIC_KEY_LEN: usize = 33;
-
pub struct SignResult {
pub signature: [u8; 64],
pub recid: u8,
@@ -71,7 +69,7 @@ pub fn _secp256k1_nonce_commit(
private_key: &[u8; 32],
msg: &[u8; 32],
host_commitment: &[u8; 32],
-) -> Result<[u8; EC_PUBLIC_KEY_LEN], ()> {
+) -> Result<[u8; PUBLIC_KEY_SIZE], ()> {
let mut signer_commitment = MaybeUninit::<bitbox02_sys::secp256k1_ecdsa_s2c_opening>::uninit();
if unsafe {
bitbox02_sys::secp256k1_ecdsa_anti_exfil_signer_commit(
@@ -86,7 +84,7 @@ pub fn _secp256k1_nonce_commit(
return Err(());
}
- let mut out = [0u8; EC_PUBLIC_KEY_LEN];
+ let mut out = [0u8; PUBLIC_KEY_SIZE];
if unsafe {
bitbox02_sys::secp256k1_ecdsa_s2c_opening_serialize(
secp.ctx().as_ptr().cast(),
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.