Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Do all Linux distributions use the same cryptographic hash function?

If yes, is it provided with the kernel itself?

EDIT:- I refer to the function mainly used for storing user login passwords.

share|improve this question
Crytographic hash functions for what use(s), exactly? There are many uses for these, and "Linux" is a common name for a collection of loosely coupled packages, each of which can very well use their own at their whim, or even use different ones by configuration selected by the distribution. – vonbrand Nov 14 '15 at 0:46
up vote 3 down vote accepted

No & no to your questions.

I'd take a look at the crypt(3) function for more info. From man crypt(3):


The glibc2 version of this function has the following additional features. If salt is a character string starting with the three characters $1$ followed by at most eight characters, and optionally terminated by $, then instead of using the DES machine, the glibc crypt function uses an MD5-based algorithm, and outputs up to 34 bytes, namely $1$&‹string›$, where ‹string› stands for the up to 8 characters following $1$ in the salt, followed by 22 bytes chosen from the set [a–zA–Z0–9./]. The entire key is significant here (instead of only the first 8 bytes).

You can check your pam setup to see whether you're using MD5 or DES:

$ egrep "password.*pam_unix.so" /etc/pam.d/system-auth
password    sufficient    pam_unix.so md5 shadow nis nullok try_first_pass use_authtok

And you can see in this systems /etc/shadow file that it's using MD5 as well:

root:$1$<DELETED PASSWORD HASH>:14245:0:99999:7:::

The codes you'll see in the /etc/shadow for each type of hashing:

  • $1 – MD5
  • $2 – blowfish
  • $2a – eksblowfish
  • $5 – SHA-256
  • $6 – SHA-512

On Red Hat distros you can change this using the authconfig command.

$ sudo authconfig --passalgo=sha512 --update


share|improve this answer
Note that the password hashing functions aren't the hash functions MD5, SHA-256, etc. but functions built on them (basically iterating them a large number of times)). – Gilles Mar 21 '14 at 2:27

No and it's not provided by the kernel. depending of the version, of the distro and of the unixes you use, you will find different hash encoding algorithm used (I assume you mean to store password mainly).
By looking at the /etc/shadow file as root you will be able to see which hash is used on your linux.

If you want to sign something with a hash, most Unices, will integrate the binary md5sum or sha1sum

share|improve this answer
Note that the hashes computer with md5sum and friends are the usual cryptographic hashes, which are not used to hash passwords. Password hashes are slow; the usual ones on unix are built on MD5 or SHA-2 (iterated many times and with salt thrown in). See my answer for more details. – Gilles Mar 21 '14 at 2:28

Note that a password hash function is a particular type of cryptographic hash function, which is not used for other uses of cryptographic hash functions. A password hash function needs to be slow; usually, we use fast cryptographic hash functions. In fact, technically, a password hash function isn't a hash function but a salted key stretching algorithm, taking two inputs (the password and the salt) whereas a hash function takes a single input (the data). See How to securely hash passwords? for more information about password hashing.

For historical reasons, many unix documents call password hashing “encryption”, but this is not an encryption process (you can't decrypt a hash back into the password). The historical reason is that in the early days of Unix, the password hashing function was built on the DES algorithm, which is primarily used for encryption.

Password hashing is performed by a function in the standard library called crypt. (Note that there is a traditional Unix utility called crypt, which is unrelated; this one actually encrypts.) The kernel doesn't know anything about passwords. (Some kernels on some platforms do provide a cryptographic library, to take advantage of hardware accelerators.)

The historical crypt function used a DES-based algorithm, which was ok for the time but is too weak for today's computer speeds. Nowadays the password hash function is indicated by the characters at the beginning of the salt: $1$, $5$, $6$, … These three values (and a few more) are de facto standard across many unices (including Linux systems based on Glibc, which is practically all non-embedded ones and some of the larger embedded ones). Some unix variants offer more choices. Embedded Linux systems may not have all these methods.

$1$ is based on MD5, but with a fixed number of iterations and is deprecated for that reason. $5$ and $6 are based on a variable number of iterations of SHA2-256 and SHA2-512 respectively. See How to create SHA512 password hashes on command line if you want to compute some password hashes from the command line.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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