CRYPT_ROUNDSconstconst CRYPT_ROUNDS: { readonly default: 5000; readonly min: 1000; readonly max: 999999999; }The rounds glibc uses when none are named, and the least and most it accepts.
SHA-512 crypt ($6$), the password hash of glibc's crypt(3) that Linux accounts and Ubuntu's installer accept, on Web Crypto alone (commons 0001-crypto FR-003). The algorithm is Ulrich Drepper's "Unix crypt using SHA-256 and SHA-512". The salt is given, so the kernel stays free of effects: a caller makes one from random bytes with cryptSalt(crypto.getRandomValues(new Uint8Array(16))). Taken from Stolos's src/archon/core/crypt.ts.
import { sha512Crypt } from "./crypt.ts";
await sha512Crypt("Hello world!", "saltstring");
// "$6$saltstring$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJuesI68u4OTLiBFdcbYEdFCoEOfaS35inz1"CRYPT_ROUNDSconstconst CRYPT_ROUNDS: { readonly default: 5000; readonly min: 1000; readonly max: 999999999; }The rounds glibc uses when none are named, and the least and most it accepts.
cryptSaltfunctionfunction cryptSalt(bytes: Uint8Array<ArrayBufferLike>): stringA salt of crypt's alphabet (./0-9A-Za-z) made from bytes, one character each, at most 16.
sha512Cryptfunctionfunction sha512Crypt(password: string, salt: string, rounds?: number | undefined): Promise<string>A password hashed as SHA-512 crypt: $6$<salt>$<hash>, with rounds=<n>$ after $6$ where rounds are given (5000 where they are not). Only the first 16 characters of the salt count, and given rounds are clamped to what glibc accepts, as glibc does.
verifySha512Cryptfunctionfunction verifySha512Crypt(password: string, hash: string): Promise<boolean>Whether a password matches a $6$ hash, by hashing it again with the hash's own salt and rounds.