Skip to content

Conversion from Hmac to HKDF #153

Closed

Description

@Firstyear

The current api design makes the assumption that you can provide initial key material to expand, on that you have a prk that is able to create a new hmac instance.

However, if we don't have access to the key bytes directly (pkcs11, tpm), it would be good to be able to initialise a hkdf from an existing hmac instance provided that trait needed traits are satifised.

For example

let tpm_hmac = ...... ; // impls the needed Mac traits, output size user, etc. 

let hkdf = Hkdf::from<tpm_hmac>(tpm_hmac);

Activity

  1. tarcieri commented on Oct 11, 2025

    @tarcieri
    Member

    If you’re able to get the PRK out of the HSM/TPM you can do Hkdf::from_prk

    But it seems like what you actually want is to be able to use different implementations of HKDF for HkdfExtract and Hkdf

    You could also instantiate HkdfExtract with whatever HSM/TPM adapter you have, use it to extract the PRK, then call Hkdf::from_prk.

  2. Firstyear commented on Oct 13, 2025

    @Firstyear
    Author

    Part of the point of a HSM/TPM is that you can't extract the PRK though. You'd be doing a "HMAC to derive the PRK, then making a HKDF from that PRK"

    Where what I would like is to skip that step, and just be able to HKDF using the TPM/HSM hmac impl without the PRK dance in between.

  3. newpavlov commented on Oct 13, 2025

    @newpavlov
    Member

    I guess we could unseal the HmacImpl trait. It requires only 3 methods + Clone, which should be easy to implement on top of HSMs.

  4. tarcieri commented on Oct 13, 2025

    @tarcieri
    Member

    Being able to do HKDF with an HSM-backed HMAC (#155) is something I've wanted, but I'm not sure it actually addresses @Firstyear's issue.

    If you want to plug in a fully HSM-provided HKDF as a replacement for the software version, I'm not sure how else to solve that besides KDF traits ala: RustCrypto/traits#1879

    That said, I also think it's still reasonable to do the extract step with an HSM-backed HKDF to obtain a PRK, then do the expand step on the host, which I think #155 will also enable.

  5. Firstyear commented on Oct 14, 2025

    @Firstyear
    Author

    Thank you @newpavlov !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions