Ever been frustrated that you can only create crypt(3) compatible password hashes on *nix machines? Me too! But I figured, the crypt(3) implementation in glibc can’t be that hard to port to python, so I gave it a go, and can now present the Python package pcrypt. pcrypt uses a pure-python implementation of the crypt(3) algorithm, and is nearly 5 orders of magnitude slower than the glibc variant. However, it runs on all platforms and features a nifty CLI to quickly get compatible hashes, so it solves my immediate needs.
As a small background, crypt(3) (that is, the crypt C function found in section 3 of the man pages) is the function that hashes user passwords and stores them in /etc/shadow (and /etc/passwd before that) on most *nixes. The exact algorithm has changed over the years, from initially being the password encrypted with DES using the password itself as key and a two-character salt, through MD5, Blowfish to the SHA2-based variants most commonly used today. The modern spec is the password hashed with 5000 rounds of SHA512 and a 16 character salt,with a configurable number of rounds. The exact algorithm we use today was first designed by Poul-Henning Kamp in the nineties, using MD5 and 1000 iterations. This was very good for its time, but after a decade of Moore’s Law it didn’t hold up anymore. Red Hat started using a spec where the iteration count was customizable as part of the salt, and Ulrich Drepper combined this with PHK’s algorithm to produce the spec crypt(3) uses today.
I noticed that there has been a couple of requests for a similar pure JavaScript implementation of the algorithm, which should be doable. Being able to create hashes entirely client-side in the browser is enticing, so I hope someone will give it a go. If you do, the Python version should be close to the level of abstraction of a JavaScript version and might make adoption easier if you decide to give it a go.

Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.