1des(3)                              OpenSSL                             des(3)
2
3
4

NAME

6       DES_random_key, DES_set_key, DES_key_sched, DES_set_key_checked,
7       DES_set_key_unchecked, DES_set_odd_parity, DES_is_weak_key,
8       DES_ecb_encrypt, DES_ecb2_encrypt, DES_ecb3_encrypt, DES_ncbc_encrypt,
9       DES_cfb_encrypt, DES_ofb_encrypt, DES_pcbc_encrypt, DES_cfb64_encrypt,
10       DES_ofb64_encrypt, DES_xcbc_encrypt, DES_ede2_cbc_encrypt,
11       DES_ede2_cfb64_encrypt, DES_ede2_ofb64_encrypt, DES_ede3_cbc_encrypt,
12       DES_ede3_cbcm_encrypt, DES_ede3_cfb64_encrypt, DES_ede3_ofb64_encrypt,
13       DES_cbc_cksum, DES_quad_cksum, DES_string_to_key, DES_string_to_2keys,
14       DES_fcrypt, DES_crypt, DES_enc_read, DES_enc_write - DES encryption
15

SYNOPSIS

17        #include <openssl/des.h>
18
19        void DES_random_key(DES_cblock *ret);
20
21        int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule);
22        int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule);
23        int DES_set_key_checked(const_DES_cblock *key,
24               DES_key_schedule *schedule);
25        void DES_set_key_unchecked(const_DES_cblock *key,
26               DES_key_schedule *schedule);
27
28        void DES_set_odd_parity(DES_cblock *key);
29        int DES_is_weak_key(const_DES_cblock *key);
30
31        void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
32               DES_key_schedule *ks, int enc);
33        void DES_ecb2_encrypt(const_DES_cblock *input, DES_cblock *output,
34               DES_key_schedule *ks1, DES_key_schedule *ks2, int enc);
35        void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
36               DES_key_schedule *ks1, DES_key_schedule *ks2,
37               DES_key_schedule *ks3, int enc);
38
39        void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output,
40               long length, DES_key_schedule *schedule, DES_cblock *ivec,
41               int enc);
42        void DES_cfb_encrypt(const unsigned char *in, unsigned char *out,
43               int numbits, long length, DES_key_schedule *schedule,
44               DES_cblock *ivec, int enc);
45        void DES_ofb_encrypt(const unsigned char *in, unsigned char *out,
46               int numbits, long length, DES_key_schedule *schedule,
47               DES_cblock *ivec);
48        void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
49               long length, DES_key_schedule *schedule, DES_cblock *ivec,
50               int enc);
51        void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
52               long length, DES_key_schedule *schedule, DES_cblock *ivec,
53               int *num, int enc);
54        void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out,
55               long length, DES_key_schedule *schedule, DES_cblock *ivec,
56               int *num);
57
58        void DES_xcbc_encrypt(const unsigned char *input, unsigned char *output,
59               long length, DES_key_schedule *schedule, DES_cblock *ivec,
60               const_DES_cblock *inw, const_DES_cblock *outw, int enc);
61
62        void DES_ede2_cbc_encrypt(const unsigned char *input,
63               unsigned char *output, long length, DES_key_schedule *ks1,
64               DES_key_schedule *ks2, DES_cblock *ivec, int enc);
65        void DES_ede2_cfb64_encrypt(const unsigned char *in,
66               unsigned char *out, long length, DES_key_schedule *ks1,
67               DES_key_schedule *ks2, DES_cblock *ivec, int *num, int enc);
68        void DES_ede2_ofb64_encrypt(const unsigned char *in,
69               unsigned char *out, long length, DES_key_schedule *ks1,
70               DES_key_schedule *ks2, DES_cblock *ivec, int *num);
71
72        void DES_ede3_cbc_encrypt(const unsigned char *input,
73               unsigned char *output, long length, DES_key_schedule *ks1,
74               DES_key_schedule *ks2, DES_key_schedule *ks3, DES_cblock *ivec,
75               int enc);
76        void DES_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
77               long length, DES_key_schedule *ks1, DES_key_schedule *ks2,
78               DES_key_schedule *ks3, DES_cblock *ivec1, DES_cblock *ivec2,
79               int enc);
80        void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
81               long length, DES_key_schedule *ks1, DES_key_schedule *ks2,
82               DES_key_schedule *ks3, DES_cblock *ivec, int *num, int enc);
83        void DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out,
84               long length, DES_key_schedule *ks1,
85               DES_key_schedule *ks2, DES_key_schedule *ks3,
86               DES_cblock *ivec, int *num);
87
88        DES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output,
89               long length, DES_key_schedule *schedule,
90               const_DES_cblock *ivec);
91        DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
92               long length, int out_count, DES_cblock *seed);
93        void DES_string_to_key(const char *str, DES_cblock *key);
94        void DES_string_to_2keys(const char *str, DES_cblock *key1,
95               DES_cblock *key2);
96
97        char *DES_fcrypt(const char *buf, const char *salt, char *ret);
98        char *DES_crypt(const char *buf, const char *salt);
99
100        int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
101               DES_cblock *iv);
102        int DES_enc_write(int fd, const void *buf, int len,
103               DES_key_schedule *sched, DES_cblock *iv);
104

