crypt-hash

Pattern: 
'$0$.*' 
  '|$1$[a-zA-Z0-9./]{1,8}$[a-zA-Z0-9./]{22}' 
  '|$5$(rounds=\d+$)?[a-zA-Z0-9./]{1,16}$[a-zA-Z0-9./]{43}' 
  '|$6$(rounds=\d+$)?[a-zA-Z0-9./]{1,16}$[a-zA-Z0-9./]{86}' 

The crypt-hash type is used to store passwords using a hash function. The algorithms for applying the hash function and encoding the result are implemented in various UNIX systems as the function crypt(3).

A value of this type matches one of the forms:

  • $0$<clear text password>

  • $<id>$<salt>$<password hash>

  • $<id>$<parameter>$<salt>$<password hash>

The '$0$' prefix signals that the value is clear text. When such a value is received by the server, a hash value is calculated, and the string '$<id>$<salt>$' or $<id>$<parameter>$<salt>$ is prepended to the result. This value is stored in the configuration data store.

If a value starting with '$<id>$', where <id> is not '0', is received, the server knows that the value already represents a hashed value, and stores it as is in the data store.

When a server needs to verify a password given by a user, it finds the stored password hash string for that user, extracts the salt, and calculates the hash with the salt and given password as input. If the calculated hash value is the same as the stored value, the password given by the client is accepted.

This type defines the following hash functions:

Id Hash Function Feature
1 MD5 crypt-hash-md5
5 SHA-256 crypt-hash-sha-256
6 SHA-512 crypt-hash-sha-512

The server indicates support for the different hash functions by advertising the corresponding feature.

Reference:

  • IEEE Std 1003.1-2008 - crypt() function

  • RFC 1321: The MD5 Message-Digest Algorithm

  • FIPS.180-3.2008: Secure Hash Standard