HKDF constructor

HKDF({
  1. required List<int> ikm,
  2. required HashFunc<HashState> hash,
  3. int length = 32,
  4. List<int>? salt,
  5. List<int>? info,
  6. bool hkdfExtract = true,
})

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,
  );
}