DESCRIPTION

106       This library contains a fast implementation of the DES encryption
107       algorithm.
108
109       There are two phases to the use of DES encryption.  The first is the
110       generation of a DES_key_schedule from a key, the second is the actual
111       encryption.  A DES key is of type DES_cblock. This type is consists of
112       8 bytes with odd parity.  The least significant bit in each byte is the
113       parity bit.  The key schedule is an expanded form of the key; it is
114       used to speed the encryption process.
115
116       DES_random_key() generates a random key.  The PRNG must be seeded prior
117       to using this function (see rand(3)).  If the PRNG could not generate a
118       secure key, 0 is returned.
119
120       Before a DES key can be used, it must be converted into the
121       architecture dependent DES_key_schedule via the DES_set_key_checked()
122       or DES_set_key_unchecked() function.
123
124       DES_set_key_checked() will check that the key passed is of odd parity
125       and is not a week or semi-weak key.  If the parity is wrong, then -1 is
126       returned.  If the key is a weak key, then -2 is returned.  If an error
127       is returned, the key schedule is not generated.
128
129       DES_set_key() works like DES_set_key_checked() if the DES_check_key
130       flag is non-zero, otherwise like DES_set_key_unchecked().  These
131       functions are available for compatibility; it is recommended to use a
132       function that does not depend on a global variable.
133
134       DES_set_odd_parity() sets the parity of the passed key to odd.
135
136       DES_is_weak_key() returns 1 is the passed key is a weak key, 0 if it is
137       ok.  The probability that a randomly generated key is weak is 1/2^52,
138       so it is not really worth checking for them.
139
140       The following routines mostly operate on an input and output stream of
141       DES_cblocks.
142
143       DES_ecb_encrypt() is the basic DES encryption routine that encrypts or
144       decrypts a single 8-byte DES_cblock in electronic code book (ECB) mode.
145       It always transforms the input data, pointed to by input, into the
146       output data, pointed to by the output argument.  If the encrypt
147       argument is non-zero (DES_ENCRYPT), the input (cleartext) is encrypted
148       in to the output (ciphertext) using the key_schedule specified by the
149       schedule argument, previously set via DES_set_key. If encrypt is zero
150       (DES_DECRYPT), the input (now ciphertext) is decrypted into the output
151       (now cleartext).  Input and output may overlap.  DES_ecb_encrypt() does
152       not return a value.
153
154       DES_ecb3_encrypt() encrypts/decrypts the input block by using three-key
155       Triple-DES encryption in ECB mode.  This involves encrypting the input
156       with ks1, decrypting with the key schedule ks2, and then encrypting
157       with ks3.  This routine greatly reduces the chances of brute force
158       breaking of DES and has the advantage of if ks1, ks2 and ks3 are the
159       same, it is equivalent to just encryption using ECB mode and ks1 as the
160       key.
161
162       The macro DES_ecb2_encrypt() is provided to perform two-key Triple-DES
163       encryption by using ks1 for the final encryption.
164
165       DES_ncbc_encrypt() encrypts/decrypts using the cipher-block-chaining
166       (CBC) mode of DES.  If the encrypt argument is non-zero, the routine
167       cipher-block-chain encrypts the cleartext data pointed to by the input
168       argument into the ciphertext pointed to by the output argument, using
169       the key schedule provided by the schedule argument, and initialization
170       vector provided by the ivec argument.  If the length argument is not an
171       integral multiple of eight bytes, the last block is copied to a
172       temporary area and zero filled.  The output is always an integral
173       multiple of eight bytes.
174
175       DES_xcbc_encrypt() is RSA's DESX mode of DES.  It uses inw and outw to
176       'whiten' the encryption.  inw and outw are secret (unlike the iv) and
177       are as such, part of the key.  So the key is sort of 24 bytes.  This is
178       much better than CBC DES.
179
180       DES_ede3_cbc_encrypt() implements outer triple CBC DES encryption with
181       three keys. This means that each DES operation inside the CBC mode is
182       really an "C=E(ks3,D(ks2,E(ks1,M)))".  This mode is used by SSL.
183
184       The DES_ede2_cbc_encrypt() macro implements two-key Triple-DES by
185       reusing ks1 for the final encryption.  "C=E(ks1,D(ks2,E(ks1,M)))".
186       This form of Triple-DES is used by the RSAREF library.
187
188       DES_pcbc_encrypt() encrypt/decrypts using the propagating cipher block
189       chaining mode used by Kerberos v4. Its parameters are the same as
190       DES_ncbc_encrypt().
191
192       DES_cfb_encrypt() encrypt/decrypts using cipher feedback mode.  This
193       method takes an array of characters as input and outputs and array of
194       characters.  It does not require any padding to 8 character groups.
195       Note: the ivec variable is changed and the new changed value needs to
196       be passed to the next call to this function.  Since this function runs
197       a complete DES ECB encryption per numbits, this function is only
198       suggested for use when sending small numbers of characters.
199
200       DES_cfb64_encrypt() implements CFB mode of DES with 64bit feedback.
201       Why is this useful you ask?  Because this routine will allow you to
202       encrypt an arbitrary number of bytes, no 8 byte padding.  Each call to
203       this routine will encrypt the input bytes to output and then update
204       ivec and num.  num contains 'how far' we are though ivec.  If this does
205       not make much sense, read more about cfb mode of DES :-).
206
207       DES_ede3_cfb64_encrypt() and DES_ede2_cfb64_encrypt() is the same as
208       DES_cfb64_encrypt() except that Triple-DES is used.
209
210       DES_ofb_encrypt() encrypts using output feedback mode.  This method
211       takes an array of characters as input and outputs and array of
212       characters.  It does not require any padding to 8 character groups.
213       Note: the ivec variable is changed and the new changed value needs to
214       be passed to the next call to this function.  Since this function runs
215       a complete DES ECB encryption per numbits, this function is only
216       suggested for use when sending small numbers of characters.
217
218       DES_ofb64_encrypt() is the same as DES_cfb64_encrypt() using Output
219       Feed Back mode.
220
221       DES_ede3_ofb64_encrypt() and DES_ede2_ofb64_encrypt() is the same as
222       DES_ofb64_encrypt(), using Triple-DES.
223
224       The following functions are included in the DES library for
225       compatibility with the MIT Kerberos library.
226
227       DES_cbc_cksum() produces an 8 byte checksum based on the input stream
228       (via CBC encryption).  The last 4 bytes of the checksum are returned
229       and the complete 8 bytes are placed in output. This function is used by
230       Kerberos v4.  Other applications should use EVP_DigestInit(3) etc.
231       instead.
232
233       DES_quad_cksum() is a Kerberos v4 function.  It returns a 4 byte
234       checksum from the input bytes.  The algorithm can be iterated over the
235       input, depending on out_count, 1, 2, 3 or 4 times.  If output is non-
236       NULL, the 8 bytes generated by each pass are written into output.
237
238       The following are DES-based transformations:
239
240       DES_fcrypt() is a fast version of the Unix crypt(3) function.  This
241       version takes only a small amount of space relative to other fast
242       crypt() implementations.  This is different to the normal crypt in that
243       the third parameter is the buffer that the return value is written
244       into.  It needs to be at least 14 bytes long.  This function is thread
245       safe, unlike the normal crypt.
246
247       DES_crypt() is a faster replacement for the normal system crypt().
248       This function calls DES_fcrypt() with a static array passed as the
249       third parameter.  This emulates the normal non-thread safe semantics of
250       crypt(3).
251
252       DES_enc_write() writes len bytes to file descriptor fd from buffer buf.
253       The data is encrypted via pcbc_encrypt (default) using sched for the
254       key and iv as a starting vector.  The actual data send down fd consists
255       of 4 bytes (in network byte order) containing the length of the
256       following encrypted data.  The encrypted data then follows, padded with
257       random data out to a multiple of 8 bytes.
258
259       DES_enc_read() is used to read len bytes from file descriptor fd into
260       buffer buf. The data being read from fd is assumed to have come from
261       DES_enc_write() and is decrypted using sched for the key schedule and
262       iv for the initial vector.
263
264       Warning: The data format used by DES_enc_write() and DES_enc_read() has
265       a cryptographic weakness: When asked to write more than MAXWRITE bytes,
266       DES_enc_write() will split the data into several chunks that are all
267       encrypted using the same IV.  So don't use these functions unless you
268       are sure you know what you do (in which case you might not want to use
269       them anyway).  They cannot handle non-blocking sockets.  DES_enc_read()
270       uses an internal state and thus cannot be used on multiple files.
271
272       DES_rw_mode is used to specify the encryption mode to use with
273       DES_enc_read() and DES_end_write().  If set to DES_PCBC_MODE (the
274       default), DES_pcbc_encrypt is used.  If set to DES_CBC_MODE
275       DES_cbc_encrypt is used.
276

