From 2dfe98d41f82b4ea5779f110fb629c425c1063c1 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Mon, 8 Feb 2021 11:32:27 -0800 Subject: [PATCH] pbkdf2 v0.7.3 --- .github/workflows/pbkdf2.yml | 39 ++++++++++++++++++------------------ Cargo.lock | 3 ++- pbkdf2/CHANGELOG.md | 6 ++++++ pbkdf2/Cargo.toml | 3 ++- pbkdf2/src/lib.rs | 39 +++++++++++++++++++++++++++++++++++- 5 files changed, 68 insertions(+), 22 deletions(-) diff --git a/.github/workflows/pbkdf2.yml b/.github/workflows/pbkdf2.yml index 0eff4f7d..3674d3a0 100644 --- a/.github/workflows/pbkdf2.yml +++ b/.github/workflows/pbkdf2.yml @@ -17,25 +17,26 @@ env: RUSTFLAGS: "-Dwarnings" jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - 1.47.0 # MSRV - - stable - target: - - thumbv7em-none-eabi - - wasm32-unknown-unknown - steps: - - uses: actions/checkout@v1 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.rust }} - target: ${{ matrix.target }} - override: true - - run: cargo build --target ${{ matrix.target }} --release --no-default-features +# TODO(tarcieri): test when new cargo resolver is available (RFC 2957) +# build: +# runs-on: ubuntu-latest +# strategy: +# matrix: +# rust: +# - 1.47.0 # MSRV +# - stable +# target: +# - thumbv7em-none-eabi +# - wasm32-unknown-unknown +# steps: +# - uses: actions/checkout@v1 +# - uses: actions-rs/toolchain@v1 +# with: +# profile: minimal +# toolchain: ${{ matrix.rust }} +# target: ${{ matrix.target }} +# override: true +# - run: cargo build --target ${{ matrix.target }} --release --no-default-features test: runs-on: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index c8b95f86..c6eee592 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -274,13 +274,14 @@ dependencies = [ [[package]] name = "pbkdf2" -version = "0.7.2" +version = "0.7.3" dependencies = [ "base64ct", "crypto-mac 0.10.0", "hex-literal", "hmac", "password-hash", + "rand_core", "rayon", "sha-1", "sha2", diff --git a/pbkdf2/CHANGELOG.md b/pbkdf2/CHANGELOG.md index f6634e0f..6bcf6686 100644 --- a/pbkdf2/CHANGELOG.md +++ b/pbkdf2/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.7.3 (2021-02-08) +### Changed +- Enable `rand_core` feature of `password-hash` ([#130]) + +[#130]: https://github.com/RustCrypto/password-hashing/pull/130 + ## 0.7.2 (2021-02-01) ### Changed - Bump `base64ct` dependency to v0.2 ([#119]) diff --git a/pbkdf2/Cargo.toml b/pbkdf2/Cargo.toml index 48a8706e..f01bb944 100644 --- a/pbkdf2/Cargo.toml +++ b/pbkdf2/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pbkdf2" -version = "0.7.2" +version = "0.7.3" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" description = "Generic implementation of PBKDF2" @@ -24,6 +24,7 @@ sha2 = { version = "0.9", default-features = false, optional = true } [dev-dependencies] hex-literal = "0.3" hmac = "0.10" +rand_core = { version = "0.6", features = ["std"] } sha1 = { version = "0.9", package = "sha-1" } sha2 = "0.9" diff --git a/pbkdf2/src/lib.rs b/pbkdf2/src/lib.rs index a1d76573..7f12d262 100644 --- a/pbkdf2/src/lib.rs +++ b/pbkdf2/src/lib.rs @@ -7,7 +7,44 @@ //! //! ```toml //! [dependencies] -//! pbkdf2 = { version = "0.2", default-features = false } +//! pbkdf2 = { version = "0.7", default-features = false } +//! ``` +//! +//! # Usage (simple with default params) +//! +//! Note: this example requires the `rand_core` crate with the `std` feature +//! enabled for `rand_core::OsRng` (embedded platforms can substitute their +//! own RNG) +//! +//! Add the following to your crate's `Cargo.toml` to import it: +//! +//! ```toml +//! [dependencies] +//! pbkdf2 = "0.7" +//! rand_core = { version = "0.6", features = ["std"] } +//! ``` +//! +//! The following example demonstrates the high-level password hashing API: +//! +//! ``` +//! # #[cfg(feature = "password-hash")] +//! # { +//! use pbkdf2::{ +//! password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString}, +//! Pbkdf2 +//! }; +//! use rand_core::OsRng; +//! +//! let password = b"hunter42"; // Bad password; don't actually use! +//! let salt = SaltString::generate(&mut OsRng); +//! +//! // Hash password to PHC string ($pbkdf2-sha256$...) +//! let password_hash = Pbkdf2.hash_password_simple(password, salt.as_ref()).unwrap().to_string(); +//! +//! // Verify password against PHC string +//! let parsed_hash = PasswordHash::new(&password_hash).unwrap(); +//! assert!(Pbkdf2.verify_password(password, &parsed_hash).is_ok()); +//! # } //! ``` #![no_std]