1DES_RANDOM_KEY(3)                   OpenSSL                  DES_RANDOM_KEY(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_cfb64_encrypt, DES_ede3_ofb64_encrypt, DES_cbc_cksum,
13       DES_quad_cksum, DES_string_to_key, DES_string_to_2keys, DES_fcrypt,
14       DES_crypt - 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, DES_key_schedule *schedule);
24        void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule);
25
26        void DES_set_odd_parity(DES_cblock *key);
27        int DES_is_weak_key(const_DES_cblock *key);
28
29        void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
30                             DES_key_schedule *ks, int enc);
31        void DES_ecb2_encrypt(const_DES_cblock *input, DES_cblock *output,
32                              DES_key_schedule *ks1, DES_key_schedule *ks2, int enc);
33        void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
34                              DES_key_schedule *ks1, DES_key_schedule *ks2,
35                              DES_key_schedule *ks3, int enc);
36
37        void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output,
38                              long length, DES_key_schedule *schedule, DES_cblock *ivec,
39                              int enc);
40        void DES_cfb_encrypt(const unsigned char *in, unsigned char *out,
41                             int numbits, long length, DES_key_schedule *schedule,
42                             DES_cblock *ivec, int enc);
43        void DES_ofb_encrypt(const unsigned char *in, unsigned char *out,
44                             int numbits, long length, DES_key_schedule *schedule,
45                             DES_cblock *ivec);
46        void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
47                              long length, DES_key_schedule *schedule, DES_cblock *ivec,
48                              int enc);
49        void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
50                               long length, DES_key_schedule *schedule, DES_cblock *ivec,
51                               int *num, int enc);
52        void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out,
53                               long length, DES_key_schedule *schedule, DES_cblock *ivec,
54                               int *num);
55
56        void DES_xcbc_encrypt(const unsigned char *input, unsigned char *output,
57                              long length, DES_key_schedule *schedule, DES_cblock *ivec,
58                              const_DES_cblock *inw, const_DES_cblock *outw, int enc);
59
60        void DES_ede2_cbc_encrypt(const unsigned char *input, unsigned char *output,
61                                  long length, DES_key_schedule *ks1,
62                                  DES_key_schedule *ks2, DES_cblock *ivec, int enc);
63        void DES_ede2_cfb64_encrypt(const unsigned char *in, unsigned char *out,
64                                    long length, DES_key_schedule *ks1,
65                                    DES_key_schedule *ks2, DES_cblock *ivec,
66                                    int *num, int enc);
67        void DES_ede2_ofb64_encrypt(const unsigned char *in, unsigned char *out,
68                                    long length, DES_key_schedule *ks1,
69                                    DES_key_schedule *ks2, DES_cblock *ivec, int *num);
70
71        void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
72                                  long length, DES_key_schedule *ks1,
73                                  DES_key_schedule *ks2, DES_key_schedule *ks3,
74                                  DES_cblock *ivec, int enc);
75        void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
76                                    long length, DES_key_schedule *ks1,
77                                    DES_key_schedule *ks2, DES_key_schedule *ks3,
78                                    DES_cblock *ivec, int *num, int enc);
79        void DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out,
80                                    long length, DES_key_schedule *ks1,
81                                    DES_key_schedule *ks2, DES_key_schedule *ks3,
82                                    DES_cblock *ivec, int *num);
83
84        DES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output,
85                               long length, DES_key_schedule *schedule,
86                               const_DES_cblock *ivec);
87        DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
88                                long length, int out_count, DES_cblock *seed);
89        void DES_string_to_key(const char *str, DES_cblock *key);
90        void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2);
91
92        char *DES_fcrypt(const char *buf, const char *salt, char *ret);
93        char *DES_crypt(const char *buf, const char *salt);
94

DESCRIPTION

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

BUGS

252       DES_cbc_encrypt() does not modify ivec; use DES_ncbc_encrypt() instead.
253
254       DES_cfb_encrypt() and DES_ofb_encrypt() operates on input of 8 bits.
255       What this means is that if you set numbits to 12, and length to 2, the
256       first 12 bits will come from the 1st input byte and the low half of the
257       second input byte.  The second 12 bits will have the low 8 bits taken
258       from the 3rd input byte and the top 4 bits taken from the 4th input
259       byte.  The same holds for output.  This function has been implemented
260       this way because most people will be using a multiple of 8 and because
261       once you get into pulling bytes input bytes apart things get ugly!
262
263       DES_string_to_key() is available for backward compatibility with the
264       MIT library.  New applications should use a cryptographic hash
265       function.  The same applies for DES_string_to_2key().
266

NOTES

268       The des library was written to be source code compatible with the MIT
269       Kerberos library.
270
271       Applications should use the higher level functions EVP_EncryptInit(3)
272       etc. instead of calling these functions directly.
273
274       Single-key DES is insecure due to its short key size.  ECB mode is not
275       suitable for most applications; see des_modes(7).
276

RETURN VALUES

278       DES_set_key(), DES_key_sched(), DES_set_key_checked() and
279       DES_is_weak_key() return 0 on success or negative values on error.
280
281       DES_cbc_cksum() and DES_quad_cksum() return 4-byte integer representing
282       the last 4 bytes of the checksum of the input.
283
284       DES_fcrypt() returns a pointer to the caller-provided buffer and
285       DES_crypt() - to a static buffer on success; otherwise they return
286       NULL.
287

HISTORY

289       The requirement that the salt parameter to DES_crypt() and DES_fcrypt()
290       be two ASCII characters was first enforced in OpenSSL 1.1.0.  Previous
291       versions tried to use the letter uppercase A if both character were not
292       present, and could crash when given non-ASCII on some platforms.
293

SEE ALSO

295       des_modes(7), EVP_EncryptInit(3)
296
298       Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
299
300       Licensed under the OpenSSL license (the "License").  You may not use
301       this file except in compliance with the License.  You can obtain a copy
302       in the file LICENSE in the source distribution or at
303       <https://www.openssl.org/source/license.html>.
304
305
306
3071.1.1                             2018-09-11                 DES_RANDOM_KEY(3)
Impressum