authorgravatar for rob@neverwood.orgRob Napier <rob@neverwood.org> 2020-09-13 10:50:46-04:00
committergravatar for rob@neverwood.orgRob Napier <rob@neverwood.org> 2020-09-13 10:50:46-04:00
log257c5b534839d75092909f604bb2663e883a290f
treef566bbd1f9e67552f6d29964a67e48d01fce6f03
parent0f85b85acb0bd322ff7408c25dc09a84ff6621dc

Explicitly reference std.crypto.kdf in test case


2 files changed, 10 insertions(+), 10 deletions(-)

lib/std/crypto.zig+5-1
......@@ -35,7 +35,11 @@ pub const onetimeauth = struct {
3535 pub const Poly1305 = @import("crypto/poly1305.zig").Poly1305;
3636};
3737
38/// Key derivation functions
38/// A Key Derivation Function (KDF) is intended to turn a weak, human generated password into a
39/// strong key, suitable for cryptographic uses. It does this by salting and stretching the
40/// password. Salting injects non-secret random data, so that identical passwords will be converted
41/// into unique keys. Stretching applies a deliberately slow hashing function to frustrate
42/// brute-force guessing.
3943pub const kdf = struct {
4044 pub const pbkdf2 = @import("crypto/pbkdf2.zig").pbkdf2;
4145};
lib/std/crypto/pbkdf2.zig+5-9
......@@ -10,14 +10,6 @@ const debug = std.debug;
1010const assert = debug.assert;
1111const mem = std.mem;
1212
13//! PBKDF2 (Password-Based Key Derivation Function 2) is intended to turn a weak, human generated
14//! password into a strong key, suitable for cryptographic uses. It does this by salting and
15//! stretching the password. Salting injects non-secret random data, so that identical passwords
16//! will be converted into unique keys. Stretching applies a deliberately slow hashing function to
17//! frustrate brute-force guessing.
18//!
19//! PBKDF2 is defined in RFC 2898, and is a recommendation of NIST SP 800-132.
20
2113// RFC 2898 Section 5.2
2214//
2315// FromSpec:
......@@ -48,6 +40,8 @@ const mem = std.mem;
4840
4941/// Apply PBKDF2 to generate a key from a password.
5042///
43/// PBKDF2 is defined in RFC 2898, and is a recommendation of NIST SP 800-132.
44///
5145/// derivedKey: Slice of appropriate size for generated key. Generally 16 or 32 bytes in length.
5246/// May be uninitialized. All bytes will be written.
5347/// Maximum size is (2^32 - 1) * Hash.digest_length
......@@ -62,6 +56,8 @@ const mem = std.mem;
6256/// the derivedKey. It is common to tune this parameter to achieve approximately 100ms.
6357///
6458/// Prf: Pseudo-random function to use. A common choice is std.crypto.auth.hmac.HmacSha256.
59///
60/// PBKDF2 is defined in RFC 2898, and is a recommendation of NIST SP 800-132.
6561pub fn pbkdf2(derivedKey: []u8, password: []const u8, salt: []const u8, rounds: u32, comptime Prf: type) void {
6662 assert(rounds >= 1);
6763
......@@ -161,7 +157,7 @@ test "RFC 6070 one iteration" {
161157
162158 var derivedKey: [dkLen]u8 = undefined;
163159
164 pbkdf2(&derivedKey, p, s, c, crypto.auth.hmac.HmacSha1);
160 std.crypto.kdf.pbkdf2(&derivedKey, p, s, c, crypto.auth.hmac.HmacSha1);
165161
166162 const expected = "0c60c80f961f0e71f3a9b524af6012062fe037a6";
167163