Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scrypt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ subtle = { version = "2", default-features = false , optional = true }

[features]
default = ["include_simple"]
include_simple = ["rand", "base64", "subtle"]
include_simple = ["rand", "base64", "subtle", "std"]
std = []

[badges]
travis-ci = { repository = "RustCrypto/password-hashing" }
27 changes: 7 additions & 20 deletions scrypt/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{error, fmt};
use core::fmt;

/// `scrypt()` error
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
Expand All @@ -24,23 +24,17 @@ impl fmt::Display for InvalidOutputLen {
}
}

impl error::Error for InvalidOutputLen {
fn description(&self) -> &str {
"invalid output buffer length"
}
}
#[cfg(feature = "std")]
impl std::error::Error for InvalidOutputLen {}

impl fmt::Display for InvalidParams {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("invalid scrypt parameters")
}
}

impl error::Error for InvalidParams {
fn description(&self) -> &str {
"invalid scrypt parameters"
}
}
#[cfg(feature = "std")]
impl std::error::Error for InvalidParams {}

#[cfg(feature = "include_simple")]
impl fmt::Display for CheckError {
Expand All @@ -52,12 +46,5 @@ impl fmt::Display for CheckError {
}
}

#[cfg(feature = "include_simple")]
impl error::Error for CheckError {
fn description(&self) -> &str {
match *self {
CheckError::HashMismatch => "password hash mismatch",
CheckError::InvalidFormat => "invalid `hashed_value` format",
}
}
}
#[cfg(all(feature = "include_simple", feature = "std"))]
impl std::error::Error for CheckError {}
9 changes: 7 additions & 2 deletions scrypt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@
//! # References
//! \[1\] - [C. Percival. Stronger Key Derivation Via Sequential
//! Memory-Hard Functions](http://www.tarsnap.com/scrypt/scrypt.pdf)

#![no_std]
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")]

#[cfg(feature = "include_simple")]
extern crate base64;
#[macro_use]
extern crate alloc;

#[cfg(feature = "std")]
extern crate std;

use hmac::Hmac;
use pbkdf2::pbkdf2;
Expand Down
3 changes: 1 addition & 2 deletions scrypt/src/params.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::mem::size_of;
use std::usize;
use core::{mem::size_of, usize};

use crate::errors::InvalidParams;

Expand Down
4 changes: 2 additions & 2 deletions scrypt/src/simple.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#![cfg(feature="include_simple")]
use std::io;

use super::scrypt;
use crate::errors::CheckError;
use crate::ScryptParams;

use alloc::string::String;
use subtle::ConstantTimeEq;
// TODO: replace with rand core and seprate os-rng crate
use base64;
use byteorder::{ByteOrder, LittleEndian};
// TODO: replace with rand_core
use rand::{OsRng, RngCore};

/// `scrypt_simple` is a helper function that should be sufficient for the
Expand Down