0

After user password change the size of salt decreased in RHEL/Centos 6, eg:

cat /etc/shadow

... root:$6$FkMNsNxT$FW77....................nbL0...... bin:*:15422:0:99999:7::: ...

As you can see, FkMNsNxT is 8 characters.

Why it happens? In the beginning, after installation, the size is 16 chars.

  • Did you change password encryption algorithm? A 16 character salt means 128 bits, which indicates another algorithm than sha512crypt which is what the current password is encoded with (see man 5 crypt). – Kusalananda Aug 17 '21 at 17:00
  • No, password encryption not changed – user13726895 Aug 17 '21 at 17:07
  • If you say that the salt was 128 bits previously, then the encryption method has obviously changed. – Kusalananda Aug 17 '21 at 17:15
  • @Kusalananda, no, that doesn't follow. both the sha256crypt and sha512crypt algorithms can take variable-length salts. This is quite a valid hash of the password foobar: $6$abc$cyugVWWBuhMmAXlbiQBF7DHoFwA0ff6g9AF6j6N1EKMUXHyGGvjkzhQdzV13AFJpV7xnnx8eC.f372Ypp1Zug. – ilkkachu Aug 17 '21 at 18:30
  • @ilkkachu I might obviously be interpreting the crypt(5) manual wrong when it says that sha512crypt uses a variable salt of between 6 and 96 bits (less than 128 bits). The entry that you show seems to be using a 24 bit salt (the abc value). – Kusalananda Aug 17 '21 at 18:32
  • @Kusalananda, ah, hmm. 16 chars of base64 encoded data would be 16*6 = 96 bits, which might explain it. They can't be arbitrary bytes anyway, since $, : and newline are used as separators in /etc/shadow and other control chars might also cause issues. I tested that with Perl, and it cuts the salt at 16 chars (but didn't enforce the base64 alphabet, allowing hashes like $6$!!!$, but they didn't work with the actual PAM module) – ilkkachu Aug 17 '21 at 18:41
  • @ilkkachu The salt is base64-encoded? Ah, yes it is, in a way. Well then. Then it's just a matter of the OP getting another salt value. I don't really see an issue here any longer. – Kusalananda Aug 17 '21 at 18:47
  • yep, base64 but with a custom alphabet (./0-9A-Za-z vs. the more standard A-Za-z0-9+/, so the order is different too, not just the two special chars) – ilkkachu Aug 17 '21 at 19:05

1 Answers1

0

It's up to the program that creates the password hash to determine the salt, and its length. Based on what I've looked up before, there's at least two different pieces of code for that going around. E.g. on Debian/Ubuntu, changing the password via PAM (with passwd), creates a 16 character salt always, but using chpasswd -a SHA512 creates a variable-length salt. On RHEL/CentOS plain passwd used the latter algorithm when I last tested.

The installer probably just uses different code than whatever the user used to change their password.

ilkkachu
  • 138,973