IF Commons GitHub

crypt

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-crypto FR-003

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"

Source: commons/crypto/src/crypt.ts

4 of 4 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

CRYPT_ROUNDSconst
const 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.

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

cryptSaltfunction
function cryptSalt(bytes: Uint8Array<ArrayBufferLike>): string

A salt of crypt's alphabet (./0-9A-Za-z) made from bytes, one character each, at most 16.

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

sha512Cryptfunction
function 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.

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

verifySha512Cryptfunction
function 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.

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.