setkey() — Set encoding key

Standards

Standards / Extensions C or C++ Dependencies

XPG4
XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _XOPEN_SOURCE
#include <stdlib.h>

void setkey(const char *key);

General description

The setkey() function transforms the key argument array into data encryption keys which are used by the encrypt() function to encode blocks of data.

The key argument of setkey() is an array of length 64 bytes containing only the bytes with numerical value of 0 and 1. If this 64 byte array is divided into groups of 8, the low-order byte of each group is ignored. The setkey() function transforms the remaining 56 bytes, each with values 0 or 1, into 16 48-bit keys according to the Data Encryption Standard (DES) key algorithm.

Special behavior for z/OS® UNIX Services: When setkey() is called from a thread, the array of 16 bit-bit keys produced by setkey() is unique to the thread. Thus, for each thread from which the encrypt() function is called by a threaded application, the setkey() function must first be called from each thread.

Returned value

setkey() returns no values.

Special behavior for z/OS UNIX Services: The setkey() function will fail if:
Error Code
Description
EINVAL
64 byte input array contains bytes with values other than 0x00 or 0x01.
ENOMEM
Unable to allocate storage for DES keys on thread from which setkey() invoked.
Note: Because setkey() returns no values, applications wishing to check for errors should set errno to 0, call setkey(), then test errno and, if it is nonzero, assume an error has occurred.