std.x.crypto.passwd [x] std.x.crypto.passwd.Cost pub struct Cost { n_log2: int, r: int, p: int, } — scrypt's three cost parameters, as a $7$ string carries them: N = 2^n_log2, block size r, parallelization p. std.x.crypto.passwd.Hashed pub struct Hashed { cost: Cost, salt: str, digest: List[byte], } — A parsed $7$ string: its cost, its salt characters (scrypt's salt octets) and the 32-octet derived key it stores. std.x.crypto.passwd.cost pub fn cost(n_log2: int, r: int, p: int) -> Cost ! {bad_n, bad_rp} — The cost N = 2^n_log2, r, p, checked as a $7$ string must carry it. std.x.crypto.passwd.default_cap pub fn default_cap() -> int — The working-memory ceiling verify and hash hold a cost to: scrypt.memory(18, 32, 1, 32) octets (N = 2^18, r = 32, p = 1, the largest cost Ubuntu's crypt_gensalt writes). std.x.crypto.passwd.gen_salt pub fn gen_salt(random: List[byte]) -> str ! {bad_random} — A salt string from random, octets the caller read from the OS random source (getrandom(2) or /dev/urandom; std draws no entropy of its own): the octets in crypt's base-64, so 16 octets make the 22 characters Ubuntu's crypt_gensalt writes and 64 make the 86 a $7$ string holds at most. std.x.crypto.passwd.encode pub fn encode(h: Hashed) -> str — The $7$ string for h: $7$, log2 N, r and p, the salt, $, the 43-character key. std.x.crypto.passwd.parse pub fn parse(stored: str) -> Hashed ! { empty, locked, unsupported, malformed, bad_n, bad_rp, bad_salt, bad_hash, } — Parses a stored crypt(5) field as a $7$ string. std.x.crypto.passwd.hash pub fn hash(password: List[byte], salt: str, c: Cost) -> str ! {bad_n, bad_rp, bad_salt, over_cap} — The $7$ string for password under salt and c: scrypt(password, salt, 2^n_log2, r, p, 32) behind the parameters, exactly as Ubuntu's crypt writes it for the same setting. std.x.crypto.passwd.verify_capped pub fn verify_capped(password: List[byte], stored: str, cap: int) -> bool ! { empty, locked, unsupported, malformed, bad_n, bad_rp, bad_salt, bad_hash, over_cap, } — verify with the caller's own memory ceiling: whether password hashes to stored when scrypt's working memory for the stored cost is at most cap octets. std.x.crypto.passwd.verify pub fn verify(password: List[byte], stored: str) -> bool ! { empty, locked, unsupported, malformed, bad_n, bad_rp, bad_salt, bad_hash, over_cap, } — Whether password hashes to stored, a crypt(5) field: the stored $7$ string's own cost and salt are used, and the derived key is compared with the stored one in constant time.