Skip to content

Hkdf enhancement#69

Closed
WilliamTakeshi wants to merge 2 commits into
lake-rs:mainfrom
WilliamTakeshi:hkdf-enh
Closed

Hkdf enhancement#69
WilliamTakeshi wants to merge 2 commits into
lake-rs:mainfrom
WilliamTakeshi:hkdf-enh

Conversation

@WilliamTakeshi

Copy link
Copy Markdown
Collaborator

Some points raised in the #55

It changes the HKDF to not only work with HMAC-SHA256, but with any HMAC.
Improve the comments a bit

@WilliamTakeshi WilliamTakeshi self-assigned this Jun 9, 2026
@WilliamTakeshi WilliamTakeshi requested a review from chrysn June 9, 2026 12:32
Comment thread embedded-cal/src/hkdf.rs
) -> Result<Self::Prk, HkdfError> {
// When salt is absent, RFC 5869 uses HashLen zero bytes as the HMAC key.
// Buffer covers standard algorithms up to SHA-512 (64 bytes).
// Ideally this would be H::Algorithm::MAX_OUTPUT_LEN once const_trait_impl stabilises.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't need const_trait_impl for that if it is an associated const -- we can just introduce that associated constant.

Then InvalidOutputLength is back to returning inconsistent lengths, and as we start just using the underlying type as the only truth (no longer adding own knowledge), I don't think there are any cases left for it.

Comment thread embedded-cal/src/hkdf.rs

pub trait HkdfProvider {
/// HKDF-Extract (RFC 5869): returns a 32-byte pseudorandom key.
type Algorithm: HmacAlgorithm;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't we just say that trait HkdfProvider: HmacProvider, and then not use an own Algorithm at all but just everywhere use <Self as HmacProvider>::Algorithm?

Comment thread embedded-cal/src/hkdf.rs
type Algorithm: HmacAlgorithm;
/// Opaque input keying material. May be constructed from a DH shared secret
/// without the raw bytes ever being user-visible.
type Ikm: ?Sized;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not having any From<[u8]> for Ikm and AsRef<[u8]> for Okm means that users depend on knowing the concrete type -- which they can because of the blanket implementation, but then, we could just also not have types here until we start differentiating. (And that really doesn't need to be now.)

@chrysn chrysn mentioned this pull request Jun 10, 2026
@chrysn chrysn closed this in #72 Jun 11, 2026
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.

2 participants