Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#883 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
冷清
技术栈
rust

调研方向

首先阅读 pbkdf2 和 password-hash crate,以了解它们当前对 PHC 和 MCF 标识符的处理方式。该 issue 需要为组合密码哈希算法、哈希函数和序列化格式制定一致的设计,其中包括标识符的注册和验证;完成标准尚未定义。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Rust
星标
915
派生
116
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

RustCrypto/password-hashes 的其他 Issue

查看 RustCrypto/password-hashes 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。