derive method
Derives a key from the given password
and salt
using scrypt key derivation.
This method takes a password
, a salt
,
and the desired derived key length (dkLen
) as input and computes the derived key using the
scrypt key derivation function. The derived key is returned as a List<int>.
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.
Returns: A derived key as a List<int>.
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);
zero(B);
return result;
}