Skip to content

Commit

Permalink
bcrypt added
Browse files Browse the repository at this point in the history
  • Loading branch information
miroc committed Oct 12, 2015
1 parent 9033425 commit 661ac3b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ serde = "*"
serde_json = "*"
serde_macros = "*"
rand = "0.3.11"
rust-crypto = "*"

[build-dependencies]
gcc = "0.3"
Expand Down
1 change: 0 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::process::Command;
// invoking the C compiler.
extern crate gcc;

// TODO replace with https://github.com/alexcrichton/gcc-rs
fn main() {
gcc::compile_library("libtweetnacl.a", &["lib/tweetnacl/tweetnacl.c"]);

Expand Down
2 changes: 1 addition & 1 deletion src/add.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extern crate getopts;
//extern crate getopts;
use PassEntry;

static USAGE: &'static str = "Usage: rusty_pass add <title> <username> <password>";
Expand Down
25 changes: 19 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
#![feature(custom_derive, plugin)]
#![plugin(serde_macros)]

extern crate libc;
extern crate serde;
extern crate serde_json;
extern crate getopts;
extern crate rand;
//extern crate knukle;
extern crate crypto;

use getopts::Options;
use std::env;
use secstr::SecStr;
use nacl::secretbox::{SecretKey, SecretMsg};
// TODO figure out why my impl doesn't work (resolution: tweetnacl impl differs)
//
//use knuckle::secretbox::{SecretKey, SecretMsg};
use rand::{ Rng, OsRng };
use crypto::bcrypt::bcrypt;

mod secstr;
mod add;
Expand Down Expand Up @@ -75,8 +75,21 @@ fn main() {
let args: Vec<String> = env::args().collect();
//let program = args[0].clone();

let pass = "deadly.job";
let mut salt = [0u8; 16]; // 16bytes of salt bcrypt
let mut output = [0u8; 24]; // output 24 bytes

OsRng::new().unwrap().fill_bytes(&mut salt);

// TODO take only first 72 characters of input
bcrypt(10, &salt, pass.as_bytes(), &mut output);

/*
let key = SecretKey::from_str("some secret key");
let enc: SecretMsg = key.encrypt("my secret msg".as_bytes());
let enc: SecretMsg = key.encrypt("abc".as_bytes());
let decr_opt = key.decrypt(&enc);
println!("decrypted: {:?}", decr_opt.unwrap());
let mut opts = Options::new();
Expand Down Expand Up @@ -109,5 +122,5 @@ fn main() {
}
print_passwords(&passwords);
db::save_passwords(&passwords);
db::save_passwords(&passwords);*/
}
3 changes: 2 additions & 1 deletion src/secstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ For more information, please refer to <http://unlicense.org/>
*/

//! A data type suitable for storing sensitive information such as passwords and private keys in memory, featuring constant time equality, mlock and zeroing out.
extern crate libc;
//extern crate libc;
use std::fmt;
use std::ptr;
use std::borrow::Borrow;
use std::borrow::BorrowMut;
use serde::ser;
use libc;

/// A data type suitable for storing sensitive information such as passwords and private keys in memory, that implements:
///
Expand Down

0 comments on commit 661ac3b

Please sign in to comment.