HKDF constructor
HKDF({})
Implementation
factory HKDF({
required List<int> ikm,
required HashFunc hash,
int length = 32,
List<int>? salt,
List<int>? info,
bool hkdfExtract = true,
}) {
final h = hash();
int iteration = (length / h.getDigestLength).ceil();
if (iteration > 255) {
throw ArgumentException.invalidOperationArguments(
"HKDF",
name: "length",
reason: 'Cannot expand to more than 255 blocks.',
);
}
if (hkdfExtract) {
final ork = HMAC.hmac(hash, salt ?? List<int>.filled(32, 0), ikm);
return HKDF._(
ork: ork,
info: info?.clone(),
hmac: HMAC(hash, ork),
length: length,
);
}
return HKDF._(
ork: ikm.clone(),
hmac: HMAC(hash, ikm),
info: info?.clone(),
length: length,
);
}