derive method

List<int> derive(
  1. List<int> password,
  2. List<int> salt,
  3. int dkLen
)

Derives a key from the given password and salt using scrypt key derivation.

Parameters:

  • password: The password to use as input for key derivation.
  • salt: A random salt value used to enhance security.
  • dkLen: The desired length (in bytes) of the derived key.

Implementation

List<int> derive(List<int> password, List<int> salt, int dkLen) {
  final B = PBKDF2.deriveKey(
    mac: () => HMAC(() => SHA256(), password),
    salt: salt,
    iterations: 1,
    length: p * 128 * r,
  );

  for (int i = 0; i < p; i++) {
    final index = i * 128 * r;
    final copy = B.sublist(index);
    _smix(copy, r, n, _v, _xy);
    B.setAll(index, copy);
  }

  final result = PBKDF2.deriveKey(
    mac: () => HMAC(() => SHA256(), password),
    salt: B,
    iterations: 1,
    length: dkLen,
  );
  BinaryOps.zero(B);

  return result;
}