libc: make stdio_impl.h an internal libc header
[unleashed/tickless.git] / lib / libcrypto / man / DES_set_key.3
blob0a9e7381bcea470585b01cd832195169c76bcd38
1 .\"     $OpenBSD: DES_set_key.3,v 1.7 2017/02/09 03:43:05 dtucker Exp $
2 .\"     OpenSSL c7497f34 Aug 14 10:50:26 2014 -0400
3 .\"
4 .\" --------------------------------------------------------------------------
5 .\" Major patches to this file were contributed by
6 .\" Ulf Moeller <ulf@openssl.org>, Ben Laurie <ben@openssl.org>,
7 .\" and Richard Levitte <levitte@openssl.org>.
8 .\" --------------------------------------------------------------------------
9 .\" Copyright (c) 2000, 2001 The OpenSSL Project.  All rights reserved.
10 .\"
11 .\" Redistribution and use in source and binary forms, with or without
12 .\" modification, are permitted provided that the following conditions
13 .\" are met:
14 .\"
15 .\" 1. Redistributions of source code must retain the above copyright
16 .\"    notice, this list of conditions and the following disclaimer.
17 .\"
18 .\" 2. Redistributions in binary form must reproduce the above copyright
19 .\"    notice, this list of conditions and the following disclaimer in
20 .\"    the documentation and/or other materials provided with the
21 .\"    distribution.
22 .\"
23 .\" 3. All advertising materials mentioning features or use of this
24 .\"    software must display the following acknowledgment:
25 .\"    "This product includes software developed by the OpenSSL Project
26 .\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
27 .\"
28 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
29 .\"    endorse or promote products derived from this software without
30 .\"    prior written permission. For written permission, please contact
31 .\"    openssl-core@openssl.org.
32 .\"
33 .\" 5. Products derived from this software may not be called "OpenSSL"
34 .\"    nor may "OpenSSL" appear in their names without prior written
35 .\"    permission of the OpenSSL Project.
36 .\"
37 .\" 6. Redistributions of any form whatsoever must retain the following
38 .\"    acknowledgment:
39 .\"    "This product includes software developed by the OpenSSL Project
40 .\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
41 .\"
42 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
43 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
46 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
54 .\"
55 .\" --------------------------------------------------------------------------
56 .\" Parts of this file are derived from SSLeay documentation,
57 .\" which is covered by the following Copyright and license:
58 .\" --------------------------------------------------------------------------
59 .\"
60 .\" Copyright (C) 1995-1998 Tim Hudson (tjh@cryptsoft.com)
61 .\" All rights reserved.
62 .\"
63 .\" This package is an SSL implementation written
64 .\" by Eric Young (eay@cryptsoft.com).
65 .\" The implementation was written so as to conform with Netscapes SSL.
66 .\"
67 .\" This library is free for commercial and non-commercial use as long as
68 .\" the following conditions are aheared to.  The following conditions
69 .\" apply to all code found in this distribution, be it the RC4, RSA,
70 .\" lhash, DES, etc., code; not just the SSL code.  The SSL documentation
71 .\" included with this distribution is covered by the same copyright terms
72 .\" except that the holder is Tim Hudson (tjh@cryptsoft.com).
73 .\"
74 .\" Copyright remains Eric Young's, and as such any Copyright notices in
75 .\" the code are not to be removed.
76 .\" If this package is used in a product, Eric Young should be given
77 .\" attribution as the author of the parts of the library used.
78 .\" This can be in the form of a textual message at program startup or
79 .\" in documentation (online or textual) provided with the package.
80 .\"
81 .\" Redistribution and use in source and binary forms, with or without
82 .\" modification, are permitted provided that the following conditions
83 .\" are met:
84 .\" 1. Redistributions of source code must retain the copyright
85 .\"    notice, this list of conditions and the following disclaimer.
86 .\" 2. Redistributions in binary form must reproduce the above copyright
87 .\"    notice, this list of conditions and the following disclaimer in the
88 .\"    documentation and/or other materials provided with the distribution.
89 .\" 3. All advertising materials mentioning features or use of this software
90 .\"    must display the following acknowledgement:
91 .\"    "This product includes cryptographic software written by
92 .\"     Eric Young (eay@cryptsoft.com)"
93 .\"    The word 'cryptographic' can be left out if the rouines from the
94 .\"    library being used are not cryptographic related :-).
95 .\" 4. If you include any Windows specific code (or a derivative thereof)
96 .\"    from the apps directory (application code) you must include an
97 .\"    acknowledgement: "This product includes software written by
98 .\"    Tim Hudson (tjh@cryptsoft.com)"
99 .\"
100 .\" THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
101 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
102 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
103 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
104 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
105 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
106 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
107 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
108 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
109 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
110 .\" SUCH DAMAGE.
112 .\" The licence and distribution terms for any publically available version or
113 .\" derivative of this code cannot be changed.  i.e. this code cannot simply be
114 .\" copied and put under another distribution licence
115 .\" [including the GNU Public Licence.]
117 .Dd $Mdocdate: February 9 2017 $
118 .Dt DES_SET_KEY 3
120 .Sh NAME
121 .Nm DES_random_key ,
122 .Nm DES_set_key ,
123 .Nm DES_key_sched ,
124 .Nm DES_set_key_checked ,
125 .Nm DES_set_key_unchecked ,
126 .Nm DES_set_odd_parity ,
127 .Nm DES_is_weak_key ,
128 .Nm DES_ecb_encrypt ,
129 .Nm DES_ecb2_encrypt ,
130 .Nm DES_ecb3_encrypt ,
131 .Nm DES_ncbc_encrypt ,
132 .Nm DES_cfb_encrypt ,
133 .Nm DES_ofb_encrypt ,
134 .Nm DES_pcbc_encrypt ,
135 .Nm DES_cfb64_encrypt ,
136 .Nm DES_ofb64_encrypt ,
137 .Nm DES_xcbc_encrypt ,
138 .Nm DES_ede2_cbc_encrypt ,
139 .Nm DES_ede2_cfb64_encrypt ,
140 .Nm DES_ede2_ofb64_encrypt ,
141 .Nm DES_ede3_cbc_encrypt ,
142 .Nm DES_ede3_cbcm_encrypt ,
143 .Nm DES_ede3_cfb64_encrypt ,
144 .Nm DES_ede3_ofb64_encrypt ,
145 .Nm DES_cbc_cksum ,
146 .Nm DES_quad_cksum ,
147 .Nm DES_string_to_key ,
148 .Nm DES_string_to_2keys ,
149 .Nm DES_fcrypt ,
150 .Nm DES_crypt ,
151 .Nm DES_enc_read ,
152 .Nm DES_enc_write
153 .Nd DES encryption
154 .Sh SYNOPSIS
155 .In openssl/des.h
156 .Ft void
157 .Fo DES_random_key
158 .Fa "DES_cblock *ret"
160 .Ft int
161 .Fo DES_set_key
162 .Fa "const_DES_cblock *key"
163 .Fa "DES_key_schedule *schedule"
165 .Ft int
166 .Fo DES_key_sched
167 .Fa "const_DES_cblock *key"
168 .Fa "DES_key_schedule *schedule"
170 .Ft int
171 .Fo DES_set_key_checked
172 .Fa "const_DES_cblock *key"
173 .Fa "DES_key_schedule *schedule"
175 .Ft void
176 .Fo DES_set_key_unchecked
177 .Fa "const_DES_cblock *key"
178 .Fa "DES_key_schedule *schedule"
180 .Ft void
181 .Fo DES_set_odd_parity
182 .Fa "DES_cblock *key"
184 .Ft int
185 .Fo DES_is_weak_key
186 .Fa "const_DES_cblock *key"
188 .Ft void
189 .Fo DES_ecb_encrypt
190 .Fa "const_DES_cblock *input"
191 .Fa "DES_cblock *output"
192 .Fa "DES_key_schedule *ks"
193 .Fa "int enc"
195 .Ft void
196 .Fo DES_ecb2_encrypt
197 .Fa "const_DES_cblock *input"
198 .Fa "DES_cblock *output"
199 .Fa "DES_key_schedule *ks1"
200 .Fa "DES_key_schedule *ks2"
201 .Fa "int enc"
203 .Ft void
204 .Fo DES_ecb3_encrypt
205 .Fa "const_DES_cblock *input"
206 .Fa "DES_cblock *output"
207 .Fa "DES_key_schedule *ks1"
208 .Fa "DES_key_schedule *ks2"
209 .Fa "DES_key_schedule *ks3"
210 .Fa "int enc"
212 .Ft void
213 .Fo DES_ncbc_encrypt
214 .Fa "const unsigned char *input"
215 .Fa "unsigned char *output"
216 .Fa "long length"
217 .Fa "DES_key_schedule *schedule"
218 .Fa "DES_cblock *ivec"
219 .Fa "int enc"
221 .Ft void
222 .Fo DES_cfb_encrypt
223 .Fa "const unsigned char *in"
224 .Fa "unsigned char *out"
225 .Fa "int numbits"
226 .Fa "long length"
227 .Fa "DES_key_schedule *schedule"
228 .Fa "DES_cblock *ivec"
229 .Fa "int enc"
231 .Ft void
232 .Fo DES_ofb_encrypt
233 .Fa "const unsigned char *in"
234 .Fa "unsigned char *out"
235 .Fa "int numbits"
236 .Fa "long length"
237 .Fa "DES_key_schedule *schedule"
238 .Fa "DES_cblock *ivec"
240 .Ft void
241 .Fo DES_pcbc_encrypt
242 .Fa "const unsigned char *input"
243 .Fa "unsigned char *output"
244 .Fa "long length"
245 .Fa "DES_key_schedule *schedule"
246 .Fa "DES_cblock *ivec"
247 .Fa "int enc"
249 .Ft void
250 .Fo DES_cfb64_encrypt
251 .Fa "const unsigned char *in"
252 .Fa "unsigned char *out"
253 .Fa "long length"
254 .Fa "DES_key_schedule *schedule"
255 .Fa "DES_cblock *ivec"
256 .Fa "int *num"
257 .Fa "int enc"
259 .Ft void
260 .Fo DES_ofb64_encrypt
261 .Fa "const unsigned char *in"
262 .Fa "unsigned char *out"
263 .Fa "long length"
264 .Fa "DES_key_schedule *schedule"
265 .Fa "DES_cblock *ivec"
266 .Fa "int *num"
268 .Ft void
269 .Fo DES_xcbc_encrypt
270 .Fa "const unsigned char *input"
271 .Fa "unsigned char *output"
272 .Fa "long length"
273 .Fa "DES_key_schedule *schedule"
274 .Fa "DES_cblock *ivec"
275 .Fa "const_DES_cblock *inw"
276 .Fa "const_DES_cblock *outw"
277 .Fa "int enc"
279 .Ft void
280 .Fo DES_ede2_cbc_encrypt
281 .Fa "const unsigned char *input"
282 .Fa "unsigned char *output"
283 .Fa "long length"
284 .Fa "DES_key_schedule *ks1"
285 .Fa "DES_key_schedule *ks2"
286 .Fa "DES_cblock *ivec"
287 .Fa "int enc"
289 .Ft void
290 .Fo DES_ede2_cfb64_encrypt
291 .Fa "const unsigned char *in"
292 .Fa "unsigned char *out"
293 .Fa "long length"
294 .Fa "DES_key_schedule *ks1"
295 .Fa "DES_key_schedule *ks2"
296 .Fa "DES_cblock *ivec"
297 .Fa "int *num"
298 .Fa "int enc"
300 .Ft void
301 .Fo DES_ede2_ofb64_encrypt
302 .Fa "const unsigned char *in"
303 .Fa "unsigned char *out"
304 .Fa "long length"
305 .Fa "DES_key_schedule *ks1"
306 .Fa "DES_key_schedule *ks2"
307 .Fa "DES_cblock *ivec"
308 .Fa "int *num"
310 .Ft void
311 .Fo DES_ede3_cbc_encrypt
312 .Fa "const unsigned char *input"
313 .Fa "unsigned char *output"
314 .Fa "long length"
315 .Fa "DES_key_schedule *ks1"
316 .Fa "DES_key_schedule *ks2"
317 .Fa "DES_key_schedule *ks3"
318 .Fa "DES_cblock *ivec"
319 .Fa "int enc"
321 .Ft void
322 .Fo DES_ede3_cbcm_encrypt
323 .Fa "const unsigned char *in"
324 .Fa "unsigned char *out"
325 .Fa "long length"
326 .Fa "DES_key_schedule *ks1"
327 .Fa "DES_key_schedule *ks2"
328 .Fa "DES_key_schedule *ks3"
329 .Fa "DES_cblock *ivec1"
330 .Fa "DES_cblock *ivec2"
331 .Fa "int enc"
333 .Ft void
334 .Fo DES_ede3_cfb64_encrypt
335 .Fa "const unsigned char *in"
336 .Fa "unsigned char *out"
337 .Fa "long length"
338 .Fa "DES_key_schedule *ks1"
339 .Fa "DES_key_schedule *ks2"
340 .Fa "DES_key_schedule *ks3"
341 .Fa "DES_cblock *ivec"
342 .Fa "int *num"
343 .Fa "int enc"
345 .Ft void
346 .Fo DES_ede3_ofb64_encrypt
347 .Fa "const unsigned char *in"
348 .Fa "unsigned char *out"
349 .Fa "long length"
350 .Fa "DES_key_schedule *ks1"
351 .Fa "DES_key_schedule *ks2"
352 .Fa "DES_key_schedule *ks3"
353 .Fa "DES_cblock *ivec"
354 .Fa "int *num"
356 .Ft DES_LONG
357 .Fo DES_cbc_cksum
358 .Fa "const unsigned char *input"
359 .Fa "DES_cblock *output"
360 .Fa "long length"
361 .Fa "DES_key_schedule *schedule"
362 .Fa "const_DES_cblock *ivec"
364 .Ft DES_LONG
365 .Fo DES_quad_cksum
366 .Fa "const unsigned char *input"
367 .Fa "DES_cblock output[]"
368 .Fa "long length"
369 .Fa "int out_count"
370 .Fa "DES_cblock *seed"
372 .Ft void
373 .Fo DES_string_to_key
374 .Fa "const char *str"
375 .Fa "DES_cblock *key"
377 .Ft void
378 .Fo DES_string_to_2keys
379 .Fa "const char *str"
380 .Fa "DES_cblock *key1"
381 .Fa "DES_cblock *key2"
383 .Ft char *
384 .Fo DES_fcrypt
385 .Fa "const char *buf"
386 .Fa "const char *salt"
387 .Fa "char *ret"
389 .Ft char *
390 .Fo DES_crypt
391 .Fa "const char *buf"
392 .Fa "const char *salt"
394 .Ft int
395 .Fo DES_enc_read
396 .Fa "int fd"
397 .Fa "void *buf"
398 .Fa "int len"
399 .Fa "DES_key_schedule *sched"
400 .Fa "DES_cblock *iv"
402 .Ft int
403 .Fo DES_enc_write
404 .Fa "int fd"
405 .Fa "const void *buf"
406 .Fa "int len"
407 .Fa "DES_key_schedule *sched"
408 .Fa "DES_cblock *iv"
410 .Sh DESCRIPTION
411 This library contains a fast implementation of the DES encryption
412 algorithm.
414 There are two phases to the use of DES encryption.
415 The first is the generation of a
416 .Vt DES_key_schedule
417 from a key, and the second is the actual encryption.
418 A DES key is of type
419 .Vt DES_cblock .
420 This type consists of 8 bytes with odd parity.
421 The least significant bit in each byte is the parity bit.
422 The key schedule is an expanded form of the key; it is used to speed the
423 encryption process.
425 .Fn DES_random_key
426 generates a random key in odd parity.
428 Before a DES key can be used, it must be converted into the architecture
429 dependent
430 .Vt DES_key_schedule
431 via the
432 .Fn DES_set_key_checked
434 .Fn DES_set_key_unchecked
435 function.
437 .Fn DES_set_key_checked
438 will check that the key passed is of odd parity and is not a weak or
439 semi-weak key.
440 If the parity is wrong, then -1 is returned.
441 If the key is a weak key, then -2 is returned.
442 If an error is returned, the key schedule is not generated.
444 .Fn DES_set_key
445 works like
446 .Fn DES_set_key_checked
447 if the
448 .Em DES_check_key
449 flag is non-zero, otherwise like
450 .Fn DES_set_key_unchecked .
451 These functions are available for compatibility; it is recommended to
452 use a function that does not depend on a global variable.
454 .Fn DES_set_odd_parity
455 sets the parity of the passed
456 .Fa key
457 to odd.
459 .Fn DES_is_weak_key
460 returns 1 if the passed key is a weak key or 0 if it is ok.
462 The following routines mostly operate on an input and output stream of
463 .Vt DES_cblock Ns s .
465 .Fn DES_ecb_encrypt
466 is the basic DES encryption routine that encrypts or decrypts a single
467 8-byte
468 .Vt DES_cblock
469 in electronic code book (ECB) mode.
470 It always transforms the input data, pointed to by
471 .Fa input ,
472 into the output data, pointed to by the
473 .Fa output
474 argument.
475 If the
476 .Fa enc
477 argument is non-zero
478 .Pq Dv DES_ENCRYPT ,
480 .Fa input
481 (cleartext) is encrypted into the
482 .Fa output
483 (ciphertext) using the key_schedule specified by the
484 .Fa schedule
485 argument, previously set via
486 .Fn DES_set_key .
488 .Fa enc
489 is zero
490 .Pq Dv DES_DECRYPT ,
492 .Fa input
493 (now ciphertext) is decrypted into the
494 .Fa output
495 (now cleartext).
496 Input and output may overlap.
497 .Fn DES_ecb_encrypt
498 does not return a value.
500 .Fn DES_ecb3_encrypt
501 encrypts/decrypts the
502 .Fa input
503 block by using three-key Triple-DES encryption in ECB mode.
504 This involves encrypting the input with
505 .Fa ks1 ,
506 decrypting with the key schedule
507 .Fa ks2 ,
508 and then encrypting with
509 .Fa ks3 .
510 This routine greatly reduces the chances of brute force breaking of DES
511 and has the advantage of if
512 .Fa ks1 ,
513 .Fa ks2 ,
515 .Fa ks3
516 are the same, it is equivalent to just encryption using ECB mode and
517 .Fa ks1
518 as the key.
520 The macro
521 .Fn DES_ecb2_encrypt
522 is provided to perform two-key Triple-DES encryption by using
523 .Fa ks1
524 for the final encryption.
526 .Fn DES_ncbc_encrypt
527 encrypts/decrypts using the cipher-block-chaining (CBC) mode of DES.
528 If the
529 .Fa enc
530 argument is non-zero, the routine cipher-block-chain encrypts the
531 cleartext data pointed to by the
532 .Fa input
533 argument into the ciphertext pointed to by the
534 .Fa output
535 argument, using the key schedule provided by the
536 .Fa schedule
537 argument, and initialization vector provided by the
538 .Fa ivec
539 argument.
540 If the
541 .Fa length
542 argument is not an integral multiple of eight bytes, the last block is
543 copied to a temporary area and zero filled.
544 The output is always an integral multiple of eight bytes.
546 .Fn DES_xcbc_encrypt
547 is RSA's DESX mode of DES.
548 It uses
549 .Fa inw
551 .Fa outw
552 to "whiten" the encryption.
553 .Fa inw
555 .Fa outw
556 are secret (unlike the iv) and are as such, part of the key.
557 So the key is sort of 24 bytes.
558 This is much better than CBC DES.
560 .Fn DES_ede3_cbc_encrypt
561 implements outer triple CBC DES encryption with three keys.
562 This means that each DES operation inside the CBC mode is really an
563 .Qq Li C=E(ks3,D(ks2,E(ks1,M))) .
564 This mode is used by SSL.
567 .Fn DES_ede2_cbc_encrypt
568 macro implements two-key Triple-DES by reusing
569 .Fa ks1
570 for the final encryption.
571 .Qq Li C=E(ks1,D(ks2,E(ks1,M))) .
572 This form of Triple-DES is used by the RSAREF library.
574 .Fn DES_pcbc_encrypt
575 encrypt/decrypts using the propagating cipher block chaining mode used
576 by Kerberos v4.
577 Its parameters are the same as
578 .Fn DES_ncbc_encrypt .
580 .Fn DES_cfb_encrypt
581 encrypt/decrypts using cipher feedback mode.
582 This method takes an array of characters as input and outputs an array
583 of characters.
584 It does not require any padding to 8 character groups.
585 Note: the
586 .Fa ivec
587 variable is changed and the new changed value needs to be passed to the
588 next call to this function.
589 Since this function runs a complete DES ECB encryption per
590 .Fa numbits ,
591 this function is only suggested for use when sending small numbers of
592 characters.
594 .Fn DES_cfb64_encrypt
595 implements CFB mode of DES with 64bit feedback.
596 Why is this useful you ask?
597 Because this routine will allow you to encrypt an arbitrary number of
598 bytes, no 8 byte padding.
599 Each call to this routine will encrypt the input bytes to output and
600 then update ivec and num.
601 num contains "how far" we are though ivec.
602 If this does not make much sense, read more about cfb mode of DES :-).
604 .Fn DES_ede3_cfb64_encrypt
606 .Fn DES_ede2_cfb64_encrypt
607 is the same as
608 .Fn DES_cfb64_encrypt
609 except that Triple-DES is used.
611 .Fn DES_ofb_encrypt
612 encrypts using output feedback mode.
613 This method takes an array of characters as input and outputs an array
614 of characters.
615 It does not require any padding to 8 character groups.
616 Note: the
617 .Fa ivec
618 variable is changed and the new changed value needs to be passed to the
619 next call to this function.
620 Since this function runs a complete DES ECB encryption per numbits, this
621 function is only suggested for use when sending small numbers of
622 characters.
624 .Fn DES_ofb64_encrypt
625 is the same as
626 .Fn DES_cfb64_encrypt
627 using Output Feed Back mode.
629 .Fn DES_ede3_ofb64_encrypt
631 .Fn DES_ede2_ofb64_encrypt
632 is the same as
633 .Fn DES_ofb64_encrypt ,
634 using Triple-DES.
636 The following functions are included in the DES library for
637 compatibility with the MIT Kerberos library.
639 .Fn DES_cbc_cksum
640 produces an 8-byte checksum based on the input stream (via CBC
641 encryption).
642 The last 4 bytes of the checksum are returned and the complete 8 bytes
643 are placed in
644 .Fa output .
645 This function is used by Kerberos v4.
646 Other applications should use
647 .Xr EVP_DigestInit 3
648 etc. instead.
650 .Fn DES_quad_cksum
651 is a Kerberos v4 function.
652 It returns a 4-byte checksum from the input bytes.
653 The algorithm can be iterated over the input, depending on
654 .Fa out_count ,
655 1, 2, 3 or 4 times.
657 .Fa output
659 .Pf non- Dv NULL ,
660 the 8 bytes generated by each pass are written into
661 .Fa output .
663 The following are DES-based transformations:
665 .Fn DES_fcrypt
666 is a fast version of the Unix
667 .Xr crypt 3
668 function.
669 This version takes only a small amount of space relative to other
670 fast crypt implementations.
671 This is different to the normal crypt in that the third parameter is the
672 buffer that the return value is written into.
673 It needs to be at least 14 bytes long.
674 This function is thread safe, unlike the normal crypt.
676 .Fn DES_crypt
677 is a faster replacement for the normal system
678 .Xr crypt 3 .
679 This function calls
680 .Fn DES_fcrypt
681 with a static array passed as the third parameter.
682 This emulates the normal non-thread safe semantics of
683 .Xr crypt 3 .
685 .Fn DES_enc_write
686 writes
687 .Fa len
688 bytes to file descriptor
689 .Fa fd
690 from buffer
691 .Fa buf .
692 The data is encrypted via
693 .Em pcbc_encrypt
694 (default) using
695 .Fa sched
696 for the key and
697 .Fa iv
698 as a starting vector.
699 The actual data send down
700 .Fa fd
701 consists of 4 bytes (in network byte order) containing the length of the
702 following encrypted data.
703 The encrypted data then follows, padded with random data out to a
704 multiple of 8 bytes.
706 .Fn DES_enc_read
707 is used to read
708 .Fa len
709 bytes from file descriptor
710 .Fa fd
711 into buffer
712 .Fa buf .
713 The data being read from
714 .Fa fd
715 is assumed to have come from
716 .Fn DES_enc_write
717 and is decrypted using
718 .Fa sched
719 for the key schedule and
720 .Fa iv
721 for the initial vector.
723 .Sy Warning :
724 The data format used by
725 .Fn DES_enc_write
727 .Fn DES_enc_read
728 has a cryptographic weakness: when asked to write more than
729 .Dv MAXWRITE
730 bytes,
731 .Fn DES_enc_write
732 will split the data into several chunks that are all encrypted using the
733 same IV.
734 So don't use these functions unless you are sure you know what
735 you do (in which case you might not want to use them anyway).
736 They cannot handle non-blocking sockets.
737 .Fn DES_enc_read
738 uses an internal state and thus cannot be used on multiple files.
740 .Em DES_rw_mode
741 is used to specify the encryption mode to use with
742 .Fn DES_enc_read .
743 If set to
744 .Dv DES_PCBC_MODE
745 (the default), DES_pcbc_encrypt is used.
746 If set to
747 .Dv DES_CBC_MODE
748 DES_cbc_encrypt is used.
749 .Sh SEE ALSO
750 .Xr crypt 3 ,
751 .Xr RAND_bytes 3
754 .Xr evp 3
755 library provides higher-level encryption functions.
756 .Sh STANDARDS
757 ANSI X3.106
759 The DES library was initially written to be source code compatible
760 with the MIT Kerberos library.
761 .Sh HISTORY
762 In OpenSSL 0.9.7, all des_ functions were renamed to DES_ to avoid
763 clashes with older versions of libdes.
765 .Fn DES_set_key_checked
767 .Fn DES_set_key_unchecked
768 were added in OpenSSL 0.9.5.
770 .Fn des_generate_random_block ,
771 .Fn des_init_random_number_generator ,
772 .Fn des_new_random_key ,
773 .Fn des_set_random_generator_seed ,
774 .Fn des_set_sequence_number ,
776 .Fn des_rand_data 3
777 are used in newer versions of Kerberos but are not implemented here.
779 .Fn DES_random_key
780 generated cryptographically weak random data in SSLeay and in OpenSSL
781 prior version 0.9.5, as well as in the original MIT library.
782 .Sh AUTHORS
783 .An Eric Young Aq Mt eay@cryptsoft.com
784 .Sh CAVEATS
785 Single-key DES is insecure due to its short key size.
786 ECB mode is not suitable for most applications.
787 .Sh BUGS
788 DES_cbc_encrypt does not modify
789 .Fa ivec ;
791 .Fn DES_ncbc_encrypt
792 instead.
794 .Fn DES_cfb_encrypt
796 .Fn DES_ofb_encrypt
797 operates on input of 8 bits.
798 What this means is that if you set numbits to 12, and length to 2, the
799 first 12 bits will come from the 1st input byte and the low half of the
800 second input byte.
801 The second 12 bits will have the low 8 bits taken from the 3rd input
802 byte and the top 4 bits taken from the 4th input byte.
803 The same holds for output.
804 This function has been implemented this way because most people will be
805 using a multiple of 8 and because once you get into pulling input
806 bytes apart things get ugly!
808 .Fn DES_string_to_key
809 is available for backward compatibility with the MIT library.
810 New applications should use a cryptographic hash function.
811 The same applies for
812 .Fn DES_string_to_2key .