Skip to Content
oxcrypto

SHA-crypt

Read and create Unix password records in the SHA-256 or SHA-512 crypt formats.

from oxcrypto.password.sha_crypt import SHA_CRYPT

algorithm = SHA_CRYPT.SHA512_CRYPT
encoded = algorithm.hash(b"example password")
assert algorithm.verify(b"example password", encoded)

SHA256_CRYPT uses the Unix $5$ format and SHA512_CRYPT uses $6$.

hash takes a keyword-only rounds from 1,000 to 999,999,999 (default 5,000). The record always carries rounds=:

encoded = algorithm.hash(b"example password", rounds=656_000)
assert encoded.startswith("$6$rounds=656000$")

SHA-crypt is Ulrich Drepper's "Unix crypt using SHA-256 and SHA-512" specification, a de facto standard without RFC or NIST status. The implementation is the RustCrypto sha-crypt crate 0.6.0, a stable release with no published audit. Tests use the vectors from the specification.