Pass a salt to mkpasswd with yescrypt algorithm

encryptionwhois

I am trying to verify this hashed password from my /etc/shadow file:
$y$j9T$eia4V8bEUD9QBJAEwilXU.$TLUJexdhrx/q3Nc/YaCrlkVkrxUkimYn3o432pxFr90

I would like to pass the hash to mkpasswd this way but it fails:

$ mkpasswd -m yescrypt secret eia4V8bEUD9QBJAEwilXU.
Wrong salt length: 22 bytes when 0 expected.

$ mkpasswd -m yescrypt secret "$y$j9T$eia4V8bEUD9QBJAEwilXU.$"
crypt: Invalid argument

How can I pass the salt or parameters from the hashed string?

By the way, I have found a way to verify the password with a python script as described in this SO post, so it means we have enough info (parameters and salt) to compute the hash. But I would prefer to do it with mkpasswd:

$ python3 -c 'import crypt, os; print(crypt.crypt("secret", "$y$j9T$eia4V8bEUD9QBJAEwilXU.$"))'
$y$j9T$eia4V8bEUD9QBJAEwilXU.$TLUJexdhrx/q3Nc/YaCrlkVkrxUkimYn3o432pxFr90

Best Answer

If you pass the salt (eg with -S or as the second param) and include the $ settings then you don't need to specify the method

% mkpasswd -S '$y$j9T$eia4V8bEUD9QBJAEwilXU.' secret
$y$j9T$eia4V8bEUD9QBJAEwilXU.$TLUJexdhrx/q3Nc/YaCrlkVkrxUkimYn3o432pxFr90

% mkpasswd secret '$y$j9T$eia4V8bEUD9QBJAEwilXU.'       
$y$j9T$eia4V8bEUD9QBJAEwilXU.$TLUJexdhrx/q3Nc/YaCrlkVkrxUkimYn3o432pxFr90
Related Question