Skip to content

Commit

Permalink
key: Improve docs
Browse files Browse the repository at this point in the history
Crypto is _hard_. Make an effort to improve the docs with a minimum of
exactly correct information.
  • Loading branch information
tcharding committed Aug 11, 2023
1 parent 14e8218 commit 037860c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ use crate::{ecdsa, SECP256K1};
#[cfg(feature = "bitcoin_hashes")]
use crate::{hashes, ThirtyTwoByteHash};

/// Secret 256-bit key used as `x` in an ECDSA signature.
/// Secret key - a 256-bit key used to create ECDSA and schnorr signatures.
///
/// A point on the secp256k1 curve i.e., a positive 256-bit integer guaranteed to be less than the
/// secp256k1 curve order.
///
/// This value should be generated using a [cryptographically secure pseudorandom number generator].
///
/// # Side channel attacks
///
Expand Down Expand Up @@ -48,6 +53,7 @@ use crate::{hashes, ThirtyTwoByteHash};
/// ```
/// [`bincode`]: https://docs.rs/bincode
/// [`cbor`]: https://docs.rs/cbor
/// [cryptographically secure pseudorandom number generator]: https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator
#[derive(Copy, Clone)]
pub struct SecretKey([u8; constants::SECRET_KEY_SIZE]);
impl_display_secret!(SecretKey);
Expand Down Expand Up @@ -115,7 +121,9 @@ impl str::FromStr for SecretKey {
}
}

/// A Secp256k1 public key, used for verification of signatures.
/// Public key - a point on the secp256k1 curve.
///
/// Obtained by multiplying a secret key scalar by G (the generator point).
///
/// # Serde support
///
Expand Down Expand Up @@ -1070,7 +1078,10 @@ impl CPtr for KeyPair {
fn as_mut_c_ptr(&mut self) -> *mut Self::Target { &mut self.0 }
}

/// An x-only public key, used for verification of schnorr signatures and serialized according to BIP-340.
/// An x-only public key - the X co-ordinate of a point on the secp256k1 curve.
///
/// To convert to a point (`PublicKey`) one must choose the [`Parity`] of the Y co-ordinate. When
/// used to create schnorr signatures the Y co-ordinate is always positive.
///
/// # Serde support
///
Expand Down

0 comments on commit 037860c

Please sign in to comment.