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