mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-02-10 08:53:08 +00:00
27 lines
609 B
Rust
27 lines
609 B
Rust
|
|
use rand_core::OsRng;
|
||
|
|
use x25519_dalek::{PublicKey, StaticSecret};
|
||
|
|
|
||
|
|
use crate::types::SharedSecret;
|
||
|
|
|
||
|
|
#[derive(Clone)]
|
||
|
|
pub struct InstallationKeyPair {
|
||
|
|
secret: StaticSecret,
|
||
|
|
public: PublicKey,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl InstallationKeyPair {
|
||
|
|
pub fn generate() -> Self {
|
||
|
|
let secret = StaticSecret::random_from_rng(OsRng);
|
||
|
|
let public = PublicKey::from(&secret);
|
||
|
|
Self { secret, public }
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn dh(&self, their_public: &PublicKey) -> SharedSecret {
|
||
|
|
self.secret.diffie_hellman(their_public).to_bytes()
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn public(&self) -> &PublicKey {
|
||
|
|
&self.public
|
||
|
|
}
|
||
|
|
}
|