1DES_RANDOM_KEY(3ossl) OpenSSL DES_RANDOM_KEY(3ossl)
2
3
4
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
17 #include <openssl/des.h>
18
19 The following functions have been deprecated since OpenSSL 3.0, and can
20 be hidden entirely by defining OPENSSL_API_COMPAT with a suitable
21 version value, see openssl_user_macros(7):
22
23 void DES_random_key(DES_cblock *ret);
24
25 int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule);
26 int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule);
27 int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule);
28 void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule);
29
30 void DES_set_odd_parity(DES_cblock *key);
31 int DES_is_weak_key(const_DES_cblock *key);
32
33 void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
34 DES_key_schedule *ks, int enc);
35 void DES_ecb2_encrypt(const_DES_cblock *input, DES_cblock *output,
36 DES_key_schedule *ks1, DES_key_schedule *ks2, int enc);
37 void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
38 DES_key_schedule *ks1, DES_key_schedule *ks2,
39 DES_key_schedule *ks3, int enc);
40
41 void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output,
42 long length, DES_key_schedule *schedule, DES_cblock *ivec,
43 int enc);
44 void DES_cfb_encrypt(const unsigned char *in, unsigned char *out,
45 int numbits, long length, DES_key_schedule *schedule,
46 DES_cblock *ivec, int enc);
47 void DES_ofb_encrypt(const unsigned char *in, unsigned char *out,
48 int numbits, long length, DES_key_schedule *schedule,
49 DES_cblock *ivec);
50 void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
51 long length, DES_key_schedule *schedule, DES_cblock *ivec,
52 int enc);
53 void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
54 long length, DES_key_schedule *schedule, DES_cblock *ivec,
55 int *num, int enc);
56 void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out,
57 long length, DES_key_schedule *schedule, DES_cblock *ivec,
58 int *num);
59
60 void DES_xcbc_encrypt(const unsigned char *input, unsigned char *output,
61 long length, DES_key_schedule *schedule, DES_cblock *ivec,
62 const_DES_cblock *inw, const_DES_cblock *outw, int enc);
63
64 void DES_ede2_cbc_encrypt(const unsigned char *input, unsigned char *output,
65 long length, DES_key_schedule *ks1,
66 DES_key_schedule *ks2, DES_cblock *ivec, int enc);
67 void DES_ede2_cfb64_encrypt(const unsigned char *in, unsigned char *out,
68 long length, DES_key_schedule *ks1,
69 DES_key_schedule *ks2, DES_cblock *ivec,
70 int *num, int enc);
71 void DES_ede2_ofb64_encrypt(const unsigned char *in, unsigned char *out,
72 long length, DES_key_schedule *ks1,
73 DES_key_schedule *ks2, DES_cblock *ivec, int *num);
74
75 void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
76 long length, DES_key_schedule *ks1,
77 DES_key_schedule *ks2, DES_key_schedule *ks3,
78 DES_cblock *ivec, int enc);
79 void DES_ede3_cfb64_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, 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, DES_cblock *key2);
95
96 char *DES_fcrypt(const char *buf, const char *salt, char *ret);
97 char *DES_crypt(const char *buf, const char *salt);
98
100 All of the functions described on this page are deprecated.
101 Applications should instead use EVP_EncryptInit_ex(3),
102 EVP_EncryptUpdate(3) and EVP_EncryptFinal_ex(3) or the equivalently
103 named decrypt functions.
104
105 This library contains a fast implementation of the DES encryption
106 algorithm.
107
108 There are two phases to the use of DES encryption. The first is the
109 generation of a DES_key_schedule from a key, the second is the actual
110 encryption. A DES key is of type DES_cblock. This type consists of 8
111 bytes with odd parity. The least significant bit in each byte is the
112 parity bit. The key schedule is an expanded form of the key; it is
113 used to speed the encryption process.
114
115 DES_random_key() generates a random key. The random generator must be
116 seeded when calling this function. If the automatic seeding or
117 reseeding of the OpenSSL CSPRNG fails due to external circumstances
118 (see RAND(7)), the operation will fail. If the function fails, 0 is
119 returned.
120
121 Before a DES key can be used, it must be converted into the
122 architecture dependent DES_key_schedule via the DES_set_key_checked()
123 or DES_set_key_unchecked() function.
124
125 DES_set_key_checked() will check that the key passed is of odd parity
126 and is not a weak or semi-weak key. If the parity is wrong, then -1 is
127 returned. If the key is a weak key, then -2 is returned. If an error
128 is returned, the key schedule is not generated.
129
130 DES_set_key() works like DES_set_key_checked() and remains for backward
131 compatibility.
132
133 DES_set_odd_parity() sets the parity of the passed key to odd.
134
135 DES_is_weak_key() returns 1 if the passed key is a weak key, 0 if it is
136 ok.
137
138 The following routines mostly operate on an input and output stream of
139 DES_cblocks.
140
141 DES_ecb_encrypt() is the basic DES encryption routine that encrypts or
142 decrypts a single 8-byte DES_cblock in electronic code book (ECB) mode.
143 It always transforms the input data, pointed to by input, into the
144 output data, pointed to by the output argument. If the encrypt
145 argument is nonzero (DES_ENCRYPT), the input (cleartext) is encrypted
146 in to the output (ciphertext) using the key_schedule specified by the
147 schedule argument, previously set via DES_set_key. If encrypt is zero
148 (DES_DECRYPT), the input (now ciphertext) is decrypted into the output
149 (now cleartext). Input and output may overlap. DES_ecb_encrypt() does
150 not return a value.
151
152 DES_ecb3_encrypt() encrypts/decrypts the input block by using three-key
153 Triple-DES encryption in ECB mode. This involves encrypting the input
154 with ks1, decrypting with the key schedule ks2, and then encrypting
155 with ks3. This routine greatly reduces the chances of brute force
156 breaking of DES and has the advantage of if ks1, ks2 and ks3 are the
157 same, it is equivalent to just encryption using ECB mode and ks1 as the
158 key.
159
160 The macro DES_ecb2_encrypt() is provided to perform two-key Triple-DES
161 encryption by using ks1 for the final encryption.
162
163 DES_ncbc_encrypt() encrypts/decrypts using the cipher-block-chaining
164 (CBC) mode of DES. If the encrypt argument is nonzero, the routine
165 cipher-block-chain encrypts the cleartext data pointed to by the input
166 argument into the ciphertext pointed to by the output argument, using
167 the key schedule provided by the schedule argument, and initialization
168 vector provided by the ivec argument. If the length argument is not an
169 integral multiple of eight bytes, the last block is copied to a
170 temporary area and zero filled. The output is always an integral
171 multiple of eight bytes.
172
173 DES_xcbc_encrypt() is RSA's DESX mode of DES. It uses inw and outw to
174 'whiten' the encryption. inw and outw are secret (unlike the iv) and
175 are as such, part of the key. So the key is sort of 24 bytes. This is
176 much better than CBC DES.
177
178 DES_ede3_cbc_encrypt() implements outer triple CBC DES encryption with
179 three keys. This means that each DES operation inside the CBC mode is
180 "C=E(ks3,D(ks2,E(ks1,M)))". This mode is used by SSL.
181
182 The DES_ede2_cbc_encrypt() macro implements two-key Triple-DES by
183 reusing ks1 for the final encryption. "C=E(ks1,D(ks2,E(ks1,M)))".
184 This form of Triple-DES is used by the RSAREF library.
185
186 DES_pcbc_encrypt() encrypts/decrypts using the propagating cipher block
187 chaining mode used by Kerberos v4. Its parameters are the same as
188 DES_ncbc_encrypt().
189
190 DES_cfb_encrypt() encrypts/decrypts using cipher feedback mode. This
191 method takes an array of characters as input and outputs an array of
192 characters. It does not require any padding to 8 character groups.
193 Note: the ivec variable is changed and the new changed value needs to
194 be passed to the next call to this function. Since this function runs
195 a complete DES ECB encryption per numbits, this function is only
196 suggested for use when sending a small number of characters.
197
198 DES_cfb64_encrypt() implements CFB mode of DES with 64-bit feedback.
199 Why is this useful you ask? Because this routine will allow you to
200 encrypt an arbitrary number of bytes, without 8 byte padding. Each
201 call to this routine will encrypt the input bytes to output and then
202 update ivec and num. num contains 'how far' we are though ivec. If
203 this does not make much sense, read more about CFB mode of DES.
204
205 DES_ede3_cfb64_encrypt() and DES_ede2_cfb64_encrypt() is the same as
206 DES_cfb64_encrypt() except that Triple-DES is used.
207
208 DES_ofb_encrypt() encrypts using output feedback mode. This method
209 takes an array of characters as input and outputs an array of
210 characters. It does not require any padding to 8 character groups.
211 Note: the ivec variable is changed and the new changed value needs to
212 be passed to the next call to this function. Since this function runs
213 a complete DES ECB encryption per numbits, this function is only
214 suggested for use when sending a small number of characters.
215
216 DES_ofb64_encrypt() is the same as DES_cfb64_encrypt() using Output
217 Feed Back mode.
218
219 DES_ede3_ofb64_encrypt() and DES_ede2_ofb64_encrypt() is the same as
220 DES_ofb64_encrypt(), using Triple-DES.
221
222 The following functions are included in the DES library for
223 compatibility with the MIT Kerberos library.
224
225 DES_cbc_cksum() produces an 8 byte checksum based on the input stream
226 (via CBC encryption). The last 4 bytes of the checksum are returned
227 and the complete 8 bytes are placed in output. This function is used by
228 Kerberos v4. Other applications should use EVP_DigestInit(3) etc.
229 instead.
230
231 DES_quad_cksum() is a Kerberos v4 function. It returns a 4 byte
232 checksum from the input bytes. The algorithm can be iterated over the
233 input, depending on out_count, 1, 2, 3 or 4 times. If output is non-
234 NULL, the 8 bytes generated by each pass are written into output.
235
236 The following are DES-based transformations:
237
238 DES_fcrypt() is a fast version of the Unix crypt(3) function. This
239 version takes only a small amount of space relative to other fast
240 crypt() implementations. This is different to the normal crypt() in
241 that the third parameter is the buffer that the return value is written
242 into. It needs to be at least 14 bytes long. This function is thread
243 safe, unlike the normal crypt().
244
245 DES_crypt() is a faster replacement for the normal system crypt().
246 This function calls DES_fcrypt() with a static array passed as the
247 third parameter. This mostly emulates the normal non-thread-safe
248 semantics of crypt(3). The salt must be two ASCII characters.
249
250 The values returned by DES_fcrypt() and DES_crypt() are terminated by
251 NUL character.
252
253 DES_enc_write() writes len bytes to file descriptor fd from buffer buf.
254 The data is encrypted via pcbc_encrypt (default) using sched for the
255 key and iv as a starting vector. The actual data send down fd consists
256 of 4 bytes (in network byte order) containing the length of the
257 following encrypted data. The encrypted data then follows, padded with
258 random data out to a multiple of 8 bytes.
259
261 DES_cbc_encrypt() does not modify ivec; use DES_ncbc_encrypt() instead.
262
263 DES_cfb_encrypt() and DES_ofb_encrypt() operates on input of 8 bits.
264 What this means is that if you set numbits to 12, and length to 2, the
265 first 12 bits will come from the 1st input byte and the low half of the
266 second input byte. The second 12 bits will have the low 8 bits taken
267 from the 3rd input byte and the top 4 bits taken from the 4th input
268 byte. The same holds for output. This function has been implemented
269 this way because most people will be using a multiple of 8 and because
270 once you get into pulling bytes input bytes apart things get ugly!
271
272 DES_string_to_key() is available for backward compatibility with the
273 MIT library. New applications should use a cryptographic hash
274 function. The same applies for DES_string_to_2key().
275
277 The des library was written to be source code compatible with the MIT
278 Kerberos library.
279
280 Applications should use the higher level functions EVP_EncryptInit(3)
281 etc. instead of calling these functions directly.
282
283 Single-key DES is insecure due to its short key size. ECB mode is not
284 suitable for most applications; see des_modes(7).
285
287 DES_set_key(), DES_key_sched(), and DES_set_key_checked() return 0 on
288 success or negative values on error.
289
290 DES_is_weak_key() returns 1 if the passed key is a weak key, 0 if it is
291 ok.
292
293 DES_cbc_cksum() and DES_quad_cksum() return 4-byte integer representing
294 the last 4 bytes of the checksum of the input.
295
296 DES_fcrypt() returns a pointer to the caller-provided buffer and
297 DES_crypt() - to a static buffer on success; otherwise they return
298 NULL.
299
301 des_modes(7), EVP_EncryptInit(3)
302
304 All of these functions were deprecated in OpenSSL 3.0.
305
306 The requirement that the salt parameter to DES_crypt() and DES_fcrypt()
307 be two ASCII characters was first enforced in OpenSSL 1.1.0. Previous
308 versions tried to use the letter uppercase A if both character were not
309 present, and could crash when given non-ASCII on some platforms.
310
312 Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
313
314 Licensed under the Apache License 2.0 (the "License"). You may not use
315 this file except in compliance with the License. You can obtain a copy
316 in the file LICENSE in the source distribution or at
317 <https://www.openssl.org/source/license.html>.
318
319
320
3213.0.9 2023-07-27 DES_RANDOM_KEY(3ossl)