after looking at the source , it look like they are using md5 with crypt()
you can check with these source file from "shadow-4.0.7" package :
encrypt.c
salt.c
pwdauth.c
for my linux if i want to encrypt with md5 shadow ,
i need to compile the package to get the libshadow.a ,
then use function " pw_encrypt(const char *clear, const char *salt) "
i also need to adapt function " crypt_make_salt (void) " from salt.c
below is a code(no checking/debug just for compile/test )that link with libshadow.a
gcc 001.c -o 001 -lshadow -lcrypt
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/time.h>
#include <pwd.h>
#include <shadow.h>
extern char *l64a ();
extern char *pw_encrypt();
//#define crypt pw_encrypt
char *crypt_make_salt (void)
{
struct timeval tv;
static char result[40];
result[0] = '\0';
strcpy (result, "$1$"); /* magic for the new MD5 crypt() */
// Generate 8 chars of salt, the old crypt() will use only first 2.
gettimeofday (&tv, (struct timezone *) 0);
strcat (result, l64a (tv.tv_usec));
strcat (result, l64a (tv.tv_sec + getpid () + clock ()));
if (strlen (result) > 3 + 8) /* magic+salt */
result[11] = '\0';
return result;
}
int main()
{
char *salt;
char *cp;
char *CryptP;
char *NCryptP;
struct spwd *spwd;
struct spwd *getspnam();
// pw = getpwnam("userName");
spwd = getspnam("userName");
if (spwd)
cp = spwd->sp_pwdp;
// check for matching userName/password
CryptP = pw_encrypt("userPassword",cp);
if (strcmp(CryptP, cp) == 0)
printf("\nCorrect password = %s \n",CryptP); else
printf("Fail password = %s \n",CryptP) ;
printf("spwd->sp_pwdp = %s \n",cp);
// create new MD5 crypt password
salt=crypt_make_salt();
NCryptP = pw_encrypt("myPassword",salt);
printf("\nNew password = %s \n",NCryptP);
printf("salt = %s \n\n",salt);
return 0;
}
i'm still not sure whether this is the correct way to work with shadow ,
there might be better or staright forward way ,
it's better to verify with someone experience in shadow or cryptography
hope that these at least can help you in some way or other