authorgravatar for 35231115+Rocknest@users.noreply.github.comRocknest <35231115+Rocknest@users.noreply.github.com> 2020-09-16 01:58:48+03:00
committergravatar for 35231115+Rocknest@users.noreply.github.comRocknest <35231115+Rocknest@users.noreply.github.com> 2020-09-16 01:58:48+03:00
logc35703825f17bb2b1108a371bb0559b89ff2b2a0
tree48f159529f7790fac59dacf3a4a86a865f3e1771
parent988fc6f9d1419a63d7ecd3507966ba0b4c15eac5

Add an error set


1 files changed, 9 insertions(+), 1 deletions(-)

lib/std/crypto/pbkdf2.zig+9-1
...@@ -36,6 +36,14 @@ const maxInt = std.math.maxInt;...@@ -36,6 +36,14 @@ const maxInt = std.math.maxInt;
3636
37// Based on Apple's CommonKeyDerivation, based originally on code by Damien Bergamini.37// Based on Apple's CommonKeyDerivation, based originally on code by Damien Bergamini.
3838
39pub const Pbkdf2Error = error{
40 /// At least one round is required
41 TooFewRounds,
42
43 /// Maximum length of the derived key is `maxInt(u32) * Prf.mac_length`
44 DerivedKeyTooLong,
45};
46
39/// Apply PBKDF2 to generate a key from a password.47/// Apply PBKDF2 to generate a key from a password.
40///48///
41/// PBKDF2 is defined in RFC 2898, and is a recommendation of NIST SP 800-132.49/// PBKDF2 is defined in RFC 2898, and is a recommendation of NIST SP 800-132.
...@@ -54,7 +62,7 @@ const maxInt = std.math.maxInt;...@@ -54,7 +62,7 @@ const maxInt = std.math.maxInt;
54/// the derivedKey. It is common to tune this parameter to achieve approximately 100ms.62/// the derivedKey. It is common to tune this parameter to achieve approximately 100ms.
55///63///
56/// Prf: Pseudo-random function to use. A common choice is `std.crypto.auth.hmac.HmacSha256`.64/// Prf: Pseudo-random function to use. A common choice is `std.crypto.auth.hmac.HmacSha256`.
57pub fn pbkdf2(derivedKey: []u8, password: []const u8, salt: []const u8, rounds: u32, comptime Prf: type) !void {65pub fn pbkdf2(derivedKey: []u8, password: []const u8, salt: []const u8, rounds: u32, comptime Prf: type) Pbkdf2Error!void {
58 if (rounds < 1) return error.TooFewRounds;66 if (rounds < 1) return error.TooFewRounds;
5967
60 const dkLen = derivedKey.len;68 const dkLen = derivedKey.len;