DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

crypt(S)


crypt -- password and file encryption functions

Syntax

cc . . . -lcrypt

#include <stdlib.h>
void setkey (key)
char *key;

#include <unistd.h> char *crypt (key, salt) const char *key, *salt;

#include <unistd.h> void encrypt (block, flag) char *block; int flag;

#include <crypt.h>

char *des_crypt (key, salt) char *key, *salt;

void des_encrypt (block, flag) char *block; int flag;

void des_setkey (key) char *key;

int run_setkey (p, key) int p[2]; char *key;

int run_crypt (offset, buffer, count, p) long offset; char *buffer; unsigned int count; int p[2];

int crypt_close(p) int p[2];

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-z,A-Z,0-9,.,/]. This string is used to perturb the hashing algorithm in one of 4096 different 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.

The des_setkey and des_encrypt entries provide (rather primitive) access to the actual hashing algorithm. The argument of des_setkey is a character array of length 64 containing only the characters with numerical value 0 and 1. If this string is divided into groups of 8, the low-order bit in each group is ignored; this gives a 56-bit key which is set into the machine. This is the key that is used with the hashing algorithm to encrypt the string block with 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 key set by des_setkey.

In the international version of crypt(S) a flag argument of 1 to encrypt() or des_encrypt() is not accepted, and errno is set to [ENOSYS] to indicate that the functionality is not available.

crypt, setkey, and encrypt are front-end routines that invoke des_crypt, des_setkey, and des_encrypt respectively.

The routines run_setkey and run_crypt are designed for use by applications that need cryptographic capabilities (such as ed(C) and vi(C)) that must be compatible with the crypt(C) user-level utility. run_setkey establishes a two-way pipe connection with crypt(C), using key as the password argument.

run_crypt takes a block of characters and transforms the cleartext or ciphertext using crypt(C). offset is the relative byte position from the beginning of the file that the block of text provided in buffer is coming from. count is the number of characters in buffer, and p is an array containing file descriptor indices to a table of input and output file streams. When encryption is finished, crypt_close is used to terminate the connection with crypt(C).

Return values

crypt and des_crypt return a pointer to the string representing the encrypted password.

run_crypt returns -1 if it cannot write output or read input from the pipe attached to crypt. Otherwise it returns 0.

run_setkey returns -1 if a connection with crypt(C) cannot be established. This occurs on international versions of the Operating System where crypt(C) is not available. If a null key is passed to run_setkey, 0 is returned. Otherwise, 1 is returned.

crypt_close returns 0 if it successfully terminated the connection with crypt(C). Otherwise, it returns -1.

setkey, des_setkey, encrypt, and des_encrypt do not have return values.

Diagnostics

In the international version of crypt(S), a flag argument of 1 to des_encrypt is not accepted, and errno is set to [ENOSYS] to indicate that the functionality is not available.

Note

The return value in crypt points to static data that is overwritten by each call.

See also

crypt(C), getpass(S), login(M), passwd(C), passwd(FP)

Standards conformance

crypt is conformant with:

X/Open Portability Guide, Issue 3, 1989 .


© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003