Skip to content

password-hash: add generic H param to traits#2110

Merged
tarcieri merged 1 commit intomasterfrom
password-hash/generic-hash-param
Dec 7, 2025
Merged

password-hash: add generic H param to traits#2110
tarcieri merged 1 commit intomasterfrom
password-hash/generic-hash-param

Conversation

@tarcieri
Copy link
Member

@tarcieri tarcieri commented Dec 7, 2025

Adds a generic H parameter to the (Customized)PasswordHasher and PasswordVerifier traits which specifies the return type and the hash type respectively.

A generic parameter is used instead of an associated constant in order to support overlapping impls. Notably multiple commonly used password hashing algorithms (e.g. PBKDF2, scrypt) support encoding in either the Modular Crypt Format (MCF) or Password Hashing Competition (PHC) string format, which are implemented as the mcf::PasswordHash and phc::PasswordHash types respectively.

We already have open issues to add MCF support where we currently don't support it (RustCrypto/password-hashes#727,
RustCrypto/password-hashes#747).

The blanket impl of PasswordVerifier for CustomizedPasswordHasher is retained, but only for phc::PasswordHash, as supporting it for MCF requires algorithmic-specific interpretation of the hash. However, algorithms can provide their own impls of PasswordVerifier<mcf::PasswordHash>.

Adds a generic `H` parameter to the `(Customized)PasswordHasher` and
`PasswordVerifier` traits which specifies the return type and the hash
type respectively.

A generic parameter is used instead of an associated constant in order
to support overlapping impls. Notably multiple commonly used password
hashing algorithms (e.g. PBKDF2, scrypt) support encoding in either the
Modular Crypt Format (MCF) or Password Hashing Competition (PHC) string
format, which are implemented as the `mcf::PasswordHash` and
`phc::PasswordHash` types respectively.

We already have open issues to add MCF support where we currently don't
support it (RustCrypto/password-hashes#727,
RustCrypto/password-hashes#747).

The blanket impl of `PasswordVerifier` for `CustomizedPasswordHasher` is
retained, but only for `phc::PasswordHash`, as supporting it for MCF
requires algorithmic-specific interpretation of the hash. However,
algorithms can provide their own impls of
`PasswordVerifier<mcf::PasswordHash>`.
@tarcieri
Copy link
Member Author

tarcieri commented Dec 7, 2025

Note: this almost completely decouples password-hash from phc::PasswordHash, to the point phc can be made an optional feature and potentially extracted into its own crate.

tarcieri added a commit to RustCrypto/password-hashes that referenced this pull request Dec 7, 2025
@tarcieri tarcieri merged commit 9c5a7f6 into master Dec 7, 2025
11 checks passed
@tarcieri tarcieri deleted the password-hash/generic-hash-param branch December 7, 2025 03:40
tarcieri added a commit to RustCrypto/password-hashes that referenced this pull request Dec 7, 2025
tarcieri added a commit to RustCrypto/password-hashes that referenced this pull request Dec 7, 2025
@tarcieri tarcieri mentioned this pull request Mar 9, 2026
tarcieri added a commit that referenced this pull request Mar 10, 2026
## Added
- Generic `H` param to traits to support multiple string formats e.g.
  PHC, MCF (#2110)
- Implement `From<phc::Error>` for `Error` (#2124)
- `rand_core` feature (#2126)
- Salt generating helper functions `(try_)generate_salt` (#2128)
- `Error::RngFailure` variant (#2337)

## Changed
- Edition changed to 2024 and MSRV bumped to 1.85 (#1759)
- Extract `CustomizedPasswordHasher` trait (#2105)
- Bump `getrandom` to v0.4 (#2258)

## Removed
- `Encoding` enum (#2102)
- PHC types moved to the `phc` crate, which is re-exported as
  `password_hash::phc` when the `phc` crate feature is enabled
  (#2103, #2116):
  - `Ident`
  - `Output`
  - `ParamsString`
  - `PasswordHash`
  - `PasswordHashString`
  - `Salt`
  - `SaltString`
  - `Value`
- `McfHasher` trait (#2334)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant