Skip to content

Add pure Go DES crypt(3) password hashing support - #15

Open
fpesce wants to merge 1 commit into
GehirnInc:masterfrom
fpesce:feature/des-crypt
Open

Add pure Go DES crypt(3) password hashing support#15
fpesce wants to merge 1 commit into
GehirnInc:masterfrom
fpesce:feature/des-crypt

Conversation

@fpesce

@fpesce fpesce commented Aug 15, 2026

Copy link
Copy Markdown

Pull Request: Add Pure Go Traditional DES crypt(3) Support

Target Repository: github.com/GehirnInc/crypt
Base Branch: master
Feature Branch: feature/des-crypt
Author: Francois Pesce
License: BSD-2-Clause


Title

Add pure Go traditional DES crypt(3) password hashing support


Description

Summary

This pull request adds support for the classic 13-character UNIX DES-based crypt(3) password hashing algorithm in pure Go.

While GehirnInc/crypt supports MD5, SHA-256, SHA-512, and Apache APR1 password hashing schemes, it currently lacks support for the foundational 13-character DES algorithm. Following the closure and rejection of crypt(3) password hashing proposals in golang.org/x/crypto (Proposal #14274), third-party libraries in the Go ecosystem serve as the primary solution for UNIX credential verification. This PR completes the functional scope of GehirnInc/crypt to provide full POSIX crypt(3) compatibility without Cgo dependencies.

What Changed

  1. New des_crypt Subpackage:
    • Pure Go implementation of 25-round DES crypt(3) Feistel cipher based on my (not AI, this was done 7 years ago for a personal project) implementation (github.com/fpesce/go-des-crypt), contributed under BSD 2-Clause.
    • Implements crypt.Crypter interface (Generate, Verify, Cost, SetSalt).
    • Strict 13-character hash validator (Validate(hash string) bool) ensuring standard 64-symbol alphabet (./0-9A-Za-z) and checking the 2-bit zero-mask on the 13th character for 64-bit DES block compliance.
    • Automatic 2-character cryptographically secure random salt generation via crypto/rand when salt is empty.
    • Accepts both 2-character salts and 13-character full hashes as salt arguments (POSIX idiom).
    • Strict POSIX password truncation to 8 bytes and zero-padding for < 8 bytes.
    • Constant-time verification via crypto/subtle.ConstantTimeCompare.
  2. Root crypt Package Updates:
    • Added crypt.DES constant to Crypt enum.
    • Added RegisterFallback(c Crypt, f func() Crypter, validator func(string) bool) to support prefixless algorithm registration.
    • Updated NewFromHash() and IsHashSupported() to check modular prefixes first, falling back to registered non-prefix validators (allowing transparent auto-detection of 13-character DES hashes).
  3. Tests & Documentation:
    • Exhaustive unit tests with standard test vectors ("foob" / "ar" -> "arlEKn0OzVJn.", "test" / "PQ" -> "PQl1.p7BcJRuM").
    • Integration tests in crypt_test.go verifying auto-detection and API availability.
    • Updated README.rst with algorithm list, examples, and security advisories.

Security Consideration

Traditional DES crypt(3) provides only 56 bits of key strength and is cryptographically obsolete for modern credential storage. This implementation is provided strictly for legacy password verification, retro-computing, and data migration.

Verification & Testing

go test -v -race ./...

All packages pass with 100% test coverage for new components and zero data races.

- Add des_crypt package implementing POSIX traditional 13-character DES crypt(3)
- Add crypt.DES constant and fallback auto-detection in NewFromHash / IsHashSupported
- Implement strict 13-character hash validator with 2-bit zero-mask check
- Zero Cgo dependencies, constant-time verification, and full unit test suite
- BSD-2-Clause license (engine authored by Francois Pesce)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant