crypt, encrypt, or setkey Subroutine

Purpose

Encrypts or decrypts data.

Library

Standard C Library (libc.a)

Syntax

char *crypt (PW, Salt)
const char * PW, * Salt;
void encrypt (Block, EdFlag)
char Block[64];
int EdFlag;
void setkey (Key)
const char * Key;

Description

The crypt and encrypt subroutines encrypt or decrypt data. The crypt subroutine performs a one-way encryption of a fixed data array with the supplied PW parameter. The subroutine uses the Salt parameter to vary the encryption algorithm.

The encrypt subroutine encrypts or decrypts the data supplied in the Block parameter using the key supplied by an earlier call to the setkey subroutine. The data in the Block parameter on input must be an array of 64 characters. Each character must be an char 0 or char 1.

If you need to statically bind functions from libc.a for crypt do the following:

  1. Create a file and add the following:
    #!
    ___setkey
    ___encrypt
    ___crypt
  2. Perform the linking.
  3. Add the following to the make file:
    -bI:YourFileName
    where YourFileName is the name of the file you created in step 1. It should look like the following:
    LDFLAGS=bnoautoimp -bI:/lib/syscalls.exp -bI:YourFileName -lc

These subroutines are provided for compatibility with UNIX system implementations.

Parameters

Item Description
Block Identifies a 64-character array containing the values (char) 0 and (char) 1. Upon return, this buffer contains the encrypted or decrypted data.
EdFlag Determines whether the subroutine encrypts or decrypts the data. If this parameter is 0, the data is encrypted. If this parameter is a nonzero value, the data is decrypted. If the /usr/lib/libdes or /usr/lib/libdes_64 file does not exist and if the EdFlag parameter is set to a nonzero value, the encrypt subroutine returns the ENOSYS error code. The /usr/lib/libdes and /usr/lib/libdes_64 files are part of the des fileset, which is located in the AIX® Expansion Pack.
Key Specifies an 64-element array of 0's and 1's cast as a const char data type. The Key parameter is used to encrypt or decrypt data.
PW Specifies the string to be encrypted.
Salt Determines the algorithm that the PW parameter applies to generate the returned output string. If the left brace ( { ) is not the first character of the value that the Salt parameter specifies, then the subroutine uses the Data Encryption Standard (DES) algorithm. For the DES algorithm, use the Salt parameter to vary the hashing algorithm in the one of 4096 ways. The Salt parameter must be a 2-character string that is from the following character types:
A-Z
Uppercase alpha characters
a-z
Lowercase alpha characters
0-9
Numeric characters
.
Period
/
Slash
If the left brace ( { ) is the first character of the value that the Salt parameter specifies, then the Loadable Password Algorithm (LPA) uses the name that is specified within the braces ( {} ). A set of salt characters follows the LPA name and ends with a dollar sign ($). The length of the salt character depends on the specified LPA. The following example shows a possible value for the SMD5 LPA that the Salt parameter specifies:
{SMD5}JVDbGx8K$

Return Values

The crypt subroutine returns a pointer to the encrypted password. The static area this pointer indicates may be overwritten by subsequent calls.

If the crypt subroutine is unsuccessful, a null pointer is returned and the errno global variable is set to indicate the error.

Error Codes

The encrypt subroutine returns the following error codes:

Item Description
ENOSYS The encrypt subroutine was called by using the EdFlag parameter that was set to a nonzero value. Also, the /usr/lib/libdes or /usr/lib/libdes_64 file does not exist. The /usr/lib/libdes and /usr/lib/libdes_64 files are part of the des fileset, which is located in the AIX Expansion Pack.