Skip to content

Commit

Permalink
Refactor interface to be compatible with rust-crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
r8d8 committed Jun 13, 2018
1 parent 0c5cea6 commit 74a8b0b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "rust-scrypt"
authors = ["Constantine Kryvomaz <[email protected]>"]
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"
Expand Down
22 changes: 22 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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::<usize>() >= size_of::<u32>() || (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:
Expand Down

0 comments on commit 74a8b0b

Please sign in to comment.