Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
291 changes: 223 additions & 68 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ version = "2.4.3"
description = """Master Password is an algorithm used to generate unique
passwords for websites, email accounts, or anything else based only on easily
reproducible input."""

documentation = "http://masterpasswordapp.com/algorithm.html"
homepage = "http://masterpasswordapp.com/"
repository = "https://github.com/lispyclouds/mpw-rs.git"
readme = "README.md"
license = "GPL-3.0"

authors = [
"Rahul De <[email protected]>",
"Maarten Billemont <[email protected]>"
Expand All @@ -36,6 +38,8 @@ keywords = [
"password"
]

edition = "2018"

[profile.release]
opt-level = 3
debug = false
Expand All @@ -50,8 +54,8 @@ argon2rs = "0.2"
bcrypt = "0.1"
clap = "2"
rpassword = "1.0"
ring = "0.11"
ring-pwhash = "0.11"
ring = "0.14"
scrypt = "0.2"
rustyline = "1.0"

[badges]
Expand Down
8 changes: 3 additions & 5 deletions src/arg_parse/mod.rs → src/arg_parse.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate clap;

/*
* This file is part of Master Password.
*
Expand All @@ -20,9 +18,9 @@ extern crate clap;
mod helpers;

use std::process;
use self::clap::{Arg, App};
use common::{SiteVariant, SiteType};
use benchmark::mpw_bench;
use clap::{Arg, App};
use crate::common::{SiteVariant, SiteType};
use crate::benchmark::mpw_bench;

pub struct MpwOptions {
pub site: String,
Expand Down
7 changes: 2 additions & 5 deletions src/arg_parse/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate clap;
extern crate rustyline;

/*
* This file is part of Master Password.
*
Expand All @@ -19,8 +16,8 @@ extern crate rustyline;
*/

use std::env;
use self::rustyline::error::ReadlineError;
use self::rustyline::Editor;
use rustyline::error::ReadlineError;
use rustyline::Editor;

pub fn read_opt(matches: &clap::ArgMatches, name: &str, env_var: &str) -> Option<String> {
match matches.value_of(name) {
Expand Down
17 changes: 7 additions & 10 deletions src/benchmark/mod.rs → src/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate bcrypt;
extern crate ring;

/*
* This file is part of Master Password.
*
Expand All @@ -19,12 +16,12 @@ extern crate ring;
*/

use std::time;
use self::ring::{digest, hmac};
use self::bcrypt::hash;
use common::SiteType;
use common::SiteVariant;
use core::master_key_for_user;
use core::password_for_site;
use ring::{digest, hmac};
use bcrypt::hash;
use crate::common::SiteType;
use crate::common::SiteVariant;
use crate::core::master_key_for_user;
use crate::core::password_for_site;

fn calc_speed(elapsed: time::Duration, iterations: u32) -> f64 {
let seconds = (elapsed.as_secs() as f64) + (elapsed.subsec_nanos() as f64 / 1000_000_000.0);
Expand All @@ -48,7 +45,7 @@ pub fn mpw_bench() {

println!("\n## Benchmarking Master Password\n");

let master_key = master_key_for_user(&full_name, &master_password, &algo, &site_variant)
let master_key: [u8; 64] = master_key_for_user(&full_name, &master_password, &algo, &site_variant)
.unwrap();
let iterations = 3_000_000;
println!("### Performing {} iterations of {}:",
Expand Down
12 changes: 4 additions & 8 deletions src/common/mod.rs → src/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate ring_pwhash;
extern crate argon2rs;

/*
* This file is part of Master Password.
*
Expand All @@ -18,8 +15,8 @@ extern crate argon2rs;
* along with Master Password. If not, see <http://www.gnu.org/licenses/>.
*/

use self::ring_pwhash::scrypt::{scrypt, ScryptParams};
use self::argon2rs::{Variant, Argon2};
use scrypt::{scrypt, ScryptParams};
use argon2rs::{Variant, Argon2};

pub const KEY_LENGTH: usize = 64_usize;

Expand Down Expand Up @@ -147,10 +144,10 @@ pub fn u32_to_bytes(u: u32) -> [u8; 4] {
}

pub fn derive_key(password: &[u8], salt: &[u8]) -> [u8; KEY_LENGTH] {
let scrypt_params = ScryptParams::new(32768_f64.log(2.0) as u8, 8_u32, 2_u32);
let scrypt_params = ScryptParams::new(32768_f64.log(2.0) as u8, 8_u32, 2_u32).unwrap();
let mut digest: [u8; KEY_LENGTH] = [0; KEY_LENGTH];

scrypt(password, salt, &scrypt_params, &mut digest);
scrypt(password, salt, &scrypt_params, &mut digest).unwrap();

digest
}
Expand All @@ -167,7 +164,6 @@ pub fn derive_key_argon(password: &[u8], salt: &[u8]) -> [u8; KEY_LENGTH] {
#[cfg(test)]
mod tests {
use super::*;
use common::{SiteType, SiteVariant};

#[test]
fn get_valid_site_variant() {
Expand Down
4 changes: 2 additions & 2 deletions src/core/mod.rs → src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
mod mpw_v3;
mod mpw_next;

use common::KEY_LENGTH;
use common::{SiteType, SiteVariant};
use crate::common::KEY_LENGTH;
use crate::common::{SiteType, SiteVariant};

pub fn master_key_for_user(full_name: &str,
master_password: &str,
Expand Down
2 changes: 1 addition & 1 deletion src/core/mpw_next.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with Master Password. If not, see <http://www.gnu.org/licenses/>.
*/

use common;
use crate::common;
use common::SiteVariant;

pub fn master_key(full_name: &str,
Expand Down
6 changes: 2 additions & 4 deletions src/core/mpw_v3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate ring;

/*
* This file is part of Master Password.
*
Expand All @@ -17,8 +15,8 @@ extern crate ring;
* along with Master Password. If not, see <http://www.gnu.org/licenses/>.
*/

use self::ring::{digest, hmac};
use common;
use ring::{digest, hmac};
use crate::common;
use common::{SiteVariant, SiteType};

pub fn master_key(full_name: &str,
Expand Down
4 changes: 1 addition & 3 deletions src/identicon/mod.rs → src/identicon.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate ring;

/*
* This file is part of Master Password.
*
Expand All @@ -17,7 +15,7 @@ extern crate ring;
* along with Master Password. If not, see <http://www.gnu.org/licenses/>.
*/

use self::ring::{digest, hmac};
use ring::{digest, hmac};

pub fn generate(full_name: &str, master_password: &str) -> String {
let left_arm = vec!['╔', '╚', '╰', '═'];
Expand Down
2 changes: 0 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate rpassword;

/*
* This file is part of Master Password.
*
Expand Down