NOTES

278       Single-key DES is insecure due to its short key size.  ECB mode is not
279       suitable for most applications; see des_modes(7).
280
281       The evp(3) library provides higher-level encryption functions.
282

BUGS

284       DES_3cbc_encrypt() is flawed and must not be used in applications.
285
286       DES_cbc_encrypt() does not modify ivec; use DES_ncbc_encrypt() instead.
287
288       DES_cfb_encrypt() and DES_ofb_encrypt() operates on input of 8 bits.
289       What this means is that if you set numbits to 12, and length to 2, the
290       first 12 bits will come from the 1st input byte and the low half of the
291       second input byte.  The second 12 bits will have the low 8 bits taken
292       from the 3rd input byte and the top 4 bits taken from the 4th input
293       byte.  The same holds for output.  This function has been implemented
294       this way because most people will be using a multiple of 8 and because
295       once you get into pulling bytes input bytes apart things get ugly!
296
297       DES_string_to_key() is available for backward compatibility with the
298       MIT library.  New applications should use a cryptographic hash
299       function.  The same applies for DES_string_to_2key().
300

CONFORMING TO

302       ANSI X3.106
303
304       The des library was written to be source code compatible with the MIT
305       Kerberos library.
306

SEE ALSO

308       crypt(3), des_modes(7), evp(3), rand(3)
309

