hkdf static method
HKDF-SHA256 of RFC 5869: length bytes made from secret, info
and salt. An empty salt is 32 zero bytes, like the RFC says.
Implementation
static Uint8List hkdf(
List<int> secret,
List<int> info, {
List<int> salt = const <int>[],
int length = 32,
}) {
if (length < 1 || length > 255 * 32) {
throw ArgumentError.value(length, 'length', 'must be 1 to 8160');
}
// extract: PRK = HMAC(salt, secret)
Uint8List prk = _hmac(salt.isEmpty ? Uint8List(32) : salt, secret);
// expand: T(i) = HMAC(PRK, T(i-1) + info + i)
Uint8List out = Uint8List(length);
Uint8List block = Uint8List(0);
int done = 0;
for (int i = 1; done < length; i++) {
block = _hmac(prk, <int>[...block, ...info, i]);
int take = length - done < block.length ? length - done : block.length;
out.setRange(done, done + take, block);
done += take;
}
return out;
}