Skip to content

Commit 74a8b0b

Browse files
committed
Refactor interface to be compatible with rust-crypto
1 parent 0c5cea6 commit 74a8b0b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "rust-scrypt"
33
authors = ["Constantine Kryvomaz <[email protected]>"]
44
description = "Bindings into C for Tarsnap's `Scrypt` algorithm"
55
repository = "https://github.com/r8d8/rust-scrypt"
6-
version = "1.2.0"
6+
version = "1.3.0"
77
build = "build.rs"
88
keywords = ["rust", "crypto", "scrypt"]
99
readme = "README.md"

src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#![cfg_attr(feature = "dev", plugin(clippy))]
66
#![allow(non_upper_case_globals)]
77

8+
use std::mem::size_of;
9+
810
#[link(name = "scrypt")]
911
extern "C" {
1012
pub fn crypto_scrypt(
@@ -33,6 +35,26 @@ pub struct ScryptParams {
3335
pub p: u32,
3436
}
3537

38+
impl ScryptParams {
39+
40+
///Create a new instance of ScryptParams
41+
///
42+
/// # Arguments:
43+
/// log_n - The log2 of the Scrypt parameter N
44+
/// r - The Scrypt parameter r
45+
/// p - The Scrypt parameter p
46+
///
47+
pub fn new(n: u64, r: u32, p: u32) -> ScryptParams {
48+
assert!(r > 0);
49+
assert!(p > 0);
50+
assert!(n > 0);
51+
assert!(size_of::<usize>() >= size_of::<u32>() || (r <= std::usize::MAX as u32 && p < std::usize::MAX as u32));
52+
53+
ScryptParams { n,r, p }
54+
}
55+
56+
}
57+
3658
/// Derive fixed size key for given `salt` and `passphrase`
3759
///
3860
/// #Arguments:

0 commit comments

Comments
 (0)