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 the hash as a dk_length byte array, that doesn't include anything besides the hash output.
This function was designed for password storage, not for key derivation.
For key derivation, use bcrypt.pbkdf() or bcrypt.opensshKdf() instead.
pub fn bcrypt(
password: []const u8,
salt: *const [salt_length]u8,
params: Params,
) [dk_length]u8
pub fn bcrypt(
password: []const u8,
salt: *const [salt_length]u8,
params: Params,
) [dk_length]u8 {
if (password.len <= 72 or params.silently_truncate_password) {
return bcryptWithTruncation(password, salt, params);
}
var pre_hash: [HmacSha512.mac_length]u8 = undefined;
HmacSha512.create(&pre_hash, password, salt);
const Encoder = crypt_format.Codec.Encoder;
var pre_hash_b64: [Encoder.calcSize(pre_hash.len)]u8 = undefined;
_ = Encoder.encode(&pre_hash_b64, &pre_hash);
return bcryptWithTruncation(&pre_hash_b64, salt, params);
}