encrypt() — Encoding function

Standards

Standards / Extensions C or C++ Dependencies

XPG4
XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _XOPEN_SOURCE
#include <unistd.h>

void encrypt(char block[64], int edflag);

General description

The encrypt() function uses an array of 16 48-bit keys produced by the setkey() function to encode bytes specified by the block argument according to the Data Encryption Standard (DES) encryption algorithm or to decode argument bytes according to the DES decryption algorithm.

The block argument of encrypt() is an array of length 64 bytes containing only the bytes with numerical value of 0 and 1. The array is modified in place using keys produced by setkey(). If edflag is 0, the argument is encoded using the DES encryption algorithm. If edflag is 1 the argument is decoded using the DES decryption algorithm.

Special behavior for z/OS® UNIX Services: The encrypt() function is thread-specific. Thus, for each thread from which the encrypt() function is called by a threaded application, the setkey() function must first be called from the thread to establish a DES key array for the thread.

Returned value

encrypt() returns no values.

Special behavior for z/OS UNIX Services: encrypt() will set errno to one of the following values:
Error Code
Description
EINVAL
64 byte input array contains bytes with values other than 0x00 or 0x01.
ENOMEM
If setkey() has not been called or failed to produce a DES key array for the thread from which encrypt() is called.
ENOSYS
If DES key array exists for thread from which encrypt() is called to decode data.
Note: Because encrypt() returns no values, applications wishing to check for errors should set errno to 0, call encrypt(), then test errno and, if it is nonzero, assume an error has occurred.

Related information