Function kdf [src]
Derives a key from the password, salt, and argon2 parameters.
Derived key has to be at least 4 bytes length.
Salt has to be at least 8 bytes length.
Prototype
pub fn kdf( allocator: mem.Allocator, derived_key: []u8, password: []const u8, salt: []const u8, params: Params, mode: Mode, ) KdfError!void
Parameters
allocator: mem.Allocator
derived_key: []u8
password: []const u8
salt: []const u8
params: Params
mode: Mode
Possible Errors
mlockall
is enabled, and the memory needed to spawn the thread
would exceed the limit.
Not enough userland memory to spawn the thread.
The kernel cannot allocate sufficient memory to allocate a task structure for the child, or to copy those parts of the caller's context that need to be copied.
A system-imposed limit on the number of threads was encountered. There are a number of limits that may trigger this error:
- the RLIMIT_NPROC soft resource limit (set via setrlimit(2)), which limits the number of processes and threads for a real user ID, was reached;
- the kernel's system-wide limit on the number of processes and threads, /proc/sys/kernel/threads-max, was reached (see proc(5));
- the maximum number of PIDs, /proc/sys/kernel/pid_max, was reached (see proc(5)); or
- the PID limit (pids.max) imposed by the cgroup "process num‐ ber" (PIDs) controller was reached.
Source
pub fn kdf(
allocator: mem.Allocator,
derived_key: []u8,
password: []const u8,
salt: []const u8,
params: Params,
mode: Mode,
) KdfError!void {
if (derived_key.len < 4) return KdfError.WeakParameters;
if (derived_key.len > max_int) return KdfError.OutputTooLong;
if (password.len > max_int) return KdfError.WeakParameters;
if (salt.len < 8 or salt.len > max_int) return KdfError.WeakParameters;
if (params.t < 1 or params.p < 1) return KdfError.WeakParameters;
if (params.m / 8 < params.p) return KdfError.WeakParameters;
var h0 = initHash(password, salt, params, derived_key.len, mode);
const memory = @max(
params.m / (sync_points * params.p) * (sync_points * params.p),
2 * sync_points * params.p,
);
var blocks = try Blocks.initCapacity(allocator, memory);
defer blocks.deinit();
blocks.appendNTimesAssumeCapacity([_]u64{0} ** block_length, memory);
initBlocks(&blocks, &h0, memory, params.p);
try processBlocks(allocator, &blocks, params.t, memory, params.p, mode);
finalize(&blocks, memory, params.p, derived_key);
}