'How does salt get used in openssl passwd hash (md5)?

I was trying to manually generate the password hash stored in /etc/shadow (just for curiosity).

For example using salt a and password a with md5 hash algorithm, with the command

openssl passwd -1 -salt "a" a

i get

$1$a$44cUw6Nm5bX0muHWNIwub0

Where 1 correspond to md5 hashing algorithm, a is the salt and 44cUw6Nm5bX0muHWNIwub0 should be the actual hash.

I was expecting to get the same result calculating the md5 hash of aa (password and hash concatenated), and converting it in B64 (as explained on wikipedia) but I get a different output.

What is the right way to hash and encode the password and the salt?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source