Extended Library Functions crypt(3EXT)
NAME
crypt, setkey, encrypt, des_crypt, des_setkey, des_encrypt,
run_setkey, run_crypt, crypt_close - password and file
encryption functionsSYNOPSIS
cc [ flag ... ] file ... -lcrypt [ library ... ]
#include
char *crypt(const char *key, const char *salt); void setkey(const char *key); void encrypt(char *block, int flag);char *des_crypt(const char *key, const char *salt);
void des_setkey(const char *key);
void des_encrypt(char *block, int flag);
int run_setkey(int *p, const char *key);
int run_crypt(long offset, char *buffer, unsigned int count,
int *p);int crypt_close(int *p);
DESCRIPTION
des_crypt() is the password encryption function. It is based
on a one-way hashing encryption algorithm with variations
intended (among other things) to frustrate use of hardware implementations of a key search.key is a user's typed password. salt is a two-character
string chosen from the set [a-zA-Z0-9./]; this string is
used to perturb the hashing algorithm in one of 4096 dif-
ferent ways, after which the password is used as the key to encrypt repeatedly a constant string. The returned value points to the encrypted password. The first two characters are the salt itself.SunOS 5.11 Last change: 3 Mar 2008 1
Extended Library Functions crypt(3EXT)The des_setkey() and des_encrypt() entries provide (rather
primitive) access to the actual hashing algorithm. The argu-
ment of des_setkey() is a character array of length 64 con-
taining only the characters with numerical value 0 and 1. Ifthis string is divided into groups of 8, the low-order bit
in each group is ignored, thereby creating a 56-bit key that
is set into the machine. This key is the key that will be used with the hashing algorithm to encrypt the string blockwith the function des_encrypt().
The argument to the des_encrypt() entry is a character array
of length 64 containing only the characters with numerical value 0 and 1. The argument array is modified in place to a similar array representing the bits of the argument after having been subjected to the hashing algorithm using the keyset by des_setkey(). If flag is zero, the argument is
encrypted; if non-zero, it is decrypted.
Note that decryption is not provided in the international version of crypt(). The international version is part of the C Development Set, and the domestic version is part of the Security Administration Utilities. If decryption isattempted with the international version of des_encrypt(),
an error message is printed.crypt(), setkey(), and encrypt() are front-end routines that
invoke des_crypt(), des_setkey(), and des_encrypt() respec-
tively.The routines run_setkey() and run_crypt() are designed for
use by applications that need cryptographic capabilities,such as ed(1) and vi(1). run_setkey() establishes a two-way
pipe connection with the crypt utility, using key as thepassword argument. run_crypt() takes a block of characters
and transforms the cleartext or ciphertext into their ciphertext or cleartext using the crypt utility. offset is the relative byte position from the beginning of the file that the block of text provided in block is coming from. count is the number of characters in block, and connectionis an array containing indices to a table of input and out-
put file streams. When encryption is finished,crypt_close() is used to terminate the connection with the
crypt utility.run_setkey() returns -1 if a connection with the crypt
utility cannot be established. This result will occur in international versions of the UNIX system in which the cryptSunOS 5.11 Last change: 3 Mar 2008 2
Extended Library Functions crypt(3EXT) utility is not available. If a null key is passed torun_setkey(), 0 is returned. Otherwise, 1 is returned.
run_crypt() returns -1 if it cannot write output or read
input from the pipe attached to crypt(). Otherwise it returns 0.The program must be linked with the object file access rou-
tine library libcrypt.a.RETURN VALUES
In the international version of crypt(), a flag argument of1 to encrypt() or des_encrypt() is not accepted, and errno
is set to ENOSYS to indicate that the functionality is not available.ATTRIBUTES
See attributes(5) for descriptions of the following attri-
butes:____________________________________________________________
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|_____________________________|_____________________________|
| MT-Level | Unsafe |
|_____________________________|_____________________________|
SEE ALSO
ed(1), login(1), passwd(1), vi(1), getpass(3C), passwd(4), attributes(5) NOTES The return value in crypt() points to static data that are overwritten by each call.SunOS 5.11 Last change: 3 Mar 2008 3