=pod =head1 NAME des_read_password, des_read_2password, des_string_to_key, des_string_to_2key, des_read_pw_string, des_random_key, des_set_key, des_key_sched, des_ecb_encrypt, des_ecb3_encrypt, des_cbc_encrypt, des_3cbc_encrypt, des_pcbc_encrypt, des_cfb_encrypt, des_ofb_encrypt, des_cbc_cksum, des_quad_cksum, des_enc_read, des_enc_write, des_set_odd_parity, des_is_weak_key, crypt - (non USA) DES encryption =head1 SYNOPSIS #include int des_read_password(des_cblock *key, char *prompt, int verify); int des_read_2password(des_cblock *key1, des_cblock *key2, char *prompt, int verify); int des_string_to_key(char *str, des_cblock *key); int des_string_to_2keys(char *str, des_cblock *key1, des_cblock *key2); int des_read_pw_string(char *buf, int length, char *prompt, int verify); int des_random_key(des_cblock *key); int des_set_key(des_cblock *key, des_key_schedule schedule); int des_key_sched(des_cblock *key, des_key_schedule schedule); int des_ecb_encrypt(des_cblock *input, des_cblock *output, des_key_schedule schedule, int encrypt); int des_ecb3_encrypt(des_cblock *input, des_cblock *output, des_key_schedule ks1, des_key_schedule ks2, int encrypt); int des_cbc_encrypt(des_cblock *input, des_cblock *output, long length, des_key_schedule schedule, des_cblock *ivec, int encrypt); int des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length, des_key_schedule sk1, des_key_schedule sk2, des_cblock *ivec1, des_cblock *ivec2, int encrypt); int des_pcbc_encrypt(des_cblock *input, des_cblock *output, long length, des_key_schedule schedule, des_cblock *ivec, int encrypt); int des_cfb_encrypt(unsigned char *input, unsigned char *output, int numbits, long length, des_key_schedule schedule, des_cblock *ivec, int encrypt); int des_ofb_encrypt(unsigned char *input, unsigned char *output, int numbits, long length, des_key_schedule schedule, des_cblock *ivec); unsigned long des_cbc_cksum(des_cblock *input, des_cblock *output, long length, des_key_schedule schedule, des_cblock *ivec); unsigned long des_quad_cksum(des_cblock *input, des_cblock *output, long length, int out_count, des_cblock *seed); int des_check_key; int des_enc_read(int fd, char *buf, int len, des_key_schedule sched, des_cblock *iv); int des_enc_write(int fd, char *buf, int len, des_key_schedule sched, des_cblock *iv); extern int des_rw_mode; void des_set_odd_parity(des_cblock *key); int des_is_weak_key(des_cblock *key); char *crypt(char *passwd, char *salt); =head1 DESCRIPTION This library contains a fast implementation of the DES encryption algorithm. There are two phases to the use of DES encryption. The first is the generation of a I from a key, the second is the actual encryption. A des key is of type I. This type is made from 8 characters with odd parity. The least significant bit in the character is the parity bit. The key schedule is an expanded form of the key; it is used to speed the encryption process. I writes the string specified by prompt to the standard output, turns off echo and reads an input string from standard input until terminated with a newline. If verify is non-zero, it prompts and reads the input again and verifies that both entered passwords are the same. The entered string is converted into a des key by using the I routine. The new key is placed in the I that was passed (by reference) to the routine. If there were no errors, I returns 0, -1 is returned if there was a terminal error and 1 is returned for any other error. I operates in the same way as I except that it generates two keys by using the I function. I is called by I to read and verify a string from a terminal device. The string is returned in I. The size of I is passed to the routine via the I parameter. I converts a string into a valid des key. I converts a string into two valid des keys. This routine is best suited for used to generate keys for use with I. I returns a random key that is made of a combination of process id, time and an increasing counter. Before a des key can be used, it is converted into a I via the I routine. If the I flag is non-zero, I will check that the key passed is of odd parity and is not a week or semi-weak key. If the parity is wrong, then -1 is returned. If the key is a weak key, then -2 is returned. If an error is returned, the key schedule is not generated. I is another name for the I function. The following routines mostly operate on an input and output stream of I's. I is the basic DES encryption routine that encrypts or decrypts a single 8-byte I in I mode. It always transforms the input data, pointed to by I, into the output data, pointed to by the I argument. If the I argument is non-zero (DES_ENCRYPT), the I (cleartext) is encrypted in to the I (ciphertext) using the key_schedule specified by the I argument, previously set via I. If I is zero (DES_DECRYPT), the I (now ciphertext) is decrypted into the I (now cleartext). Input and output may overlap. No meaningful value is returned. I encrypts/decrypts the I block by using triple ecb DES encryption. This involves encrypting the input with I, decryption with the key schedule I, and then encryption with the first again. This routine greatly reduces the chances of brute force breaking of DES and has the advantage of if I and I are the same, it is equivalent to just encryption using ecb mode and I as the key. I encrypts/decrypts using the I mode of DES. If the I argument is non-zero, the routine cipher-block-chain encrypts the cleartext data pointed to by the I argument into the ciphertext pointed to by the I argument, using the key schedule provided by the I argument, and initialization vector provided by the I argument. If the I argument is not an integral multiple of eight bytes, the last block is copied to a temporary area and zero filled. The output is always an integral multiple of eight bytes. To make multiple cbc encrypt calls on a large amount of data appear to be one I call, the I of subsequent calls should be the last 8 bytes of the output. I encrypts/decrypts the I block by using triple cbc DES encryption. This involves encrypting the input with key schedule I, decryption with the key schedule I, and then encryption with the first again. Two initialization vectors are required, I and I. Unlike I, these initialization vectors are modified by the subroutine. This routine greatly reduces the chances of brute force breaking of DES and has the advantage of if I and I are the same, it is equivalent to just encryption using cbc mode and I as the key. I encrypt/decrypts using a modified block chaining mode. It provides better error propagation characteristics than cbc encryption. I encrypt/decrypts using cipher feedback mode. This method takes an array of characters as input and outputs and array of characters. It does not require any padding to 8 character groups. Note: the ivec variable is changed and the new changed value needs to be passed to the next call to this function. Since this function runs a complete DES ecb encryption per numbits, this function is only suggested for use when sending small numbers of characters. I encrypt using output feedback mode. This method takes an array of characters as input and outputs and array of characters. It does not require any padding to 8 character groups. Note: the ivec variable is changed and the new changed value needs to be passed to the next call to this function. Since this function runs a complete DES ecb encryption per numbits, this function is only suggested for use when sending small numbers of characters. I produces an 8 byte checksum based on the input stream (via cbc encryption). The last 4 bytes of the checksum is returned and the complete 8 bytes is placed in I. I returns a 4 byte checksum from the input bytes. The algorithm can be iterated over the input, depending on I, 1, 2, 3 or 4 times. If I is non-NULL, the 8 bytes generated by each pass are written into I. I is used to write I bytes to file descriptor I from buffer I. The data is encrypted via I (default) using I for the key and I as a starting vector. The actual data send down I consists of 4 bytes (in network byte order) containing the length of the following encrypted data. The encrypted data then follows, padded with random data out to a multiple of 8 bytes. I is used to read I bytes from file descriptor I into buffer I. The data being read from I is assumed to have come from I and is decrypted using I for the key schedule and I for the initial vector. The I pair can be used to read/write to files, pipes and sockets. I have used them in implementing a version of rlogin in which all data is encrypted. I is used to specify the encryption mode to use with I and I. If set to I (the default), des_pcbc_encrypt is used. If set to I des_cbc_encrypt is used. These two routines and the variable are not part of the normal MIT library. I sets the parity of the passed I to odd. This routine is not part of the standard MIT library. I returns 1 is the passed key is a weak key (pick again :-), 0 if it is ok. This routine is not part of the standard MIT library. I is a replacement for the normal system crypt. It is much faster than the system crypt. =head1 BUGS I and I operates on input of 8 bits. What this means is that if you set numbits to 12, and length to 2, the first 12 bits will come from the 1st input byte and the low half of the second input byte. The second 12 bits will have the low 8 bits taken from the 3rd input byte and the top 4 bits taken from the 4th input byte. The same holds for output. This function has been implemented this way because most people will be using a multiple of 8 and because once you get into pulling bytes input bytes apart things get ugly! I is the most machine/OS dependent function and normally generates the most problems when porting this code. I is probably different from the MIT version since there are lots of fun ways to implement one-way encryption of a text string. =head1 AUTHOR Eric Young (eay@cryptsoft.com) =cut