From 4b143d6f9c4703a98f90164204bf0e7ae40bb32d Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 23 Aug 2024 09:18:21 +1000 Subject: [PATCH 1/2] Remove bitcoin_hashes range dependency In order correctly truncate the secret data we need to use recent version of `bitcoin_hashes`. Remove the range dependency and update the lock files. --- Cargo-minimal.lock | 25 +++++++++++++++++-------- Cargo-recent.lock | 25 +++++++++++++++++-------- Cargo.toml | 2 +- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Cargo-minimal.lock b/Cargo-minimal.lock index 47c84b0f6..e4185fdec 100644 --- a/Cargo-minimal.lock +++ b/Cargo-minimal.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "base-x" version = "0.2.0" @@ -18,18 +24,18 @@ dependencies = [ ] [[package]] -name = "bitcoin-internals" -version = "0.2.0" +name = "bitcoin-io" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb" +checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" [[package]] name = "bitcoin_hashes" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" dependencies = [ - "bitcoin-internals", + "bitcoin-io", "hex-conservative", ] @@ -106,9 +112,12 @@ checksum = "ee6c0438de3ca4d8cac2eec62b228e2f8865cfe9ebefea720406774223fa2d2e" [[package]] name = "hex-conservative" -version = "0.1.1" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", +] [[package]] name = "hex_lit" diff --git a/Cargo-recent.lock b/Cargo-recent.lock index f8977942f..d42ca3b17 100644 --- a/Cargo-recent.lock +++ b/Cargo-recent.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "bincode" version = "1.3.3" @@ -12,18 +18,18 @@ dependencies = [ ] [[package]] -name = "bitcoin-internals" -version = "0.2.0" +name = "bitcoin-io" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb" +checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" [[package]] name = "bitcoin_hashes" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" dependencies = [ - "bitcoin-internals", + "bitcoin-io", "hex-conservative", ] @@ -82,9 +88,12 @@ checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" [[package]] name = "hex-conservative" -version = "0.1.1" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", +] [[package]] name = "hex_lit" diff --git a/Cargo.toml b/Cargo.toml index d036b229e..59268c125 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ global-context-less-secure = ["global-context"] secp256k1-sys = { version = "0.10.0", default-features = false, path = "./secp256k1-sys" } serde = { version = "1.0.103", default-features = false, optional = true } -hashes = { package = "bitcoin_hashes", version = ">= 0.12, <= 0.14", default-features = false, optional = true } +hashes = { package = "bitcoin_hashes", version = "0.14", default-features = false, optional = true } rand = { version = "0.8", default-features = false, optional = true } [dev-dependencies] From 3d1ce0d261c39a011616f8495d80ecbd0ca006e0 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 22 Aug 2024 12:07:29 +1000 Subject: [PATCH 2/2] Truncate secret hash using precision Currently we are attempting to truncate the hash created using `bitcoin_hashes` by using the "width" formatting parameter instead of the "precision" parameter. `hex-conservative` truncates with the "precision" parameter as is expected since a hash is not an integral type. Use the formatting string `"{:.16}"` which is the "precision" formatting parameter. --- src/secret.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/secret.rs b/src/secret.rs index f13d91ae9..49323dd27 100644 --- a/src/secret.rs +++ b/src/secret.rs @@ -46,7 +46,7 @@ macro_rules! impl_display_secret { engine.input(&self.secret_bytes()); let hash = sha256::Hash::from_engine(engine); - f.debug_tuple(stringify!($thing)).field(&format_args!("#{:016x}", hash)).finish() + f.debug_tuple(stringify!($thing)).field(&format_args!("#{:.16}", hash)).finish() } }