Skip to content

Commit

Permalink
Merge pull request #8 from lbeder/update-info
Browse files Browse the repository at this point in the history
Update info and packages
  • Loading branch information
lbeder authored Jun 7, 2020
2 parents 6be9147 + 258b4af commit 3cf6ec7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 33 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "scrypt-kdf"
version = "0.5.0"
version = "0.5.1"
authors = ["Leonid Beder <[email protected]>"]
edition = "2018"

[dependencies]
getopts = "0.2.21"
rpassword = "4.0.5"
pbr = "1.0.2"
pbr = "1.0.3"
rust-crypto = "0.2.36"
hex = "0.4.2"
humantime = "2.0.0"
crossterm = "0.17.3"
crossterm = "0.17.5"
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,22 @@ Let's try to derive the key for the secret `test`, using the salt `salt`:

> ./target/release/scrypt-kdf
Progress status:

```bash
Enter your
Scrypt KDF v0.5.1

Deriving with settings:
CPU/memory cost parameter (log(N)): 20
Parallelization parameter (P): 8
Block size parameter (R): 1
Iterations: 100
Key size: 16

Enter your salt: salt
Enter your secret: 🔑
Enter your secret again: 🔑

Deriving with settings: log_n=20, r=8, p=1, iterations=100, keysize=16
Processing: 3 / 100 [======>-----------------------------------------------------------------------------------------------------] 6.00 % 7m
Processing: 12 / 100 [==============>--------------------------------------------------------------------------------------------------------------] 12.00 % 4m
```

Final result:
Expand All @@ -83,7 +90,6 @@ Enter your salt: salt
Enter your secret: 🔑
Enter your secret again: 🔑

Deriving with settings: log_n=20, r=8, p=1, iterations=100, keysize=16
Processing: 100 / 100 [=======================================================================================================================================] 100.00 %
Finished in 5m 6s
Key is (please highlight to see): ff08101f061aa670158601bf5be5efa6
Expand Down Expand Up @@ -120,17 +126,27 @@ Test vectors:
Results should be:

```bash
Scrypt KDF v0.5.1

Printing test vectors...

Deriving with settings: log_n=14, r=8, p=1, iterations=1, keysize=128
Processing: 1 / 1 [=============================================================================================================] 100.00 %
Finished in 4s
Deriving with settings:
CPU/memory cost parameter (log(N)): 14
Parallelization parameter (P): 8
Block size parameter (R): 1
Iterations: 1
Key size: 128

Key for test vector "" is:
d72c87d0f077c7766f2985dfab30e8955c373a13a1e93d315203939f542ff86e73ee37c31f4c4b571f4719fa8e3589f12db8dcb57ea9f56764bb7d58f64cf705f1f64bdd91c35da954a6fb7896f1839e6ba03f68f08b686527f9f1588ab103c22152046258e2d679842252afeb3cd6eb4e01fe9c285eb916da7e4b7a39ee5eba

Deriving with settings: log_n=14, r=8, p=1, iterations=3, keysize=128
Processing: 3 / 3 [=============================================================================================================] 100.00 %
Finished in 14s
Deriving with settings:
CPU/memory cost parameter (log(N)): 14
Parallelization parameter (P): 8
Block size parameter (R): 1
Iterations: 3
Key size: 128

Key for test vector "Hello World" is:
38f3b062f703aa0c958fc8944c9f005f1bd03a056048d5cdc6186979e4c178504050580fab8744c0272253f7df87a2e2f9bb5449a2361f0fed5105ea549e86e41f68d8b160cda5ca91e020067b0c53fc20ae19993e1f40db60d8963ec8c7c0fe74d48a44f1f78a4259f0376f6d7dd2c07d2e7aaae023b8bdfa87ddbf503fe9a3
```
Expand Down
36 changes: 17 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ fn print_usage(program: &str, opts: &Options) {
println!("{}", opts.usage(&brief));
}

fn print_version(program: &str) {
println!("{} v{}", program, VERSION);
}

fn get_options() -> Options {
let kdf_options: ScryptKDFOptions = Default::default();
let mut opts = Options::new();
Expand Down Expand Up @@ -87,11 +83,6 @@ fn parse_options() -> ScryptKDFOptions {
Err(f) => panic!(f.to_string()),
};

if matches.opt_present("v") {
print_version(&program);
exit(0);
}

if matches.opt_present("h") {
print_usage(&program, &opts);
exit(0);
Expand Down Expand Up @@ -155,11 +146,11 @@ fn read_line() -> Result<String> {
match code {
KeyCode::Enter => {
break;
},
}
KeyCode::Char(c) => {
line.push(c);
},
_ => {},
}
_ => {}
}
}

Expand Down Expand Up @@ -187,12 +178,17 @@ fn get_secret() -> String {
}

fn print_test_vectors() {
println!("Printing test vectors...");
println!();
println!("Printing test vectors...\n");

let test_vectors = ScryptKDF::test_vectors();
let test_keys = ScryptKDF::derive_test_vectors();
for (i, key) in test_keys.iter().enumerate() {
let opts = &test_vectors[i].opts;
println!(
"Deriving with settings:\n CPU/memory cost parameter (log(N)): {}\n Parallelization parameter (P): {}\n Block size parameter (R): {}\n Iterations: {}\n Key size: {}\n",
opts.log_n, opts.r, opts.p, opts.iterations, opts.keysize
);

println!(
"Key for test vector \"{}\" is: \n{}\n",
test_vectors[i].secret,
Expand All @@ -202,11 +198,6 @@ fn print_test_vectors() {
}

fn derive(opts: &ScryptKDFOptions, salt: &str, secret: &str) -> Vec<u8> {
println!(
"Deriving with settings: log_n={}, r={}, p={}, iterations={}, keysize={}",
opts.log_n, opts.r, opts.p, opts.iterations, opts.keysize
);

let mut pb = ProgressBar::new(u64::from(opts.iterations));
pb.show_speed = false;
pb.message("Processing: ");
Expand All @@ -227,8 +218,15 @@ fn derive(opts: &ScryptKDFOptions, salt: &str, secret: &str) -> Vec<u8> {
}

fn main() {
println!("Scrypt KDF v{}\n", VERSION);

let opts = parse_options();

println!(
"Deriving with settings:\n CPU/memory cost parameter (log(N)): {}\n Parallelization parameter (P): {}\n Block size parameter (R): {}\n Iterations: {}\n Key size: {}\n",
opts.log_n, opts.r, opts.p, opts.iterations, opts.keysize
);

let salt = get_salt();
let secret = get_secret();

Expand Down

0 comments on commit 3cf6ec7

Please sign in to comment.