Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is the encryption method used on /etc/shadow?

Which is the encryption method used on /etc/shadow on GNU/Linux systems? I would like to write a small program for personal purpose that uses the same API, but at the moment I don't know where to start.

Thanks in advance

like image 947
b3h3m0th Avatar asked Sep 30 '12 11:09

b3h3m0th


2 Answers

Use the crypt(3) function. On glibc, the method used depends on the salt, if it starts with:

  • $1$: it uses MD5.
  • $5$: it uses SHA-256.
  • $6$: it uses SHA-512.
  • $2a$: it uses blowfish, not supported everywhere.
  • Otherwise it uses DES.
like image 110
ninjalj Avatar answered Oct 14 '22 06:10

ninjalj


Multiple encryption methods are available in glibc, see man 3 crypt, the Glibc Notes section: http://manpages.courier-mta.org/htmlman3/crypt.3.html

When verifying an existing password, just pass the encrypted form as salt; only the initial $id$salt part will be used. When creating new password, initialize id with whatever you need and put some random characters in salt.

like image 32
Petr Baudis Avatar answered Oct 14 '22 08:10

Petr Baudis