HKDF constructor

HKDF({
  1. required List<int> ikm,
  2. required HashFunc 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 CryptoException('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, hmac: HMAC(hash, ork), length: length);
  }
  return HKDF._(ork: ikm, hmac: HMAC(hash, ikm), info: info, length: length);
}