Skip to content

Conversation

baloo
Copy link
Member

@baloo baloo commented Oct 29, 2023

This implements KBKDF as defined in https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-108r1.pdf

This also implements non-standards behavior like use-l and use-separator. Those are used in TPMs for the KDFa method for example. See comments below for questions about that.

Missing:

  • double pipeline iteration mode (if you have an oracle in mind where to get for reference values, I'd love that)
  • tests with more than sha256 / sha512

const FEEDBACK_KI: bool = false;
}

pub struct Counter<Prf, K, R = U32> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not so fan of the default values for R. I wonder if maybe a type alias might not be better. (ala x509-cert::Certificate)


// Fixed input data
h.update(label);
if use_separator {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior is not standard, but TPM specification relies on KBKDF and calls for separator to be optional (https://trustedcomputinggroup.org/wp-content/uploads/TCG_TPM2_r1p59_Part1_Architecture_pub.pdf#page=73).

Added only if Label is not present or if the last octet of Label is not zero.

For a time I intended to provide that behavior as a type parameter, but I'm not sure now. I'd love opinion.

@baloo
Copy link
Member Author

baloo commented Oct 30, 2023

Nist has test vectors http://csrc.nist.gov/groups/STM/cavp/index.html

kbkdf/src/lib.rs Outdated
/// Derives `key` from `kin` and other parameters.
fn derive(
&self,
kin: &GenericArray<u8, Prf::KeySize>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect and doesn't work with hmac.
I think I'll need for it to pass in the Prf and reset it.

@baloo
Copy link
Member Author

baloo commented Jan 29, 2025

Closing in favor of #108

@baloo baloo closed this Jan 29, 2025
@baloo baloo deleted the baloo/kbkdf/init branch August 22, 2025 15:30
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.

1 participant