Function strHash [src]

Compute a hash of a password using 2^rounds_log rounds of the bcrypt key stretching function. bcrypt is a computationally expensive and cache-hard function, explicitly designed to slow down exhaustive searches. The function returns a string that includes all the parameters required for verification. IMPORTANT: by design, bcrypt silently truncates passwords to 72 bytes. If this is an issue for your application, set the silently_truncate_password option to false.

Prototype

pub fn strHash( password: []const u8, options: HashOptions, out: []u8, ) Error![]const u8

Parameters

password: []const u8options: HashOptionsout: []u8

Possible Errors

AllocatorRequired Error
AuthenticationFailed AuthenticationError
IdentityElement IdentityElementError
InvalidEncoding EncodingError
KeyMismatch KeyMismatchError
LockedMemoryLimitExceeded SpawnError

mlockall is enabled, and the memory needed to spawn the thread would exceed the limit.

NoSpaceLeft Error
NonCanonical NonCanonicalError
NotSquare NotSquareError
OutOfMemory SpawnError

Not enough userland memory to spawn the thread.

OutputTooLong OutputTooLongError
PasswordVerificationFailed PasswordVerificationError
SignatureVerificationFailed SignatureVerificationError
SystemResources SpawnError

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.

ThreadQuotaExceeded SpawnError

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.
Unexpected SpawnError
UnexpectedSubgroup UnexpectedSubgroupError
WeakParameters WeakParametersError
WeakPublicKey WeakPublicKeyError

Source

pub fn strHash( password: []const u8, options: HashOptions, out: []u8, ) Error![]const u8 { switch (options.encoding) { .phc => return PhcFormatHasher.create(password, options.params, out), .crypt => return CryptFormatHasher.create(password, options.params, out), } }