From 394d151f93126bd8302b4a6c52fc14c084678ad9 Mon Sep 17 00:00:00 2001 From: Sebastian Holmin Date: Wed, 8 Jan 2025 18:48:58 +0100 Subject: [PATCH] Spawn key pair worker on launch --- talpid-core/src/tunnel_state_machine/mod.rs | 1 + talpid-tunnel-config-client/src/classic_mceliece.rs | 6 +++--- talpid-tunnel-config-client/src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/talpid-core/src/tunnel_state_machine/mod.rs b/talpid-core/src/tunnel_state_machine/mod.rs index 6f4dc33218d2..06588392e97b 100644 --- a/talpid-core/src/tunnel_state_machine/mod.rs +++ b/talpid-core/src/tunnel_state_machine/mod.rs @@ -25,6 +25,7 @@ use talpid_routing::RouteManagerHandle; #[cfg(target_os = "macos")] use talpid_tunnel::TunnelMetadata; use talpid_tunnel::{tun_provider::TunProvider, TunnelEvent}; +use talpid_tunnel_config_client::classic_mceliece::{spawn_keypair_worker, BUFSIZE, KEYPAIR_RX}; #[cfg(target_os = "macos")] use talpid_types::ErrorExt; diff --git a/talpid-tunnel-config-client/src/classic_mceliece.rs b/talpid-tunnel-config-client/src/classic_mceliece.rs index da6024f7136d..3d29e1997c93 100644 --- a/talpid-tunnel-config-client/src/classic_mceliece.rs +++ b/talpid-tunnel-config-client/src/classic_mceliece.rs @@ -10,7 +10,7 @@ const STACK_SIZE: usize = 2 * 1024 * 1024; /// Number of McEliece key pairs to buffer. Note that, using the below algorithm, they take up around /// 537 kB each. We therefore only buffer two, which is the largest useful amount, in case of multihop. -const BUFSIZE: usize = 2; +pub const BUFSIZE: usize = 2; /// Use the smallest CME variant with NIST security level 3. This variant has significantly smaller /// keys than the larger variants, and is considered safe. @@ -18,14 +18,14 @@ pub const ALGORITHM_NAME: &str = "Classic-McEliece-460896f-round3"; type KeyPair = (PublicKey<'static>, SecretKey<'static>); -static KEYPAIR_RX: OnceLock>> = OnceLock::new(); +pub static KEYPAIR_RX: OnceLock>> = OnceLock::new(); /// Spawn a worker that pre computes `bufsize` McEliece key pairs in a separate thread, which can be /// fetched asynchronously using the returned channel. /// /// As it can take upwards of 200 ms to generate McEliece key pairs, it needs to be done before we /// start connecting to the tunnel. -fn spawn_keypair_worker(bufsize: usize) -> mpsc::Receiver { +pub fn spawn_keypair_worker(bufsize: usize) -> mpsc::Receiver { // As one of the key pairs will be buffered by the stack of the spawned thread, we reduce the // capacity of the channel by one let bufsize = bufsize.checked_sub(1).expect("bufsize must be at least 1"); diff --git a/talpid-tunnel-config-client/src/lib.rs b/talpid-tunnel-config-client/src/lib.rs index bfa3deb29277..381bc65a5365 100644 --- a/talpid-tunnel-config-client/src/lib.rs +++ b/talpid-tunnel-config-client/src/lib.rs @@ -12,7 +12,7 @@ use tonic::transport::Endpoint; use tower::service_fn; use zeroize::Zeroize; -mod classic_mceliece; +pub mod classic_mceliece; mod ml_kem; #[cfg(not(target_os = "ios"))] mod socket;