Node:DES Encryption, Previous:crypt, Up:Cryptographic Functions
The Data Encryption Standard is described in the US Government Federal Information Processing Standards (FIPS) 46-3 published by the National Institute of Standards and Technology. The DES has been very thoroughly analyzed since it was developed in the late 1970s, and no new significant flaws have been found.
However, the DES uses only a 56-bit key (plus 8 parity bits), and a machine has been built in 1998 which can search through all possible keys in about 6 days, which cost about US$200000; faster searches would be possible with more money. This makes simple DES insecure for most purposes, and NIST no longer permits new US government systems to use simple DES.
For serious encryption functionality, it is recommended that one of the many free encryption libraries be used instead of these routines.
The DES is a reversible operation which takes a 64-bit block and a 64-bit key, and produces another 64-bit block. Usually the bits are numbered so that the most-significant bit, the first bit, of each block is numbered 1.
Under that numbering, every 8th bit of the key (the 8th, 16th, and so on) is not used by the encryption algorithm itself. But the key must have odd parity; that is, out of bits 1 through 8, and 9 through 16, and so on, there must be an odd number of `1' bits, and this completely specifies the unused bits.
void setkey (const char *key) | Function |
The |
void encrypt (char *block, int edflag) | Function |
The Like |
void setkey_r (const char *key, struct crypt_data * data) | Function |
void encrypt_r (char *block, int edflag, struct crypt_data * data) | Function |
These are reentrant versions of |
The setkey_r
and encrypt_r
functions are GNU extensions.
setkey
, encrypt
, setkey_r
, and encrypt_r
are
defined in crypt.h
.
int ecb_crypt (char *key, char *blocks, unsigned len, unsigned mode) | Function |
The function The blocks and the key are stored packed in 8-bit bytes, so
that the first bit of the key is the most-significant bit of
len is the number of bytes in blocks. It should be a
multiple of 8 (so that there is a whole number of blocks to encrypt).
len is limited to a maximum of The result of the encryption replaces the input in blocks. The mode parameter is the bitwise OR of two of the following:
The result of the function will be one of these values:
|
int DES_FAILED (int err) | Function |
This macro returns 1 if err is a `success' result code from
ecb_crypt or cbc_crypt , and 0 otherwise.
|
int cbc_crypt (char *key, char *blocks, unsigned len, unsigned mode, char *ivec) | Function |
The function For encryption in CBC mode, each block is exclusive-ored with ivec before being encrypted, then ivec is replaced with the result of the encryption, then the next block is processed. Decryption is the reverse of this process. This has the advantage that blocks which are the same before being encrypted are very unlikely to be the same after being encrypted, making it much harder to detect patterns in the data. Usually, ivec is set to 8 random bytes before encryption starts. Then the 8 random bytes are transmitted along with the encrypted data (without themselves being encrypted), and passed back in as ivec for decryption. Another possibility is to set ivec to 8 zeroes initially, and have the first the block encrypted consist of 8 random bytes. Otherwise, all the parameters are similar to those for |
void des_setparity (char *key) | Function |
The function |
The ecb_crypt
, cbc_crypt
, and des_setparity
functions and their accompanying macros are all defined in the header
rpc/des_crypt.h
.