diff --git a/crates/keyfork-shard/src/lib.rs b/crates/keyfork-shard/src/lib.rs index a672951..cec7e9d 100644 --- a/crates/keyfork-shard/src/lib.rs +++ b/crates/keyfork-shard/src/lib.rs @@ -248,10 +248,9 @@ pub trait Format { // create our shared key let our_key = EphemeralSecret::random(); let our_pubkey_mnemonic = Mnemonic::from_bytes(PublicKey::from(&our_key).as_bytes())?; - let shared_secret = our_key - .diffie_hellman(&PublicKey::from(their_pubkey)) - .to_bytes(); - let hkdf = Hkdf::::new(None, &shared_secret); + let shared_secret = our_key.diffie_hellman(&PublicKey::from(their_pubkey)); + assert!(shared_secret.was_contributory(), bug!("shared secret might be insecure")); + let hkdf = Hkdf::::new(None, shared_secret.as_bytes()); let mut shared_key_data = [0u8; 256 / 8]; hkdf.expand(b"key", &mut shared_key_data)?; @@ -515,8 +514,9 @@ pub fn remote_decrypt(w: &mut impl Write) -> Result<(), Box::new(None, &shared_secret); + let shared_secret = our_key.diffie_hellman(&PublicKey::from(pubkey)); + assert!(shared_secret.was_contributory(), bug!("shared secret might be insecure")); + let hkdf = Hkdf::::new(None, shared_secret.as_bytes()); let mut shared_key_data = [0u8; 256 / 8]; hkdf.expand(b"key", &mut shared_key_data)?;