RustCrypto / RustCrypto/password-hashes

pbkdf2: generic composition for `password-hash` use cases

Open
#883 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
909
Forks
115
Avg merge
1d 6h
Merged PRs (30d)
4

Description

Currently pbkdf2 relies on the sha2 crate to support both PHC and MCF password hashes. @newpavlov has suggested this could be implemented as generic composition instead. I'm opening this issue to spell out the specific requirements for this and why I don't think that makese sense.

pbkdf2 is really the only crate impacted by this problem: other constructions don't allow you to plug in your own hash function (sha-crypt is perhaps the closest with letting you choose between SHA-256 and SHA-512). If we wanted a truly generic solution though, e.g. in the password-hash crate, it really needs to be the combination of three things: a password hashing algorithm, a hash function, and a password hash serialization format.

The core trickiest part is the hash function-specific identifiers: for PBKDF2, these happen to be the same for PHC and MCF: pbkdf2-sha256 for SHA-256, and pbkdf2-sha512 for SHA-512. They aren't for other algorithms though, e.g. scrypt is $7$ for MCF and $scrypt$ for PHC.

At the very least, the password hashing implementation needs to be able to include this label in serialized hashes, and verify the correct algorithm-specific identifier label is in place when verifying. The current implementation in pbkdf2 is also able to do runtime dispatch to select between SHA-256 and SHA-512 when verifying based on these identifier labels.

To support generic composition, something needs to be able to define these identifiers as the combination of a password hashing algorithm, a hash function, and a password hash serialization format.

If we were to put these concerns in e.g sha2 instead of pbkdf2, how would we establish the linkage between a hash function and a particular password hash algorithm? That looks a little something like:

identifier password hash algorithm password hash serialization hash function
$5$ SHA-crypt MCF SHA-256
$6$ SHA-crypt MCF SHA-512
$pbkdf2-sha256$ PBKDF2-HMAC MCF or PHC SHA-256
$pbkdf2-sha512$ PBKDF2-HMAC MCF or PHC SHA-512

I don't think it makes sense to try to put all of this in sha2. Instead I think each password hash algorithm needs its own registry, i.e. how it works today. Really one of the two crates needs the other crate in scope so it can do things with type-level combinations of the two algorithms, and for defining details that are specific to a password hashing algorithm, I think it makes sense to put those details in the crate that contains the algorithm implementation for a given password hashing algorithm, rather than in the crate for the hash functions.

The only alternatives I can think of are for sha2 to just define a big bag of string identifiers for that algorithm with no type-specific linkage and the individual password hash algorithms can heuristically attempt to find which is appropriate, but that sounds like quite a hack.

Otherwise, the user could be responsible for providing the identifier when initializing a password hasher with a given concrete hash algorithm, but that sounds like punting a problem off to the user which is otherwise solvable.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the pbkdf2 and password-hash crates to understand their current PHC and MCF identifier handling. The issue requires an agreed design for composing the password-hashing algorithm, hash function, and serialization format, including identifier registration and verification; completion criteria are not yet defined.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cryptography, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.