HISTORY

311       In OpenSSL 0.9.7, all des_ functions were renamed to DES_ to avoid
312       clashes with older versions of libdes.  Compatibility des_ functions
313       are provided for a short while, as well as crypt().  Declarations for
314       these are in <openssl/des_old.h>. There is no DES_ variant for
315       des_random_seed().  This will happen to other functions as well if they
316       are deemed redundant (des_random_seed() just calls RAND_seed() and is
317       present for backward compatibility only), buggy or already scheduled
318       for removal.
319
320       des_cbc_cksum(), des_cbc_encrypt(), des_ecb_encrypt(),
321       des_is_weak_key(), des_key_sched(), des_pcbc_encrypt(),
322       des_quad_cksum(), des_random_key() and des_string_to_key() are
323       available in the MIT Kerberos library; des_check_key_parity(),
324       des_fixup_key_parity() and des_is_weak_key() are available in newer
325       versions of that library.
326
327       des_set_key_checked() and des_set_key_unchecked() were added in OpenSSL
328       0.9.5.
329
330       des_generate_random_block(), des_init_random_number_generator(),
331       des_new_random_key(), des_set_random_generator_seed() and
332       des_set_sequence_number() and des_rand_data() are used in newer
333       versions of Kerberos but are not implemented here.
334
335       des_random_key() generated cryptographically weak random data in SSLeay
336       and in OpenSSL prior version 0.9.5, as well as in the original MIT
337       library.
338

AUTHOR

340       Eric Young (eay@cryptsoft.com). Modified for the OpenSSL project
341       (http://www.openssl.org).
342
343
344
3451.0.0e                            2003-10-01                            des(3)
Impressum