deriveKey method

  1. @override
int deriveKey(
  1. Uint8List inp,
  2. int inpOff,
  3. Uint8List out,
  4. int outOff,
)
override

Derive key from given input and put it in out at offset outOff.

Implementation

@override
int deriveKey(Uint8List inp, int inpOff, Uint8List out, int outOff) {
  _digest.reset();

  var reps = _getReps(_parameters.desiredKeyLength, _digest.digestSize * 8);
  var output = Uint8List(reps * _digest.digestSize);
  var counter = Uint8List(4);
  for (var i = 1; i <= reps; i++) {
    var counterInt = i.toUnsigned(32);
    counter[0] = (counterInt >> 24) & 255;
    counter[1] = (counterInt >> 16) & 255;
    counter[2] = (counterInt >> 8) & 255;
    counter[3] = counterInt & 255;
    _digest.update(counter, 0, 4);
    _digest.update(_parameters.ikm, 0, _parameters.ikm.length);
    _digest.update(_parameters.salt ?? inp.sublist(inpOff), 0,
        _parameters.salt?.length ?? inp.sublist(inpOff).length);
    _digest.doFinal(output, (i - 1) * _digest.digestSize);
  }

  out.setAll(outOff, output.getRange(0, keySize));
  return keySize;
}