Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/bcrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ fn setup(cost: u32, salt: &[u8], key: &[u8]) -> Blowfish {
state
}

/// The bcrypt key derivation function.
///
/// - `cost` must be between 4 and 31.
/// - The length of `password` must be between 1 and 72.
pub fn bcrypt(cost: u32, salt: [u8; 16], password: &[u8]) -> [u8; 24] {
assert!(!password.is_empty() && password.len() <= 72);

Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Easily hash and verify passwords using bcrypt
#![deny(missing_docs)]
#![forbid(unsafe_code)]
#![cfg_attr(not(feature = "std"), no_std)]

Expand All @@ -25,7 +26,9 @@ pub use crate::errors::{BcryptError, BcryptResult};
// Cost constants
const MIN_COST: u32 = 4;
const MAX_COST: u32 = 31;
/// The default cost parameter.
pub const DEFAULT_COST: u32 = 12;
/// Base64 variant used by bcrypt.
pub const BASE_64: GeneralPurpose = GeneralPurpose::new(&BCRYPT, NO_PAD);

#[cfg(any(feature = "alloc", feature = "std"))]
Expand All @@ -41,9 +44,13 @@ pub struct HashParts {
/// BCrypt hash version
/// https://en.wikipedia.org/wiki/Bcrypt#Versioning_history
pub enum Version {
/// Version `$2a$`.
TwoA,
/// Version `$2x$`.
TwoX,
/// Version `$2y$`.
TwoY,
/// Version `$2b$`.
TwoB,
}

Expand Down