Scrypt constructor
Creates a new Scrypt
instance for key derivation.
The Scrypt
constructor initializes the parameters for scrypt key derivation, which includes the CPU/memory cost parameter (n
), block size parameter (r
), and parallelization parameter (p
).
Parameters:
n
: The CPU/memory cost parameter. It defines the general work factor for scrypt.r
: The block size parameter. It specifies the number of iterations and memory size used.p
: The parallelization parameter. It controls the amount of parallel processing.
Throws an ArgumentException if the parameters are out of the valid range or not a power of 2.
Implementation
Scrypt(this.n, this.r, this.p) {
if (p <= 0) {
throw const ArgumentException("scrypt: incorrect p");
}
if (r <= 0) {
throw const ArgumentException("scrypt: incorrect r");
}
if (n < 1 || n > 1 << 31) {
throw const ArgumentException('scrypt: N must be between 2 and 2^31');
}
if (!_isPowerOfTwo(n)) {
throw const ArgumentException("scrypt: N must be a power of 2");
}
const maxInt = (1 << 31) & mask32;
if (r * p >= 1 << 30 ||
r > maxInt ~/ 128 ~/ p ||
r > maxInt ~/ 256 ||
n > maxInt ~/ 128 ~/ r) {
throw const ArgumentException("scrypt: parameters are too large");
}
_v = List<int>.filled(32 * (n + 2) * r, 0);
_xy = List<int>.filled(_v.length - (32 * n * r), 0);
}