crypto(3) is a function that provides basic criptography. It is at a so basic level that for serious work other than that of generating a shadowed password on the system, it is not recommended (as per a statement in its own man page).
The function is declared in the crypt.h file:
extern char *crypt (__const char *__key, __const char *__salt)
The input is a raw password string and a salt string, which is an additional value that provides a certain level of randomness to crypto’s hash generation process, so that there is not a single hash that may be produced for the same password, but several instead. If one provides a salt A, the output for the password X is Y whereas another salt B is passed, the output hash cannot be Y anymore, it will be some other hash Z.
I made a program in C which uses it, whose source code file I named cryptifier.c that has the following content:
#include <crypt.h>
#include <stdio.h>
#define _XOPEN_SOURCE
#include <unistd.h>
int main(int argc, char **argv) {
const char *k = (const char *) argv[1];
const char *s = (const char *) argv[2];
char* r;
printf("'%s' with salt '%s' generates '%s'\n", k, s, crypt(k, s));
return 0;
}
The output of this function can be served as an input argument for useradd command’s -p option as described in a previous post.
IMPORTANT remark: when compiling a program that uses crypt.h now and having libc-6 it is necessary to specify -lcrypt (for libcrypt) on the gcc command line as libc-5 used to have crypt() in libc, whereas libc-6 has it in libcrypt (this is very old change, dated at least of 1998: source post).