diff --git a/Cargo.toml b/Cargo.toml index ff4088d..9d6e8c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "rust-scrypt" authors = ["Constantine Kryvomaz "] description = "Bindings into C for Tarsnap's `Scrypt` algorithm" repository = "https://github.com/r8d8/rust-scrypt" -version = "1.2.0" +version = "1.3.0" build = "build.rs" keywords = ["rust", "crypto", "scrypt"] readme = "README.md" diff --git a/src/lib.rs b/src/lib.rs index fa2d9b9..dfb52ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,8 @@ #![cfg_attr(feature = "dev", plugin(clippy))] #![allow(non_upper_case_globals)] +use std::mem::size_of; + #[link(name = "scrypt")] extern "C" { pub fn crypto_scrypt( @@ -33,6 +35,26 @@ pub struct ScryptParams { pub p: u32, } +impl ScryptParams { + + ///Create a new instance of ScryptParams + /// + /// # Arguments: + /// log_n - The log2 of the Scrypt parameter N + /// r - The Scrypt parameter r + /// p - The Scrypt parameter p + /// + pub fn new(n: u64, r: u32, p: u32) -> ScryptParams { + assert!(r > 0); + assert!(p > 0); + assert!(n > 0); + assert!(size_of::() >= size_of::() || (r <= std::usize::MAX as u32 && p < std::usize::MAX as u32)); + + ScryptParams { n,r, p } + } + +} + /// Derive fixed size key for given `salt` and `passphrase` /// /// #Arguments: