I'm learning about Linux password security (more curiosity than anything useful), and I understand that the real password is hashed and stored in the shadow password file. What I'm not sure of, and haven't been able to find in my brief Googling, is what encoding is used to encode the hashed value (and the value of the salt). It's obviously not hex, and it's obviously text, excluding the : character. Can anyone here tell me what that encoding is?

Edit: I'm understand the hashing (MD5, SHA-X), the salt, and the hashing specifier. What I'm looking for is the method of converting the hash results (a byte array (byte[])) to the sequence of characters I see in the file, ie: the encoding.

link|improve this question

76% accept rate
feedback

6 Answers

In the case of MD5 crypt(), the salt is just a random string of up to 8 characters from [a-zA-Z0-9./].

The salt and password are then hashed together, passed through a strengthening function, then encoded using a variant on Base64:

  • the MD5 state (128 bits) is shuffled up and broken into 6 groups, each containing 3 bytes (the final group includes 2 bytes of zero-padding)
  • each group of 3 bytes is then split into 4 blocks of 6 bits each
  • finally, each 6-bit group is mapped to a character in the range [a-zA-Z0-9./]
link|improve this answer
feedback

The first part of the hash in between the $'s indicates what algorithm is being used.

Check out http://en.wikipedia.org/wiki/Crypt%5F%28Unix%29 for a list of the what the different values mean.

link|improve this answer
feedback

Are you looking for the algorithm used?

Traditionally Unix and early Linux variants used a weakened DES based on a maximum of 8 characters of the password. Most modern Linux installs use MD5 hashes for the passwords, and some support SHA. Additionally, more modular support for additional algorithms has shown up, including Blowfish. The GNU libc used by most Linux's supports DES, MD5, and SHA, giving you a couple of options.

The specific type of hash algorithm used is specified as the beginning of the password as $DIGIT$. For example, $1$ is MD5.

You can get more in depth details from Wikipedia (see the page on Crypt_(Unix)) or google for 'crypt unix' or 'crypt linux'.

link|improve this answer
feedback

You could read the source code for the relevant programs, assuming that wouldn't go too far over your head.

Edit: reading my comment after I posted it, I realise it might come across as being condescending..... that's not my intention ;-)

link|improve this answer
feedback

Use the source: http://sourceware.org/git/?p=glibc.git;a=tree;f=crypt

link|improve this answer
feedback

Your question is very related to this question.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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