Skip to Content
oxcrypto

Legacy crypt

Verify insecure md5-crypt, DES crypt and BSDi crypt Unix password records.

from oxcrypto.password.argon2 import ARGON2
from oxcrypto.password.legacy_crypt import LEGACY_CRYPT

stored = "$1$dXc3I7Rw$ctlgjDdWJLMT.qwHsWhXR1"
if LEGACY_CRYPT.MD5_CRYPT.verify(b"U*U*U*U*", stored):
    stored = ARGON2.ARGON2ID.hash(b"U*U*U*U*")

Warning

These formats are legacy and insecure: they are fast to brute-force and DES crypt uses only the first 8 bytes of the password. They are verify-only, for migrating old records to a current scheme such as Argon2 on the next successful login.

  • MD5_CRYPT reads $1$ records (Poul-Henning Kamp's FreeBSD md5-crypt).
  • DES_CRYPT reads 13-character traditional Unix crypt(3) records.
  • BSDI_CRYPT reads _ records (BSDi extended DES crypt with rounds).

verify returns False for a wrong password and raises ValueError for a string the selected format cannot read, such as another selector's record.

None of these formats has RFC or NIST status. The implementation is the pw_hash crate 0.1.3 (MIT, no declared MSRV, builds on Rust 1.88), a maintained fork of pwhash 1.0.0 ported to the current RustCrypto md-5, sha2, hmac and blowfish releases. It is a single-maintainer pre-1.0 crate with no published audit, so treat it as experimental. Tests use John the Ripper 1.7.9 vectors as collected in passlib 1.7.4.

pw_hash does not zeroize: its password copies, MD5 and DES state and intermediate buffers are not wiped.