Skip to content
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

Initial commit for KBKDF #87

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

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.

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