Skip to content

Conversation

@apoelstra
Copy link
Member

@apoelstra apoelstra commented Aug 26, 2024

In addition to changing SecretKey and SharedSecret to use hashes, we also unconditionally use the public half of KeyPair as a fingerprint, since that's always available and does not need extra deps.

This patches the existing unit tests but doesn't add more. Maybe they should be removed; it's a bit weird to have unit tests for Debug output. But in this case we're doing some nontrivial logic and I guess we wanted to double-check that it was taking effect.

I'd also like to change the manual tagged-hash implementation to use bitcoin_hashes methods but those are under construction rust-bitcoin/rust-bitcoin#3184 and the existing stuff is neither faster nor less code than what's currently done. So we'll live with it.

Fixes #725

@tcharding
Copy link
Member

conceptACK. You missed setting the PR title.

@apoelstra apoelstra changed the title 2024 08 no hasher key: don't use Hasher to generate fingerprints; just use hashes crate Aug 26, 2024
There is no need to hash up the secret for Keypair. It already has a
"fingerprint" in the form of its public key. We should just use that.
@apoelstra
Copy link
Member Author

CI failure looks like some unrelated xargo thing. We definitely gotta start pinning nightly here.

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK b8ac971

I agree with having Debug tests in cases like this since failing to implement it correctly may lead to key leaks.

fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
f.debug_struct("Keypair")
.field("pubkey", &self.public_key())
.field("secret", &"<hidden>")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good idea.

Copy link
Member Author

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

Successfully ran local tests on b8ac971.

@apoelstra apoelstra merged commit fb188dd into rust-bitcoin:master Aug 26, 2024
@apoelstra apoelstra deleted the 2024-08--no-hasher branch August 26, 2024 18:58
chain-forgexcr45 added a commit to chain-forgexcr45/rust-secp256k1 that referenced this pull request Sep 28, 2025
…erate fingerprints; just use `hashes` crate

b8ac97174541b8341b67f8566d64406154b6c5e4 keypair: use public key for Debug output (Andrew Poelstra)
a16e5ecd49a994fd32fe69bcf0666a654ae66581 secret keys: debug output only when `hashes` is enabled (Andrew Poelstra)

Pull request description:

  In addition to changing `SecretKey` and `SharedSecret` to use `hashes`, we also unconditionally use the public half of `KeyPair` as a fingerprint, since that's always available and does not need extra deps.

  This patches the existing unit tests but doesn't add more. Maybe they should be removed; it's a bit weird to have unit tests for `Debug` output. But in this case we're doing some nontrivial logic and I guess we wanted to double-check that it was taking effect.

  I'd also like to change the manual tagged-hash implementation to use `bitcoin_hashes` methods but those are under construction rust-bitcoin/rust-bitcoin#3184 and the existing stuff is neither faster nor less code than what's currently done. So we'll live with it.

  Fixes #725

ACKs for top commit:
  Kixunil:
    ACK b8ac97174541b8341b67f8566d64406154b6c5e4

Tree-SHA512: d0a65e0a0069bcbc663c1d3e7f98b75868355c4db48e9a9c905cdcd2af1606ac86090cdf0aae5caa23337c5d565e6420d7c956dd0a65a1877004840075bc08e9
william2332-limf added a commit to william2332-limf/rust-secp256k1 that referenced this pull request Oct 2, 2025
…erate fingerprints; just use `hashes` crate

b8ac97174541b8341b67f8566d64406154b6c5e4 keypair: use public key for Debug output (Andrew Poelstra)
a16e5ecd49a994fd32fe69bcf0666a654ae66581 secret keys: debug output only when `hashes` is enabled (Andrew Poelstra)

Pull request description:

  In addition to changing `SecretKey` and `SharedSecret` to use `hashes`, we also unconditionally use the public half of `KeyPair` as a fingerprint, since that's always available and does not need extra deps.

  This patches the existing unit tests but doesn't add more. Maybe they should be removed; it's a bit weird to have unit tests for `Debug` output. But in this case we're doing some nontrivial logic and I guess we wanted to double-check that it was taking effect.

  I'd also like to change the manual tagged-hash implementation to use `bitcoin_hashes` methods but those are under construction rust-bitcoin/rust-bitcoin#3184 and the existing stuff is neither faster nor less code than what's currently done. So we'll live with it.

  Fixes #725

ACKs for top commit:
  Kixunil:
    ACK b8ac97174541b8341b67f8566d64406154b6c5e4

Tree-SHA512: d0a65e0a0069bcbc663c1d3e7f98b75868355c4db48e9a9c905cdcd2af1606ac86090cdf0aae5caa23337c5d565e6420d7c956dd0a65a1877004840075bc08e9
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.

Don't use std's siphash to produce secret key fingerprints

3 participants