/* * modified by: G. D. LaBossiere, Xview Solutions Inc. * last modified: 2015-07-15 * license: GNU GPL v3 * comments: requires 2 parameters on the command line: * (cannot be empty) (2 to 16 characters); returns a * sha512 encrypted hash in /etc/shadow format, i.e. $6$salt$password_hash * compile for your machine's arch: * /usr/bin/gcc -lcrypt -o passwd-sha512 passwd-sha512.c * to use an openssl-generated random salt: * passwd-sha512 "password_to_hash" "$(openssl rand -base64 16 | tr -d '+=' | head -c 16)" * adapted from http://serverfault.com/questions/330069/ */ #define XOPEN_SOURCE #include #include #include #include int main(int argc, char *argv[]) { if ( argc < 3 || (int) strlen(argv[1]) < 1 || (int) strlen(argv[2]) < 2 || \ (int) strlen(argv[2]) > 16 ) { printf("Usage:\t%s \n", argv[0]); printf("\tPassword cannot be empty."); printf(" Salt must be from 2 to 16 characters.\n"); return; } char salt[21]; sprintf(salt, "$6$%s$", argv[2]); printf("%s\n", crypt((char*) argv[1], (char*) salt)); return; }