MD5 and SHA-1 produce a hash signature, but this can be attacked by rainbow tables. Bcrypt is a more powerful hash generator for passwords and uses salt to create a non-recurrent hash. It was designed by Niels Provos and David Mazières, and is based on the Blowfish cipher. It is used as the default password hashing method for BSD and other systems.
BCrypt in Rust |
An outline of the Rust code is:
extern crate crypto; extern crate base64; use crypto::bcrypt; use crypto::bcrypt::{bcrypt}; use std::env; use std::str; fn main() { let mut c=10; let mut inpass = String::from("foo"); let args: Vec<String> = env::args().collect(); if args.len() >1 { inpass = args[1].clone();} if args.len() >2 { c = args[2].trim().parse().unwrap(); } if c>10000 {return;} let pass: &str = &inpass[..]; let mut hashit = [0u8; 24]; let s=&base64::decode_config("aaaaaaaaaaaaaaaaaaaaaO",base64::BCRYPT).unwrap(); println!("Len {}",s.len()); // base64::decode("aGVsbG8gd29ybGQ=").unwrap(); bcrypt(c,s,pass.as_bytes(), &mut hashit[..]); println!("Password: {}",pass); println!("Count: {}",c); println!("\nBcrypt: {}",hex::encode(hashit)); println!("\nBcrypt: {}",base64::encode(hashit)); }
Finally we simply build with:
cargo build
A sample run is:
Len 16 Password: Qwerty123 Count: 7 Bcrypt: 070a00f52dc0320fcdfc16fe75985a41704237daa89702a9 Bcrypt: BwoA9S3AMg/N/Bb+dZhaQXBCN9qolwKp