Scrypt constructor
Creates a Scrypt instance with CPU/memory cost n, block size r,
and parallelization p. Throws BuError if the parameters
are out of range or n isn't a power of 2.
Implementation
Scrypt(this.n, this.r, this.p) {
if (p <= 0) {
throw CoreErrors.invalidOperationArguments(
"Scrypt",
name: "p",
reason: "Incorrect p",
);
}
if (r <= 0) {
throw CoreErrors.invalidOperationArguments(
"Scrypt",
name: "r",
reason: "Incorrect r",
);
}
if (n < 1 || n > 1 << 31) {
throw CoreErrors.invalidOperationArguments(
"Scrypt",
name: "n",
reason: "N must be between 1 and 2^31",
);
}
if (!_isPowerOfTwo(n)) {
throw CoreErrors.invalidOperationArguments(
"Scrypt",
name: "n",
reason: "N must be a power of 2",
);
}
const maxInt = (1 << 31) & BinaryOps.mask32;
if (r * p >= 1 << 30 ||
r > maxInt ~/ 128 ~/ p ||
r > maxInt ~/ 256 ||
n > maxInt ~/ 128 ~/ r) {
throw CoreErrors.invalidOperationArguments(
"Scrypt",
name: "n",
reason: "Parameters are too large",
);
}
_v = List<int>.filled(32 * (n + 2) * r, 0);
_xy = List<int>.filled(_v.length - (32 * n * r), 0);
}