6

So, I have a website that reads/verifies (and writes) password hashes from the database, and I have something that makes SHA-512 style password hashes for that, ones that look like:

$6$GloHensinmyampOc$AxvlkxxXk36oDOyu8phBzbCfLn8hyWgoYNEuqNS.3dHf4JJrwlYCqha/g6pA7HJ1WwsADjWU4Qz8MfSWM2w6F.

The website is java based, so I wrote a SHA-512 hasher for it. Trouble is, there are a bunch of perl cron jobs that run that also need to verify password hashes occasionally to the database, and since those run on a Solaris box, it's crypt doesn't support the $6$ format.

So, when I do:

printf("crypt => '%s'\n",crypt("Hello",'$1$CygnieHyitJoconf$'));

I get back sensibly:

crypt => '$1$CygnieHy$n9MlDleP0qmGCfpbnVYy11'

Whereas, if I do

printf("crypt => '%s'\n",crypt("Hello",'$6$CygnieHyitJoconf$'));

I get an unhelpful

crypt => ''

Is there a way to get the SHA-512 password hashes in Perl on a box that isn't using glibc? (That's what I get told when I do a search mostly ("use crypt").

I'd really rather not re-implement SHA-512 password hashes in perl.

Thanks!

2 Answers 2

7

Actually, I think I just found my own answer: Crypt::Passwd::XS

Crypt::Passwd::XS - Full XS implementation of common crypt() algorithms

It does unix_md5, apache_md5, unix_des, unix_sha256 and unix_sha512.. I guess it's a little unfortunate that it doesn't do blowfish. But, nevertheless, it solves my problem! Thanks @hobbs anyway tho!

use strict;
use Crypt::Passwd::XS;

{
        printf("crypt => %s\n",Crypt::Passwd::XS::crypt("Hello",'$6$CygnieHyitJoconf$'));
}

Now returns

crypt => $6$CygnieHyitJoconf$vkGJm.nLrFhyWHhNTvOh9fH/k7y6k.8ed.N7TqwT93hPMPfAOUsrRiO3MmQB5xTm1XDCVlW2zwyzU48epp8pY/

as expected!

3
  • Oh, the amusing Irony. A module named "Crypt::Passwd::XS" which contains ONLY algorithms that you should NEVER use for passwords!!! bcrypt or PBKDF* guys, and if you don't understand why, you better go read up. It's subtle, but is only the difference between "useless" and "works" !!
    – cnd
    Sep 12, 2014 at 18:11
  • Really? Why shouldn't you use unix_sha512? It salts, and so far as I know it's still collision resistant.. ?
    – bnsh
    Sep 13, 2014 at 19:26
  • 1
    For the record, glibc's implementation is not a simple salt 'n hash operation, which would indeed be pretty useless in the face of attack given how ridiculously easy (fast) it is for computers to compute SHA hashes. Refer to this 2007 article written by the developer who designed it: akkadia.org/drepper/sha-crypt.html ... From a quick persual of the page bnsh linked, I'm guessing this perl module is based on the same design, which would render @cnd's argument baseless.
    – rsaw
    Jul 3, 2015 at 18:11
3

Unfortunately not. crypt will be your system libc crypt, which is responsible for choosing algorithms and mapping prefix strings to algorithms. If you want access to algorithms that aren't in your system crypt then you'll need to use a re-implementation of them, and in the case of the libc ones, I don't know of any reimplementations. glibc's "SHA-512" password hash isn't simply SHA-512; it's a custom algorithm that doesn't exist outside of glibc that I know of. If you still have a chance, you might want to change to an algorithm like bcrypt or PBKDF-SHA-2 that has multiple implementations in different languages.

1
  • It is not so much a custom algorithm as it is a different algorithm. It is sha512crypt. SHA512 is designed to be FAST, which is the opposite of what you want for a password hashing function. It follows the crypt(3) standard along with bcrypt, and supports variable complexity (a variable number of 'rounds' to make it stronger in the future when the default 5000 rounds is not enough anymore). crypt(3) is always what you should use for password hashing. nothing else, ever.
    – Allan Jude
    Jun 20, 2016 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.