Scrypt constructor
Scrypt({})
Creates an Scrypt instance with a sink for MAC generation.
Implementation
factory Scrypt({
List<int>? salt,
required int cost,
int blockSize = 8,
int parallelism = 1,
int derivedKeyLength = 64,
}) {
// validate parameters
if (cost < 1) {
throw StateError('The cost must be at least 1');
}
if (cost > 0xFFFFFF) {
throw StateError('The cost must be less than 2^24');
}
if (cost & (cost - 1) != 0) {
throw StateError('The cost must be a power of 2');
}
if (derivedKeyLength < 1) {
throw StateError('The derivedKeyLength must be at least 1');
}
if (blockSize < 1) {
throw StateError('The blockSize must be at least 1');
}
if (parallelism < 1) {
throw StateError('The parallelism must be at least 1');
}
if (blockSize * parallelism > 0x1FFFFFF) {
throw StateError('The blockSize * parallelism is too big');
}
salt ??= randomBytes(16);
// create instance
return Scrypt._(
salt: salt,
cost: cost,
blockSize: blockSize,
parallelism: parallelism,
derivedKeyLength: derivedKeyLength,
);
}