summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2024-10-17 10:02:49 +0200
committerLinus Färnstrand <linus@mullvad.net>2024-10-17 12:59:04 +0200
commitc799f7781fa04860035b74eaf966b42f69117aee (patch)
treee874e2443f4bbea086b5943873e97fa49413a845
parent541a829fe6272dc6a7985668c2c29052e3f6d779 (diff)
downloadmullvadvpn-c799f7781fa04860035b74eaf966b42f69117aee.tar.xz
mullvadvpn-c799f7781fa04860035b74eaf966b42f69117aee.zip
Improve documentation on classic mceliece threading
-rw-r--r--talpid-tunnel-config-client/src/classic_mceliece.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/talpid-tunnel-config-client/src/classic_mceliece.rs b/talpid-tunnel-config-client/src/classic_mceliece.rs
index 2036bc3fc7..7f7edd43a7 100644
--- a/talpid-tunnel-config-client/src/classic_mceliece.rs
+++ b/talpid-tunnel-config-client/src/classic_mceliece.rs
@@ -2,9 +2,7 @@ use classic_mceliece_rust::{keypair_boxed, Ciphertext, CRYPTO_CIPHERTEXTBYTES};
pub use classic_mceliece_rust::{PublicKey, SecretKey, SharedSecret};
/// The `keypair_boxed` function needs just under 1 MiB of stack in debug
-/// builds. Even though it probably works to run it directly on the main
-/// thread on all OSes, we take this precaution and always generate the huge
-/// keys on a separate thread with a large enough stack.
+/// builds.
const STACK_SIZE: usize = 2 * 1024 * 1024;
/// Use the smallest CME variant with NIST security level 3. This variant has significantly smaller
@@ -14,6 +12,10 @@ pub const ALGORITHM_NAME: &str = "Classic-McEliece-460896f-round3";
pub async fn generate_keys() -> (PublicKey<'static>, SecretKey<'static>) {
let (tx, rx) = tokio::sync::oneshot::channel();
+ // We fork off the key computation to a separate thread for two reasons:
+ // * The computation uses a lot of stack, and we don't want to rely on the default
+ // stack being large enough or having enough space left.
+ // * The computation takes a long time and must not block the async runtime thread.
std::thread::Builder::new()
.stack_size(STACK_SIZE)
.spawn(move || {