-
Notifications
You must be signed in to change notification settings - Fork 229
kdf crate
#1879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1dd9bad to
7d87e21
Compare
|
I opened this up for discussion primarily, and also reserved the I think we probably need a lot more traits than this, particularly ones for representing the "expand" and "extract" steps in proper KDFs like HKDF. |
|
Another important question: output size limits and fallibility. Should we have a How about a trait with an associated constant or typenum type that defines the maximum output size? |
|
I am assuming that "key stretching functions", e.g. Argon2, Scrypt and such, don't fall under this trait? |
|
@daxpedda I think it would be good to eventually support password-based KDFs. I think they wind up having a very similar API to other KDFs, to the point it might just be a marker trait and some usage guidelines. That said, it would probably be good to focus on traits for what's in https://github.com/rustcrypto/kdfs for now |
|
FWIW: I don't have much feedback for this kind of interface, but for OPAQUE we would like to have a trait for key stretching functions. |
|
I thought I'd collect the individual functions we're trying to abstract over: KDFs
|
|
It seems like a one-shot API which accepts IKM/password and salt, and can access pub trait Kdf {
fn derive_key(&self, secret: &[u8], salt: &[u8], out: &mut [u8]) -> Result<()>;
}As for PBKDFs, perhaps a marker trait for where it's acceptable to use a password as pub trait Pbkdf: Kdf {}Notably having a trait that wraps the low-level KDF APIs for PBKDFs (as opposed to the high-level password hash string APIs in |
|
Sounds good to me! Is it correct to interpret What about the |
These are all good questions. The "other information" parameter of One-Step KDF seems to have fairly open-ended usage, per my interpretation of NIST SP 800-56C. It's described as:
I think it would be fine to pass Re: errors, I'll need to look at the error types in the various KDF crates to see if they're actually useful, and if not we can just have a common error type, which is probably where I'll start anyway as that's simpler. |
Maybe it's better to use something like |
Traits which provide an API for interacting with Key Derivation Functions. We have several of these located at https://github.com/rustcrypto/kdfs and password-based KDFs at https://github.com/RustCrypto/password-hashes but the APIs for using these are typically just free functions, whereas traits could provide a common API.
|
Just pushed up my suggested new changes and removed draft.
HKDF still calls it a salt, and I think "salt" is still an exceedingly common term for it. It's also the parameter that gets passed as a salt in PBKDFs. I think it would probably be more confusing to call it something else other than salt. |
|
But I don't think it's correct to call customization strings (
HKDF explicitly distinguishes between |
Well, that's why I want to pass the salt parameter to salt in HKDF. I think most HKDF usages use a salt, whereas they may or may not use info and if they do, this trait isn't going to be expressive enough to cover that case. For One-Shot KDF I think it's fine to pass
Can you show me an HKDF use case which uses info but does not use salt? Because that's the only such use case where such a trait impl would be useful. I think it's much more common to configure salt but leave info unspecified. |
|
For example, in QUIC salt is fixed (so it could've been omitted) and then initialized value is used with different On Wiki "salt" is defined as:
|
|
I guess it does not really matter. The trait method accepts If we are to keep |
|
Thanks for the approval. I think it's good to have something landed to iterate on. I'll note that while in some applications like password hash strings (including the At the end of the day, KDFs have a secret and non-secret input, and it's just a bikeshed debate about what to call the non-secret input (we could consider simply calling the other input Your comment did get me thinking though that your suggestion of using the non-secret HKDF input as info rather than salt is actually probably better, because then the trait can (almost) be impl'd on |
Traits which provide an API for interacting with Key Derivation Functions.
We have several of these located at https://github.com/rustcrypto/kdfs and password-based KDFs at https://github.com/RustCrypto/password-hashes but the APIs for using these are typically just free functions, whereas traits could provide a common API.