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

BUGS

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

NOTES

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

RETURN VALUES

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

SEE ALSO

291       des_modes(7), EVP_EncryptInit(3)
292

HISTORY

294       The requirement that the salt parameter to DES_crypt() and DES_fcrypt()
295       be two ASCII characters was first enforced in OpenSSL 1.1.0.  Previous
296       versions tried to use the letter uppercase A if both character were not
297       present, and could crash when given non-ASCII on some platforms.
298
300       Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
301
302       Licensed under the OpenSSL license (the "License").  You may not use
303       this file except in compliance with the License.  You can obtain a copy
304       in the file LICENSE in the source distribution or at
305       <https://www.openssl.org/source/license.html>.
306
307
308
3091.1.1i                            2021-01-26                 DES_RANDOM_KEY(3)
Impressum