deriveKey method
Generates a new secret key from a secret key and a nonce.
Implementation
@override
Future<SecretKey> deriveKey({
required SecretKey secretKey,
required List<int> nonce,
}) async {
final numberOfBytes = (bits + 7) ~/ 8;
final macLength = macAlgorithm.macLength;
final result = Uint8List(
((numberOfBytes + macLength - 1) ~/ macLength) * macLength,
);
// Subsequent blocks
final firstInput = Uint8List(nonce.length + 4);
firstInput.setAll(0, nonce);
for (var i = 0; i < result.lengthInBytes ~/ macLength; i++) {
final block = await _f(secretKey, nonce, firstInput, i);
result.setAll(macLength * i, block);
}
// Return bytes
if (numberOfBytes == result.lengthInBytes) {
return SecretKey(result);
}
return SecretKey(List<int>.unmodifiable(Uint8List.view(
result.buffer,
result.offsetInBytes,
numberOfBytes,
)));
}