Parallel Argon2id lanes (unlock 180 ms -> 129 ms, Go 122 ms); AEAD throughput probe

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Andy Dixon
2026-10-08 13:13:25 +01:00
co-authored by Claude
parent 438180b6fb
commit 0877cc7447
3 changed files with 82 additions and 1 deletions
Generated
+52
View File
@@ -39,6 +39,7 @@ dependencies = [
"blake2", "blake2",
"cpufeatures", "cpufeatures",
"password-hash", "password-hash",
"rayon",
"zeroize", "zeroize",
] ]
@@ -211,6 +212,31 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "crossbeam-deque"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "622f3fc73690be383c7214310406f28a90e6edeadc3cea882f9d71e495b9711a"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc74980687109a3b14c72fd458107bf0baa1da1a1a805e178d15501ba9b86d9d"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
[[package]] [[package]]
name = "crypto-common" name = "crypto-common"
version = "0.2.2" version = "0.2.2"
@@ -283,6 +309,12 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "either"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
[[package]] [[package]]
name = "errno" name = "errno"
version = "0.3.14" version = "0.3.14"
@@ -697,6 +729,26 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
[[package]]
name = "rayon"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
dependencies = [
"crossbeam-deque",
"crossbeam-utils",
]
[[package]] [[package]]
name = "ring" name = "ring"
version = "0.17.14" version = "0.17.14"
+5 -1
View File
@@ -10,7 +10,7 @@ repository = "https://github.com/andydixon/vault"
publish = false publish = false
[dependencies] [dependencies]
argon2 = { version = "0.6", default-features = false, features = ["alloc", "zeroize"] } argon2 = { version = "0.6", default-features = false, features = ["alloc", "zeroize", "parallel"] }
chacha20poly1305 = { version = "0.11", default-features = false, features = ["alloc", "zeroize"] } chacha20poly1305 = { version = "0.11", default-features = false, features = ["alloc", "zeroize"] }
hkdf = "0.13" hkdf = "0.13"
hmac = { version = "0.13", features = ["zeroize"] } hmac = { version = "0.13", features = ["zeroize"] }
@@ -44,3 +44,7 @@ strip = true
[[bench]] [[bench]]
name = "micro" name = "micro"
harness = false harness = false
[[bench]]
name = "aead_probe"
harness = false
+25
View File
@@ -0,0 +1,25 @@
use chacha20poly1305::aead::{AeadInOut, KeyInit};
use chacha20poly1305::{ChaCha20Poly1305, Key, Nonce};
use std::time::Instant;
fn main() {
let c = ChaCha20Poly1305::new(&Key::from([1u8; 32]));
let mut buf = vec![0u8; 64 * 1024];
let n = 1024; // 64 MiB
let t = Instant::now();
for i in 0..n {
let mut nb = [0u8; 12];
nb[3..11].copy_from_slice(&(i as u64).to_be_bytes());
std::hint::black_box(c.encrypt_inout_detached(&Nonce::from(nb), &[], buf.as_mut_slice().into()).unwrap());
}
let s = t.elapsed().as_secs_f64();
println!("raw seal: {:.0} MB/s", (n * 65536) as f64 / s / 1e6);
let key = [1u8; 32];
let data = vec![0u8; 64 << 20];
let t = Instant::now();
let mut out = Vec::with_capacity(data.len() + (1 << 20));
vault::crypto::stream::seal_all(&key, &data, &mut out);
println!("seal_all: {:.0} MB/s", data.len() as f64 / t.elapsed().as_secs_f64() / 1e6);
let t = Instant::now();
let n = vault::crypto::stream::open_all(&key, &mut out).unwrap();
println!("open_all: {:.0} MB/s ({n})", data.len() as f64 / t.elapsed().as_secs_f64() / 1e6);
}