hkdfExpand function

Uint8List hkdfExpand({
  1. required Uint8List prk,
  2. required Uint8List info,
  3. required int length,
})

Implementation

Uint8List hkdfExpand({
  required Uint8List prk,
  required Uint8List info,
  required int length,
}) {
  var hashLen = 32;
  int n = (length + hashLen - 1) ~/ hashLen;
  var okm = <int>[];
  var previous = <int>[];

  for (var i = 1; i <= n; i++) {
    var hmacSha256 = crypto.Hmac(crypto.sha256, prk);
    var data = <int>[
      ...previous,
      ...info,
      i,
    ];
    previous = hmacSha256.convert(data).bytes;
    okm.addAll(previous);
  }
  return Uint8List.fromList(okm.sublist(0, length));
}