struct Params [src]
Scrypt parameters
Fields
ln: u6The CPU/Memory cost parameter [ln] is log2(N).
r: u30The [r]esource usage parameter specifies the block size.
p: u30The [p]arallelization parameter.
A large value of [p] can be used to increase the computational cost of scrypt without
increasing the memory usage.
Members
- fromLimits (Function)
- interactive (Constant)
- owasp (Constant)
- sensitive (Constant)
Source
pub const Params = struct {
const Self = @This();
/// The CPU/Memory cost parameter [ln] is log2(N).
ln: u6,
/// The [r]esource usage parameter specifies the block size.
r: u30,
/// The [p]arallelization parameter.
/// A large value of [p] can be used to increase the computational cost of scrypt without
/// increasing the memory usage.
p: u30,
/// Baseline parameters for interactive logins
pub const interactive = Self.fromLimits(524288, 16777216);
/// Baseline parameters for offline usage
pub const sensitive = Self.fromLimits(33554432, 1073741824);
/// Recommended parameters according to the
/// [OWASP cheat sheet](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html).
pub const owasp = Self{ .ln = 17, .r = 8, .p = 1 };
/// Create parameters from ops and mem limits, where mem_limit given in bytes
pub fn fromLimits(ops_limit: u64, mem_limit: usize) Self {
const ops = @max(32768, ops_limit);
const r: u30 = 8;
if (ops < mem_limit / 32) {
const max_n = ops / (r * 4);
return Self{ .r = r, .p = 1, .ln = @as(u6, @intCast(math.log2(max_n))) };
} else {
const max_n = mem_limit / (@as(usize, @intCast(r)) * 128);
const ln = @as(u6, @intCast(math.log2(max_n)));
const max_rp = @min(0x3fffffff, (ops / 4) / (@as(u64, 1) << ln));
return Self{ .r = r, .p = @as(u30, @intCast(max_rp / @as(u64, r))), .ln = ln };
}
}
}