Closed conradludgate closed 5 months ago
You need to change HMAC provider from Hmac
to SimpleHmac
. You can do it by using this type: Hkdf<Blake2s256, SimpleHmac<Blake2s256>>
.
Thanks, that seems to work. On a separate note, am I correct in thinking the algorithm defined in the paper is written as
let mut hkdf = SimpleHkdf::extract(Some(key), &input).1;
hkdf.expand(&[], out);
That's the only way that makes sense to me
@newpavlov perhaps hkdf
should be changed to always use SimpleHmac
and instead be generic around just the digest function rather than the Hmac
implementation?
@tarcieri
SimpleHmac
is a bit suboptimal for "eager" hash functions like SHA-256. And HMAC/HKDF are overwhelmingly used with such functions. I would even say that the HMAC algorithm implicitly assumes that hash functions are "eager". Arguably, HMAC should not be used with hashes like BLAKE2, so it's somewhat unfortunate that Wireguard specified in such way.
It may be possible to somehow select between Hmac
/SimpleHmac
based on implementation of BufferKindUser
, but it would require a bit of experimentation.
@conradludgate
am I correct in thinking the algorithm defined in the paper is written as
I think it will be more straightforward for you to use HMAC directly for implementing this without relying on the hkdf
crate.
SimpleHmac is a bit suboptimal for "eager" hash functions like SHA-256
@newpavlov but for HKDF specifically, the inputs are typically short enough does it really matter versus the API ergonomics?
In most practical cases the ergonomics are fine. But we probably should make SimpleHkdf
more noticeable in the docs. Also, before discussing potential change of defaults we should see whether it's possible to switch between HMAC providers automatically as mentioned above.
WireGuard uses Blake2s as the hash function of choice for the NoiseIK protocol. NoiseIK then heavily suggests to use HKDF after all diffie-hellman exchanges. Thus, WireGuard uses HKDF-Blake2s.
https://www.wireguard.com/papers/wireguard.pdf
Trying to perform a HKDF using Blake2s256 with the RustCrypto crates leads to this error.