Skip to content

Commit ce3e93e

Browse files
committed
Add --scrypt-rc and --argon2-rc to stability tests
1 parent 2504a3c commit ce3e93e

3 files changed

Lines changed: 59 additions & 6 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ Usage: slowkey stability-test [OPTIONS] --tasks <TASKS>
586586
Options:
587587
-t, --tasks <TASKS> Number of tasks
588588
-i, --iterations <ITERATIONS> Number of iterations to perform (must be greater than 0 and lesser than or equal 2000) [default: 2000]
589+
--scrypt-rc Use rust-crypto's Scrypt implementation instead of libsodium (default)
590+
--argon2-rc Use rust-crypto's Argon2id implementation instead of libsodium (default)
589591
-h, --help Print help
590592
```
591593
@@ -1262,6 +1264,10 @@ In order to run stability tests, you can run the `stability-test` command and sp
12621264
12631265
> slowkey stability-test -t 8
12641266
1267+
By default, stability tests use libsodium implementations for Scrypt and Argon2id. You can use the `--scrypt-rc` and `--argon2-rc` flags to test the rust-crypto implementations instead:
1268+
1269+
> slowkey stability-test -t 8 --scrypt-rc --argon2-rc
1270+
12651271
```sh
12661272
Setting up a stability test task pool with 8 tasks, each running 2000 iterations
12671273

src/main.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,20 @@ enum Commands {
211211
default_value = STABILITY_TEST_ITERATIONS.to_string(),
212212
help = format!("Number of iterations to perform (must be greater than {} and lesser than or equal {})", 0, STABILITY_TEST_ITERATIONS))]
213213
iterations: usize,
214+
215+
#[arg(
216+
long,
217+
action = clap::ArgAction::SetTrue,
218+
help = "Use rust-crypto's Scrypt implementation instead of libsodium (default)"
219+
)]
220+
scrypt_rc: bool,
221+
222+
#[arg(
223+
long,
224+
action = clap::ArgAction::SetTrue,
225+
help = "Use rust-crypto's Argon2id implementation instead of libsodium (default)"
226+
)]
227+
argon2_rc: bool,
214228
},
215229

216230
#[command(about = "Daisy-chain derivation through multiple secrets files")]
@@ -753,8 +767,25 @@ fn main() {
753767
log!("Saved benchmark reports to: \"{}\"", output_path.display());
754768
},
755769

756-
Commands::StabilityTest { tasks, iterations } => {
757-
stability_test(tasks, iterations);
770+
Commands::StabilityTest {
771+
tasks,
772+
iterations,
773+
scrypt_rc,
774+
argon2_rc,
775+
} => {
776+
let scrypt_implementation = if scrypt_rc {
777+
ScryptImplementation::RustCrypto
778+
} else {
779+
ScryptImplementation::Libsodium
780+
};
781+
782+
let argon2_implementation = if argon2_rc {
783+
Argon2idImplementation::RustCrypto
784+
} else {
785+
Argon2idImplementation::Libsodium
786+
};
787+
788+
stability_test(tasks, iterations, scrypt_implementation, argon2_implementation);
758789
},
759790

760791
Commands::DaisyDerive {

src/stability.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use crate::{log, warning};
22
use crate::{
33
slowkey::{SlowKey, SlowKeyOptions},
4-
utils::algorithms::{argon2id::Argon2idOptions, balloon_hash::BalloonHashOptions, scrypt::ScryptOptions},
4+
utils::algorithms::{
5+
argon2id::{Argon2idImplementation, Argon2idOptions},
6+
balloon_hash::BalloonHashOptions,
7+
scrypt::{ScryptImplementation, ScryptOptions},
8+
},
59
};
610
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
711
use rayon::iter::{IntoParallelIterator, ParallelIterator};
@@ -2019,7 +2023,10 @@ static EXPECTED: [&str; STABILITY_TEST_ITERATIONS] = [
20192023
"cf47a21d7876e09751c534db476c71689ba52b7c85f0f84945e3fa5c27b736af",
20202024
];
20212025

2022-
pub fn stability_test(tasks: usize, iterations: usize) {
2026+
pub fn stability_test(
2027+
tasks: usize, iterations: usize, scrypt_implementation: ScryptImplementation,
2028+
argon2_implementation: Argon2idImplementation,
2029+
) {
20232030
if tasks == 0 {
20242031
panic!("Invalid number of tasks");
20252032
}
@@ -2057,8 +2064,17 @@ pub fn stability_test(tasks: usize, iterations: usize) {
20572064
let slowkey = SlowKey::new(&SlowKeyOptions {
20582065
iterations,
20592066
length: SlowKeyOptions::DEFAULT_OUTPUT_SIZE,
2060-
scrypt: ScryptOptions::default(),
2061-
argon2id: Argon2idOptions::default(),
2067+
scrypt: ScryptOptions::new_with_implementation(
2068+
ScryptOptions::DEFAULT_LOG_N,
2069+
ScryptOptions::DEFAULT_R,
2070+
ScryptOptions::DEFAULT_P,
2071+
scrypt_implementation,
2072+
),
2073+
argon2id: Argon2idOptions::new_with_implementation(
2074+
Argon2idOptions::DEFAULT_M_COST,
2075+
Argon2idOptions::DEFAULT_T_COST,
2076+
argon2_implementation,
2077+
),
20622078
balloon_hash: BalloonHashOptions::default(),
20632079
});
20642080

0 commit comments

Comments
 (0)