Struct bdk_chain::bitcoin::secp256k1::ecdh::SharedSecret
pub struct SharedSecret(/* private fields */);
Expand description
Enables two parties to create a shared secret without revealing their own secrets.
§Examples
let s = Secp256k1::new();
let (sk1, pk1) = s.generate_keypair(&mut rand::thread_rng());
let (sk2, pk2) = s.generate_keypair(&mut rand::thread_rng());
let sec1 = SharedSecret::new(&pk2, &sk1);
let sec2 = SharedSecret::new(&pk1, &sk2);
assert_eq!(sec1, sec2);
Implementations§
pub fn display_secret(&self) -> DisplaySecret
pub fn display_secret(&self) -> DisplaySecret
Formats the explicit byte value of the shared secret kept inside the type as a little-endian hexadecimal string using the provided formatter.
This is the only method that outputs the actual shared secret value, and, thus, should be used with extreme caution.
§Examples
use secp256k1::{SecretKey, PublicKey};
use secp256k1::ecdh::SharedSecret;
let secret = SharedSecret::new(&pk, &sk);
// Here we explicitly display the secret value:
assert_eq!(
format!("{}", secret.display_secret()),
"cf05ae7da039ddce6d56dd57d3000c6dd91c6f1695eae47e05389f11e2467043"
);
// Also, we can explicitly display with `Debug`:
assert_eq!(
format!("{:?}", secret.display_secret()),
format!("DisplaySecret(\"{}\")", secret.display_secret())
);
pub fn non_secure_erase(&mut self)
pub fn non_secure_erase(&mut self)
Attempts to erase the contents of the underlying array.
Note, however, that the compiler is allowed to freely copy or move the
contents of this array to other places in memory. Preventing this behavior
is very subtle. For more discussion on this, please see the documentation
of the zeroize
crate.
pub fn new(point: &PublicKey, scalar: &SecretKey) -> SharedSecret
pub fn new(point: &PublicKey, scalar: &SecretKey) -> SharedSecret
Creates a new shared secret from a pubkey and secret key.
pub fn secret_bytes(&self) -> [u8; 32]
pub fn secret_bytes(&self) -> [u8; 32]
Returns the shared secret as a byte value.
pub fn from_bytes(bytes: [u8; 32]) -> SharedSecret
pub fn from_bytes(bytes: [u8; 32]) -> SharedSecret
Creates a shared secret from bytes
array.
pub fn from_slice(bytes: &[u8]) -> Result<SharedSecret, Error>
pub fn from_slice(bytes: &[u8]) -> Result<SharedSecret, Error>
Creates a shared secret from bytes
slice.
Trait Implementations§
§fn clone(&self) -> SharedSecret
fn clone(&self) -> SharedSecret
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§fn deserialize<D>(d: D) -> Result<SharedSecret, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(d: D) -> Result<SharedSecret, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
§fn eq(&self, other: &SharedSecret) -> bool
fn eq(&self, other: &SharedSecret) -> bool
self
and other
values to be equal, and is used
by ==
.§fn partial_cmp(&self, other: &SharedSecret) -> Option<Ordering>
fn partial_cmp(&self, other: &SharedSecret) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more