| author | |
| committer | |
| log | 8a1a40276fb1577f46b89e3aefc17f9e82a933d6 |
| tree | 18279327dd9e4bf9bea700c365237fcc0c0d752c |
| parent | 257c5b534839d75092909f604bb2663e883a290f |
3 files changed, 19 insertions(+), 11 deletions(-)
lib/std/crypto.zig+2-9| ... | ... | @@ -35,14 +35,7 @@ pub const onetimeauth = struct { |
| 35 | 35 | pub const Poly1305 = @import("crypto/poly1305.zig").Poly1305; |
| 36 | 36 | }; |
| 37 | 37 | |
| 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. | |
| 43 | pub const kdf = struct { | |
| 44 | pub const pbkdf2 = @import("crypto/pbkdf2.zig").pbkdf2; | |
| 45 | }; | |
| 38 | pub const kdf = @import("crypto/kdf.zig"); | |
| 46 | 39 | |
| 47 | 40 | /// Core functions, that should rarely be used directly by applications. |
| 48 | 41 | pub const core = struct { |
| ... | ... | @@ -86,7 +79,7 @@ test "crypto" { |
| 86 | 79 | _ = @import("crypto/gimli.zig"); |
| 87 | 80 | _ = @import("crypto/hmac.zig"); |
| 88 | 81 | _ = @import("crypto/md5.zig"); |
| 89 | _ = @import("crypto/pbkdf2.zig"); | |
| 82 | _ = @import("crypto/kdf.zig"); | |
| 90 | 83 | _ = @import("crypto/poly1305.zig"); |
| 91 | 84 | _ = @import("crypto/sha1.zig"); |
| 92 | 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 | ||
| 13 | pub const pbkdf2 = @import("pbkdf2.zig").pbkdf2; | |
| 14 | ||
| 15 | test "kdf" { | |
| 16 | _ = @import("pbkdf2.zig"); | |
| 17 | } |
lib/std/crypto/pbkdf2.zig-2| ... | ... | @@ -56,8 +56,6 @@ const mem = std.mem; |
| 56 | 56 | /// the derivedKey. It is common to tune this parameter to achieve approximately 100ms. |
| 57 | 57 | /// |
| 58 | 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. | |
| 61 | 59 | pub fn pbkdf2(derivedKey: []u8, password: []const u8, salt: []const u8, rounds: u32, comptime Prf: type) void { |
| 62 | 60 | assert(rounds >= 1); |
| 63 | 61 |