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

NOTES

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

BUGS

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

CONFORMING TO

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

SEE ALSO

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

HISTORY

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

AUTHOR

339       Eric Young (eay@cryptsoft.com). Modified for the OpenSSL project
340       (http://www.openssl.org).
341
342
343
3441.0.2k                            2017-01-26                            des(3)
Impressum