UnixCrypt(3pm)

πŸ“¦
version 1.0 Β· 2 versions
  • 1.0 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.0 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– UnixCrypt β€” the Crypt::UnixCrypt manual page, bestie edition πŸ’–

okay so you're reading the UnixCrypt(3pm) page from the User Contributed Perl Documentation section and honestly? you came to the right place. sit down, hydrate, let's get into it. 🫢


✨ NAME ✨

Crypt::UnixCrypt β€” a perl-only implementation of the "crypt" function. no C, no XS, just vibes and pure Perl doing the whole thing itself. πŸ’…


🌸 SYNOPSIS 🌸

here's the whole move, copy it exactly, do not freestyle:

use Crypt::UnixCrypt;
$hashed = crypt($plaintext,$salt);

# always use this module's crypt
BEGIN { $Crypt::UnixCrpyt::OVERRIDE_BUILTIN = 1 }
use Crypt::UnixCrypt;
yes the second one literally says $Crypt::UnixCrpyt::OVERRIDE_BUILTIN and no that is not me being sloppy, that's the actual text on the page, iykyk. πŸ‘€ copy it character for character.

πŸ¦‹ DESCRIPTION πŸ¦‹

so this module exists for all those poor souls whose perl port looks at crypt() and hits them with:

The crypt() function is unimplemented due to excessive paranoia.

the paranoia. the audacity. anyway. 😭 this module is your little pocket backup so you're not left hanging.

it will not overload a built-in crypt() unless you force it β€” and the forcing mechanism is a true value on the variable $Crypt::UnixCrypt::OVERRIDE_BUILTIN. that's the whole trigger. no true value, no override. periodt. ✨

and like, if you're using this module, chances are you've got neither a built-in crypt() function nor a crypt(3) manpage. so the author very kindly pasted in the relevant chunks of that description (from their Linux system) right here for us. bless. πŸ™ so here's what crypt actually is:

crypt is the password encryption function. it's based on the Data Encryption Standard algorithm, with variations intended (among other things) to discourage use of hardware implementations of a key search. πŸ”

$plaintext is a user's typed password.

$salt is a two-character string chosen from the set [a-zA-Z0-9./]. this string is used to perturb the algorithm in one of 4096 different ways. 4096! cute number. love that for it.

by taking the lowest 7 bit of each character of $plaintext (filling it up to 8 characters with zeros, if needed), a 56-bit key is obtained. this 56-bit key is used to encrypt repeatedly a constant string (usually a string consisting of all zeros). the returned value points to the encrypted password: a series of 13 printable ASCII characters β€” and the first two characters represent the salt itself. iconic structure honestly. πŸŽ€

Warning: the key space consists of 2**56 equal 7.2e16 possible values. exhaustive searches of this key space are possible using massively parallel computers. software, such as crack(1), is available which will search the portion of this key space that is generally used by humans for passwords. hence, password selection should, at minimum, avoid common words and names. the use of a passwd(1) program that checks for crackable passwords during the selection process is recommended.

like... that's a real warning bestie. πŸ’€ your birthday is not a password. your dog's name is not a password. we've been over this.

and then the part that really matters: the DES algorithm itself has a few quirks which make the use of the crypt(3) interface a very poor choice for anything other than password authentication. if you are planning on using the crypt(3) interface for a cryptography project β€” don't do it. get a good book on encryption and one of the widely available DES libraries. that's the author's advice, verbatim energy, and they meant it. 🚫


this module is free software; you may redistribute it and/or modify it under the same terms as Perl itself. slay, open source. πŸ’–


πŸ‘‘ AUTHORS πŸ‘‘

  • Written by Martin Vorlaender, martin@radiogaga.harz.de, 11-DEC-1997. πŸ—“οΈ
  • Based upon Java source code written by jdumas@zgs.com
  • which in turn is based upon C source code written by Eric Young, eay@psych.uq.oz.au.

a whole lineage of legends. we stan an inherited codebase. 🌈


⚠️ CAVEATS ⚠️

in extreme situations, this function doesn't behave like crypt(3) β€” for example, when called with a salt not in [A-Za-z0-9./]{2}. so like, keep your salt inside the set bestie. that's the whole note. don't get cute with it. πŸ™ˆ


πŸ’œ SEE ALSO πŸ’œ


okay that's the whole page, you're fully caught up, go forth and hash responsibly. 🧚 this little writeup is perl v5.34.0, dated 2022-06-12, filed under UnixCrypt(3pm) β€” and that's the tea. πŸ’…βœ¨πŸ“

πŸ“¦ where this page comes from