authorgravatar for rob@neverwood.orgRob Napier <rob@neverwood.org> 2020-09-13 11:08:06-04:00
committergravatar for rob@neverwood.orgRob Napier <rob@neverwood.org> 2020-09-13 11:08:06-04:00
log8a1a40276fb1577f46b89e3aefc17f9e82a933d6
tree18279327dd9e4bf9bea700c365237fcc0c0d752c
parent257c5b534839d75092909f604bb2663e883a290f

Extract kdf.zig to provide namespace documentation


3 files changed, 19 insertions(+), 11 deletions(-)

lib/std/crypto.zig+2-9
...@@ -35,14 +35,7 @@ pub const onetimeauth = struct {...@@ -35,14 +35,7 @@ pub const onetimeauth = struct {
35 pub const Poly1305 = @import("crypto/poly1305.zig").Poly1305;35 pub const Poly1305 = @import("crypto/poly1305.zig").Poly1305;
36};36};
3737
38/// A Key Derivation Function (KDF) is intended to turn a weak, human generated password into a38pub const kdf = @import("crypto/kdf.zig");
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.
43pub const kdf = struct {
44 pub const pbkdf2 = @import("crypto/pbkdf2.zig").pbkdf2;
45};
4639
47/// Core functions, that should rarely be used directly by applications.40/// Core functions, that should rarely be used directly by applications.
48pub const core = struct {41pub const core = struct {
...@@ -86,7 +79,7 @@ test "crypto" {...@@ -86,7 +79,7 @@ test "crypto" {
86 _ = @import("crypto/gimli.zig");79 _ = @import("crypto/gimli.zig");
87 _ = @import("crypto/hmac.zig");80 _ = @import("crypto/hmac.zig");
88 _ = @import("crypto/md5.zig");81 _ = @import("crypto/md5.zig");
89 _ = @import("crypto/pbkdf2.zig");82 _ = @import("crypto/kdf.zig");
90 _ = @import("crypto/poly1305.zig");83 _ = @import("crypto/poly1305.zig");
91 _ = @import("crypto/sha1.zig");84 _ = @import("crypto/sha1.zig");
92 _ = @import("crypto/sha2.zig");85 _ = @import("crypto/sha2.zig");
lib/std/crypto/kdf.zig created+17
...@@ -0,0 +1,17 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2020 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6
7//! A Key Derivation Function (KDF) is intended to turn a weak, human generated password into a
8//! strong key, suitable for cryptographic uses. It does this by salting and stretching the
9//! password. Salting injects non-secret random data, so that identical passwords will be converted
10//! into unique keys. Stretching applies a deliberately slow hashing function to frustrate
11//! brute-force guessing.
12
13pub const pbkdf2 = @import("pbkdf2.zig").pbkdf2;
14
15test "kdf" {
16 _ = @import("pbkdf2.zig");
17}
lib/std/crypto/pbkdf2.zig-2
...@@ -56,8 +56,6 @@ const mem = std.mem;...@@ -56,8 +56,6 @@ const mem = std.mem;
56/// the derivedKey. It is common to tune this parameter to achieve approximately 100ms.56/// the derivedKey. It is common to tune this parameter to achieve approximately 100ms.
57///57///
58/// Prf: Pseudo-random function to use. A common choice is std.crypto.auth.hmac.HmacSha256.58/// 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.
61pub fn pbkdf2(derivedKey: []u8, password: []const u8, salt: []const u8, rounds: u32, comptime Prf: type) void {59pub fn pbkdf2(derivedKey: []u8, password: []const u8, salt: []const u8, rounds: u32, comptime Prf: type) void {
62 assert(rounds >= 1);60 assert(rounds >= 1);
6361