Skip to content

Conversation

@tarcieri
Copy link
Member

Right now there's not a way to generate a random salt in the context of MCF password hashes when not using the high-level
PasswordHash::hash_password API, e.g. for KDF usage, which is to say that for PHC password hashes phc::Salt::generate is fine for this purpose since it now provides raw bytes, but password hashes which use MCF don't have access to that type.

This is often still documented as using some static value with a comment saying it needs to be unique. Instead we should provide a reusable solution in the rustdoc.

These can potentially be replaced with the crypto_common::Generate trait and something like a RecommendedLengthSalt type after there's a new getrandom crate prerelease, but in the meantime these helper functions seem like a reasonable enough stopgap, and can potentially stick around and use the Generate trait for you.

Right now there's not a way to generate a random salt in the context of
MCF password hashes when not using the high-level
`PasswordHash::hash_password` API, e.g. for KDF usage, which is to say
that for PHC password hashes `phc::Salt::generate` is fine for this
purpose since it now provides raw bytes, but password hashes which use
MCF don't have access to that type.

This is often still documented as using some static value with a comment
saying it needs to be unique. Instead we should provide a reusable
solution in the rustdoc.

These can potentially be replaced with the `crypto_common::Generate`
trait and something like a `RecommendedLengthSalt` type after there's a
new `getrandom` crate prerelease, but in the meantime these helper
functions seem like a reasonable enough stopgap, and can potentially
stick around and use the `Generate` trait for you.
@tarcieri tarcieri merged commit 70faf07 into master Dec 14, 2025
11 checks passed
@tarcieri tarcieri deleted the password-hash/salt-generating-helper-functions branch December 14, 2025 15:47
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.

2 participants