des_set_key() -- SSLeay 0.9.0b -- January 1999

NAME

des_set_odd_parity, des_is_weak_key, des_set_key, des_key_sched, des_string_to_key,
des_string_to_2keys, des_random_key, des_xwhite_in2out -- des key-handling functions

SYNOPSIS

#include "des.h"

int des_check_key;

void des_set_odd_parity(key)
des_cblock *key;

int des_is_weak_key(key)
des_cblock *key;

int des_set_key(key,schedule)
des_cblock *key;
des_key_schedule schedule;

int des_key_sched(key,schedule)
des_cblock *key;
des_key_schedule schedule;

void des_string_to_key(str,key)
char *str;
des_cblock *key;

void des_string_to_2keys(str,key1,key2)
char *str;
des_cblock *key1, *key2;

void des_random_key(ret)
des_cblock ret;

void des_xwhite_in2out((des_key,in_white,out_white)
des_cblock (*des_key);
des_cblock (*in_white);
des_cblock (*out_white);

DESCRIPTION

All of the encryption functions take what is called a des_key_schedule as an argument. A des_key_schedule is an expanded form of the des key. A des_key is 8 bytes of odd parity, the type used to hold the key is a des_cblock. A des_cblock is an array of 8 bytes.

The functions and global variable are as follows:

des_check_key: DES keys are supposed to be odd parity. If this variable is set to a non-zero value, des_set_key() will check that the key has odd parity and is not one of the known weak DES keys. By default this variable is turned off.

des_set_odd_parity() takes a DES key (8 bytes) and sets the parity to odd.

des_is_weak_key() returns a non-zero value if the DES key passed is a weak or semi-weak DES key. If it is a weak or semi-weak key, don't use it; try a different one. If you are using 'random' keys, the chances of hitting a weak key are 1/2^52 so it is probably not worth checking for them. For more information about weak keys, see DES weak, semi-weak, and possibly-weak keys.

des_set_key() converts an 8 byte DES key into a des_key_schedule. A des_key_schedule is an expanded form of the key which is used to perform actual encryption. It can be regenerated from the DES key so it only needs to be kept when encryption or decryption is about to occur. Don't save or pass around des_key_schedules since they are CPU architecture dependent, DES keys are not. If des_check_key is non zero, zero is returned if the key has the wrong parity or the key is a weak or semi-weak key, else 1 is returned.

des_key_sched() is an alternative name for des_set_key().

des_string_to_key() takes str and converts it into a DES key. This routine is compatible with the one in MIT's libdes. Not recommended for use; use MD5 on the key and take the first 8 bits of the hash output instead.

des_string_to_2keys() takes str and converts it into 2 DES keys. Not recommended for use: use MD5 on the key and take the full 16 bytes of the hash output instead, 8 bytes for each key.

des_random_key() returns a random key. Make sure to 'seed' the random number generator (with des_random_seed()) before using this function. Not recommended for use; an MD5-based random number system is now available.

des_xwhite_in2out() is used only in the implementation of the DESX algorithm; this is the function that 'whitens' the key using in_white and out_white. You should have no reason to call it directly.