RustCrypto / KDFs

Collection of Key Derivation Functions written in pure Rust
67 stars 28 forks source link

Update digest to 0.8, refactor for API changes, remove redundant crate #21

Closed timvisee closed 6 years ago

timvisee commented 6 years ago

This PR updates the digest dependency to version 0.8 (newest), and includes various refactorings to support this change. More crates start depending on these newer digest and hmac versions, thus an update is required. This might be considered breaking, as the set of required traits has changed caused by hmac. This PR does solve issue #20 .

The following crates have been updated to their newest version:

I've removed generic-array as it seems to be redundant, it is re-exported/provided by digest now.

Note that on line 60 in hkdf.rs, I've replaced result().code() with result_reset().code() as Rust was complaining about use-after-move issues, because the old result() consumes the hmac. I'm not 100% if this change is correct, this might introduce an extra clone, I don't know.

Unit tests and benchmarks succeed on rustc 1.29.2 (17a9dc751 2018-10-05) and rustc 1.31.0-nightly (4699283c5 2018-10-13).

timvisee commented 6 years ago

@warner Awesome. I believe I'm getting similar results.

What about implementing a similar method as before through a PR on hmac to get similar performance?

newpavlov commented 6 years ago

@timvisee Reset methods were reworked a bit in the latest trait versions. There is now a dedicated reset(&mut self) method and result_reset() methods are defined as a combination of reset and result methods. Code can be seen here. And HMAC reset method can be seen here. I hoped that optimizer will be smart enough to remove unnecessary operations, but I guess there is a small performance regression, maybe forcing inlining could improve situation a bit. Because regression is in the range of the measurement error I think we can merge this PR as-is.