RustCrypto / KDFs

Collection of Key Derivation Functions written in pure Rust
67 stars 28 forks source link

Simplify the trait bounds, fixes #54 #56

Closed jbis9051 closed 2 years ago

jbis9051 commented 2 years ago

Fixes #54

jbis9051 commented 2 years ago

I replaced Hmac with SimpleHmac. An alternative would be to create a SimpleHkdf.

Using SimpleHmac is preferable because it will allow hashes like the BLAKE family to be used. See: https://github.com/BLAKE3-team/BLAKE3/issues/223

jbis9051 commented 2 years ago

Wonder if I can make it generic over Hmac implementation. The user could provide Hmac or SimpleHmac depending on what they need. We would reexport Hmac and SimpleHmac.

jbis9051 commented 2 years ago

I'd like to ideally get the interface to Hkdf<Sha256, SimpleHmac>. I've currently (not pushed yet) gotten it to Hkdf<Sha256, SimpleHmac<Sha256>>.

jbis9051 commented 2 years ago

So this is another option. We make the Hmac implementation generic so the user can provide SimpleHmac or Hmac depending on the algo they used. I think it's better than simply replacing Hmac with SimpleHmac.

@tarcieri if you like this approach, I can add a couple tests for testing both Hmac and SimpleHmac. I could also either reexport Hmac and SimpleHmac or remove the dependency. I'd also add a note in the docs on how this works.

A couple considerations:

Do we really want users to be able to pass anything to Hkdf? Maybe we should add a dummy trait to restrict passing either Hmac or SimpleHmac as there maybe other things that would fulfills the trait requirements but wouldn't be appropriate.

newpavlov commented 2 years ago

57 has been merged, so I will close this PR. But anyway thank you for it!