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.
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.
No & no to your questions.
I'd take a look at the crypt(3)
function for more info. From man crypt(3)
:
GNU EXTENSION
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:
On Red Hat distros you can change this using the authconfig
command.
$ sudo authconfig --passalgo=sha512 --update
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.
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
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 'SO- stop being evil'
Mar 21 '14 at 02:28