mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
Extract kdf.zig to provide namespace documentation
This commit is contained in:
parent
257c5b5348
commit
8a1a40276f
@ -35,14 +35,7 @@ pub const onetimeauth = struct {
|
||||
pub const Poly1305 = @import("crypto/poly1305.zig").Poly1305;
|
||||
};
|
||||
|
||||
/// A Key Derivation Function (KDF) is intended to turn a weak, human generated password into a
|
||||
/// strong key, suitable for cryptographic uses. It does this by salting and stretching the
|
||||
/// password. Salting injects non-secret random data, so that identical passwords will be converted
|
||||
/// into unique keys. Stretching applies a deliberately slow hashing function to frustrate
|
||||
/// brute-force guessing.
|
||||
pub const kdf = struct {
|
||||
pub const pbkdf2 = @import("crypto/pbkdf2.zig").pbkdf2;
|
||||
};
|
||||
pub const kdf = @import("crypto/kdf.zig");
|
||||
|
||||
/// Core functions, that should rarely be used directly by applications.
|
||||
pub const core = struct {
|
||||
@ -86,7 +79,7 @@ test "crypto" {
|
||||
_ = @import("crypto/gimli.zig");
|
||||
_ = @import("crypto/hmac.zig");
|
||||
_ = @import("crypto/md5.zig");
|
||||
_ = @import("crypto/pbkdf2.zig");
|
||||
_ = @import("crypto/kdf.zig");
|
||||
_ = @import("crypto/poly1305.zig");
|
||||
_ = @import("crypto/sha1.zig");
|
||||
_ = @import("crypto/sha2.zig");
|
||||
|
||||
17
lib/std/crypto/kdf.zig
Normal file
17
lib/std/crypto/kdf.zig
Normal file
@ -0,0 +1,17 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2015-2020 Zig Contributors
|
||||
// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
|
||||
// The MIT license requires this copyright notice to be included in all copies
|
||||
// and substantial portions of the software.
|
||||
|
||||
//! A Key Derivation Function (KDF) is intended to turn a weak, human generated password into a
|
||||
//! strong key, suitable for cryptographic uses. It does this by salting and stretching the
|
||||
//! password. Salting injects non-secret random data, so that identical passwords will be converted
|
||||
//! into unique keys. Stretching applies a deliberately slow hashing function to frustrate
|
||||
//! brute-force guessing.
|
||||
|
||||
pub const pbkdf2 = @import("pbkdf2.zig").pbkdf2;
|
||||
|
||||
test "kdf" {
|
||||
_ = @import("pbkdf2.zig");
|
||||
}
|
||||
@ -56,8 +56,6 @@ const mem = std.mem;
|
||||
/// the derivedKey. It is common to tune this parameter to achieve approximately 100ms.
|
||||
///
|
||||
/// Prf: Pseudo-random function to use. A common choice is std.crypto.auth.hmac.HmacSha256.
|
||||
///
|
||||
/// PBKDF2 is defined in RFC 2898, and is a recommendation of NIST SP 800-132.
|
||||
pub fn pbkdf2(derivedKey: []u8, password: []const u8, salt: []const u8, rounds: u32, comptime Prf: type) void {
|
||||
assert(rounds >= 1);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user