Skip to content

Commit

Permalink
Allow extending the iterations number when restoring from a checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeder committed Oct 21, 2024
1 parent 47fa6ff commit 2708644
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
17 changes: 14 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,19 @@ fn main() {
path: path.clone(),
});

slowkey_opts = checkpoint_data.data.slowkey.clone();
if iterations <= checkpoint_data.data.iteration {
panic!(
"Invalid iterations number {} for checkpoint {}",
iterations, checkpoint_data.data.iteration
);
}

slowkey_opts = SlowKeyOptions {
iterations,
length: checkpoint_data.data.slowkey.length,
scrypt: checkpoint_data.data.slowkey.scrypt,
argon2id: checkpoint_data.data.slowkey.argon2id,
};

offset = checkpoint_data.data.iteration + 1;
offset_data.clone_from(&checkpoint_data.data.data);
Expand Down Expand Up @@ -614,9 +626,8 @@ fn main() {
let slowkey_opts = checkpoint_data.data.slowkey.clone();

println!(
"{}: iterations: {}, length: {}, {}: (n: {}, r: {}, p: {}), {}: (version: {}, m_cost: {}, t_cost: {})",
"{}: length: {}, {}: (n: {}, r: {}, p: {}), {}: (version: {}, m_cost: {}, t_cost: {})",
"SlowKey Parameters".yellow(),
&slowkey_opts.iterations.to_string().cyan(),
&slowkey_opts.length.to_string().cyan(),
"Scrypt".green(),
&slowkey_opts.scrypt.n.to_string().cyan(),
Expand Down
27 changes: 24 additions & 3 deletions src/utils/checkpoints/checkpoint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use crate::{
slowkey::SlowKeyOptions,
utils::chacha20poly1305::{ChaCha20Poly1305, Nonce},
utils::{
argon2id::Argon2idOptions,
chacha20poly1305::{ChaCha20Poly1305, Nonce},
scrypt::ScryptOptions,
},
};

use glob::{glob_with, MatchOptions};
Expand Down Expand Up @@ -34,11 +38,28 @@ pub struct OpenCheckpointOptions {
pub key: Vec<u8>,
}

#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
pub struct CheckpointSlowKeyOptions {
pub length: usize,
pub scrypt: ScryptOptions,
pub argon2id: Argon2idOptions,
}

impl From<SlowKeyOptions> for CheckpointSlowKeyOptions {
fn from(options: SlowKeyOptions) -> Self {
CheckpointSlowKeyOptions {
length: options.length,
scrypt: options.scrypt,
argon2id: options.argon2id,
}
}
}

#[derive(Serialize, Deserialize)]
pub struct SlowKeyData {
pub iteration: usize,
pub data: Vec<u8>,
pub slowkey: SlowKeyOptions,
pub slowkey: CheckpointSlowKeyOptions,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -104,7 +125,7 @@ impl Checkpoint {
data: SlowKeyData {
iteration: 0,
data: Vec::new(),
slowkey: opts.slowkey.clone(),
slowkey: opts.slowkey.clone().into(),
},
},
checkpoint_extension_padding: (opts.iterations as f64).log10().round() as usize + 1,
Expand Down

0 comments on commit 2708644

Please sign in to comment.