Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions hkdf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ rust-version = "1.85"
[dependencies]
hmac = "0.13.0-rc.3"

# optional dependencies
kdf = { version = "0.1.0-pre.1", optional = true }

[dev-dependencies]
blobby = "0.4"
hex-literal = "1"
Expand Down
13 changes: 13 additions & 0 deletions hkdf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub use errors::{InvalidLength, InvalidPrkLength};
pub use hmac;
pub use hmac_impl::HmacImpl;

#[cfg(feature = "kdf")]
pub use kdf::{self, Kdf};

/// [`GenericHkdfExtract`] variant which uses [`Hmac`] for the underlying HMAC implementation.
pub type HkdfExtract<H> = GenericHkdfExtract<Hmac<H>>;
/// [`GenericHkdf`] variant which uses [`Hmac`] for the underlying HMAC implementation.
Expand Down Expand Up @@ -62,6 +65,16 @@ impl<H: HmacImpl> GenericHkdfExtract<H> {
}
}

#[cfg(feature = "kdf")]
impl<H: HmacImpl> Kdf for GenericHkdfExtract<H> {
fn derive_key(&self, secret: &[u8], info: &[u8], out: &mut [u8]) -> kdf::Result<()> {
Copy link
Member Author

Choose a reason for hiding this comment

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

@newpavlov per your point on RustCrypto/traits#1879 it does seem like the non-secret argument to derive_key is a better fit for HKDF info and maybe we can consider renaming it in the trait.

For now I have used the info name in the impl.

let mut extract = self.clone();
extract.input_ikm(secret);
let (_, hkdf) = extract.finalize();
hkdf.expand(info, out).map_err(|_| kdf::Error)
}
}

/// Structure representing the HKDF, capable of HKDF-Expand and HKDF-Extract operations.
/// Recommendations for the correct usage of the parameters can be found in the
/// [crate root](index.html#usage).
Expand Down