Skip to content

Commit 8f20e81

Browse files
authored
std.crypto.pwhash: Add recommended parameters (#20527)
These parameters according to the OWASP cheat sheet.
1 parent c40708a commit 8f20e81

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

lib/std/crypto/argon2.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ pub const Params = struct {
9191
/// Baseline parameters for offline usage using argon2id type
9292
pub const sensitive_2id = Self.fromLimits(4, 1073741824);
9393

94+
/// Recommended parameters for argon2id type according to the
95+
/// [OWASP cheat sheet](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html).
96+
pub const owasp_2id = Self{ .t = 2, .m = 19 * 1024, .p = 1 };
97+
9498
/// Create parameters from ops and mem limits, where mem_limit given in bytes
9599
pub fn fromLimits(ops_limit: u32, mem_limit: usize) Self {
96100
const m = mem_limit / 1024;

lib/std/crypto/bcrypt.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,14 @@ pub const State = struct {
408408

409409
/// bcrypt parameters
410410
pub const Params = struct {
411+
const Self = @This();
412+
411413
/// log2 of the number of rounds
412414
rounds_log: u6,
415+
416+
/// Minimum recommended parameters according to the
417+
/// [OWASP cheat sheet](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html).
418+
pub const owasp = Self{ .rounds_log = 10 };
413419
};
414420

415421
/// Compute a hash of a password using 2^rounds_log rounds of the bcrypt key stretching function.

lib/std/crypto/scrypt.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ pub const Params = struct {
141141
/// Baseline parameters for offline usage
142142
pub const sensitive = Self.fromLimits(33554432, 1073741824);
143143

144+
/// Recommended parameters according to the
145+
/// [OWASP cheat sheet](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html).
146+
pub const owasp = Self{ .ln = 17, .r = 8, .p = 1 };
147+
144148
/// Create parameters from ops and mem limits, where mem_limit given in bytes
145149
pub fn fromLimits(ops_limit: u64, mem_limit: usize) Self {
146150
const ops = @max(32768, ops_limit);

0 commit comments

Comments
 (0)