summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/DES_set_key.3
diff options
context:
space:
mode:
authorschwarze <>2016-11-02 09:11:53 +0000
committerschwarze <>2016-11-02 09:11:53 +0000
commitb50ac7faef96a45291b0c3201b82185f7579e826 (patch)
tree9166b196a2c833fc7a0154973d11551824a6bfb9 /src/lib/libcrypto/man/DES_set_key.3
parent506350d1237710b9d86fdb3a794c6e6265f71221 (diff)
downloadopenbsd-b50ac7faef96a45291b0c3201b82185f7579e826.tar.gz
openbsd-b50ac7faef96a45291b0c3201b82185f7579e826.tar.bz2
openbsd-b50ac7faef96a45291b0c3201b82185f7579e826.zip
convert DES and DH manuals from pod to mdoc
Diffstat (limited to 'src/lib/libcrypto/man/DES_set_key.3')
-rw-r--r--src/lib/libcrypto/man/DES_set_key.3697
1 files changed, 697 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/DES_set_key.3 b/src/lib/libcrypto/man/DES_set_key.3
new file mode 100644
index 0000000000..9c33bf29e6
--- /dev/null
+++ b/src/lib/libcrypto/man/DES_set_key.3
@@ -0,0 +1,697 @@
1.Dd $Mdocdate: November 2 2016 $
2.Dt DES_SET_KEY 3
3.Os
4.Sh NAME
5.Nm DES_random_key ,
6.Nm DES_set_key ,
7.Nm DES_key_sched ,
8.Nm DES_set_key_checked ,
9.Nm DES_set_key_unchecked ,
10.Nm DES_set_odd_parity ,
11.Nm DES_is_weak_key ,
12.Nm DES_ecb_encrypt ,
13.Nm DES_ecb2_encrypt ,
14.Nm DES_ecb3_encrypt ,
15.Nm DES_ncbc_encrypt ,
16.Nm DES_cfb_encrypt ,
17.Nm DES_ofb_encrypt ,
18.Nm DES_pcbc_encrypt ,
19.Nm DES_cfb64_encrypt ,
20.Nm DES_ofb64_encrypt ,
21.Nm DES_xcbc_encrypt ,
22.Nm DES_ede2_cbc_encrypt ,
23.Nm DES_ede2_cfb64_encrypt ,
24.Nm DES_ede2_ofb64_encrypt ,
25.Nm DES_ede3_cbc_encrypt ,
26.Nm DES_ede3_cbcm_encrypt ,
27.Nm DES_ede3_cfb64_encrypt ,
28.Nm DES_ede3_ofb64_encrypt ,
29.Nm DES_cbc_cksum ,
30.Nm DES_quad_cksum ,
31.Nm DES_string_to_key ,
32.Nm DES_string_to_2keys ,
33.Nm DES_fcrypt ,
34.Nm DES_crypt ,
35.Nm DES_enc_read ,
36.Nm DES_enc_write
37.Nd DES encryption
38.Sh SYNOPSIS
39.In openssl/des.h
40.Ft void
41.Fo DES_random_key
42.Fa "DES_cblock *ret"
43.Fc
44.Ft int
45.Fo DES_set_key
46.Fa "const_DES_cblock *key"
47.Fa "DES_key_schedule *schedule"
48.Fc
49.Ft int
50.Fo DES_key_sched
51.Fa "const_DES_cblock *key"
52.Fa "DES_key_schedule *schedule"
53.Fc
54.Ft int
55.Fo DES_set_key_checked
56.Fa "const_DES_cblock *key"
57.Fa "DES_key_schedule *schedule"
58.Fc
59.Ft void
60.Fo DES_set_key_unchecked
61.Fa "const_DES_cblock *key"
62.Fa "DES_key_schedule *schedule"
63.Fc
64.Ft void
65.Fo DES_set_odd_parity
66.Fa "DES_cblock *key"
67.Fc
68.Ft int
69.Fo DES_is_weak_key
70.Fa "const_DES_cblock *key"
71.Fc
72.Ft void
73.Fo DES_ecb_encrypt
74.Fa "const_DES_cblock *input"
75.Fa "DES_cblock *output"
76.Fa "DES_key_schedule *ks"
77.Fa "int enc"
78.Fc
79.Ft void
80.Fo DES_ecb2_encrypt
81.Fa "const_DES_cblock *input"
82.Fa "DES_cblock *output"
83.Fa "DES_key_schedule *ks1"
84.Fa "DES_key_schedule *ks2"
85.Fa "int enc"
86.Fc
87.Ft void
88.Fo DES_ecb3_encrypt
89.Fa "const_DES_cblock *input"
90.Fa "DES_cblock *output"
91.Fa "DES_key_schedule *ks1"
92.Fa "DES_key_schedule *ks2"
93.Fa "DES_key_schedule *ks3"
94.Fa "int enc"
95.Fc
96.Ft void
97.Fo DES_ncbc_encrypt
98.Fa "const unsigned char *input"
99.Fa "unsigned char *output"
100.Fa "long length"
101.Fa "DES_key_schedule *schedule"
102.Fa "DES_cblock *ivec"
103.Fa "int enc"
104.Fc
105.Ft void
106.Fo DES_cfb_encrypt
107.Fa "const unsigned char *in"
108.Fa "unsigned char *out"
109.Fa "int numbits"
110.Fa "long length"
111.Fa "DES_key_schedule *schedule"
112.Fa "DES_cblock *ivec"
113.Fa "int enc"
114.Fc
115.Ft void
116.Fo DES_ofb_encrypt
117.Fa "const unsigned char *in"
118.Fa "unsigned char *out"
119.Fa "int numbits"
120.Fa "long length"
121.Fa "DES_key_schedule *schedule"
122.Fa "DES_cblock *ivec"
123.Fc
124.Ft void
125.Fo DES_pcbc_encrypt
126.Fa "const unsigned char *input"
127.Fa "unsigned char *output"
128.Fa "long length"
129.Fa "DES_key_schedule *schedule"
130.Fa "DES_cblock *ivec"
131.Fa "int enc"
132.Fc
133.Ft void
134.Fo DES_cfb64_encrypt
135.Fa "const unsigned char *in"
136.Fa "unsigned char *out"
137.Fa "long length"
138.Fa "DES_key_schedule *schedule"
139.Fa "DES_cblock *ivec"
140.Fa "int *num"
141.Fa "int enc"
142.Fc
143.Ft void
144.Fo DES_ofb64_encrypt
145.Fa "const unsigned char *in"
146.Fa "unsigned char *out"
147.Fa "long length"
148.Fa "DES_key_schedule *schedule"
149.Fa "DES_cblock *ivec"
150.Fa "int *num"
151.Fc
152.Ft void
153.Fo DES_xcbc_encrypt
154.Fa "const unsigned char *input"
155.Fa "unsigned char *output"
156.Fa "long length"
157.Fa "DES_key_schedule *schedule"
158.Fa "DES_cblock *ivec"
159.Fa "const_DES_cblock *inw"
160.Fa "const_DES_cblock *outw"
161.Fa "int enc"
162.Fc
163.Ft void
164.Fo DES_ede2_cbc_encrypt
165.Fa "const unsigned char *input"
166.Fa "unsigned char *output"
167.Fa "long length"
168.Fa "DES_key_schedule *ks1"
169.Fa "DES_key_schedule *ks2"
170.Fa "DES_cblock *ivec"
171.Fa "int enc"
172.Fc
173.Ft void
174.Fo DES_ede2_cfb64_encrypt
175.Fa "const unsigned char *in"
176.Fa "unsigned char *out"
177.Fa "long length"
178.Fa "DES_key_schedule *ks1"
179.Fa "DES_key_schedule *ks2"
180.Fa "DES_cblock *ivec"
181.Fa "int *num"
182.Fa "int enc"
183.Fc
184.Ft void
185.Fo DES_ede2_ofb64_encrypt
186.Fa "const unsigned char *in"
187.Fa "unsigned char *out"
188.Fa "long length"
189.Fa "DES_key_schedule *ks1"
190.Fa "DES_key_schedule *ks2"
191.Fa "DES_cblock *ivec"
192.Fa "int *num"
193.Fc
194.Ft void
195.Fo DES_ede3_cbc_encrypt
196.Fa "const unsigned char *input"
197.Fa "unsigned char *output"
198.Fa "long length"
199.Fa "DES_key_schedule *ks1"
200.Fa "DES_key_schedule *ks2"
201.Fa "DES_key_schedule *ks3"
202.Fa "DES_cblock *ivec"
203.Fa "int enc"
204.Fc
205.Ft void
206.Fo DES_ede3_cbcm_encrypt
207.Fa "const unsigned char *in"
208.Fa "unsigned char *out"
209.Fa "long length"
210.Fa "DES_key_schedule *ks1"
211.Fa "DES_key_schedule *ks2"
212.Fa "DES_key_schedule *ks3"
213.Fa "DES_cblock *ivec1"
214.Fa "DES_cblock *ivec2"
215.Fa "int enc"
216.Fc
217.Ft void
218.Fo DES_ede3_cfb64_encrypt
219.Fa "const unsigned char *in"
220.Fa "unsigned char *out"
221.Fa "long length"
222.Fa "DES_key_schedule *ks1"
223.Fa "DES_key_schedule *ks2"
224.Fa "DES_key_schedule *ks3"
225.Fa "DES_cblock *ivec"
226.Fa "int *num"
227.Fa "int enc"
228.Fc
229.Ft void
230.Fo DES_ede3_ofb64_encrypt
231.Fa "const unsigned char *in"
232.Fa "unsigned char *out"
233.Fa "long length"
234.Fa "DES_key_schedule *ks1"
235.Fa "DES_key_schedule *ks2"
236.Fa "DES_key_schedule *ks3"
237.Fa "DES_cblock *ivec"
238.Fa "int *num"
239.Fc
240.Ft DES_LONG
241.Fo DES_cbc_cksum
242.Fa "const unsigned char *input"
243.Fa "DES_cblock *output"
244.Fa "long length"
245.Fa "DES_key_schedule *schedule"
246.Fa "const_DES_cblock *ivec"
247.Fc
248.Ft DES_LONG
249.Fo DES_quad_cksum
250.Fa "const unsigned char *input"
251.Fa "DES_cblock output[]"
252.Fa "long length"
253.Fa "int out_count"
254.Fa "DES_cblock *seed"
255.Fc
256.Ft void
257.Fo DES_string_to_key
258.Fa "const char *str"
259.Fa "DES_cblock *key"
260.Fc
261.Ft void
262.Fo DES_string_to_2keys
263.Fa "const char *str"
264.Fa "DES_cblock *key1"
265.Fa "DES_cblock *key2"
266.Fc
267.Ft char *
268.Fo DES_fcrypt
269.Fa "const char *buf"
270.Fa "const char *salt"
271.Fa "char *ret"
272.Fc
273.Ft char *
274.Fo DES_crypt
275.Fa "const char *buf"
276.Fa "const char *salt"
277.Fc
278.Ft int
279.Fo DES_enc_read
280.Fa "int fd"
281.Fa "void *buf"
282.Fa "int len"
283.Fa "DES_key_schedule *sched"
284.Fa "DES_cblock *iv"
285.Fc
286.Ft int
287.Fo DES_enc_write
288.Fa "int fd"
289.Fa "const void *buf"
290.Fa "int len"
291.Fa "DES_key_schedule *sched"
292.Fa "DES_cblock *iv"
293.Fc
294.Sh DESCRIPTION
295This library contains a fast implementation of the DES encryption
296algorithm.
297.Pp
298There are two phases to the use of DES encryption.
299The first is the generation of a
300.Vt DES_key_schedule
301from a key, the second is the actual encryption.
302A DES key is of type
303.Vt DES_cblock .
304This type is consists of 8 bytes with odd parity.
305The least significant bit in each byte is the parity bit.
306The key schedule is an expanded form of the key; it is used to speed the
307encryption process.
308.Pp
309.Fn DES_random_key
310generates a random key in odd parity.
311.Pp
312Before a DES key can be used, it must be converted into the architecture
313dependent
314.Vt DES_key_schedule
315via the
316.Fn DES_set_key_checked
317or
318.Fn DES_set_key_unchecked
319function.
320.Pp
321.Fn DES_set_key_checked
322will check that the key passed is of odd parity and is not a week or
323semi-weak key.
324If the parity is wrong, then -1 is returned.
325If the key is a weak key, then -2 is returned.
326If an error is returned, the key schedule is not generated.
327.Pp
328.Fn DES_set_key
329works like
330.Fn DES_set_key_checked
331if the
332.Em DES_check_key
333flag is non-zero, otherwise like
334.Fn DES_set_key_unchecked .
335These functions are available for compatibility; it is recommended to
336use a function that does not depend on a global variable.
337.Pp
338.Fn DES_set_odd_parity
339sets the parity of the passed
340.Fa key
341to odd.
342.Pp
343.Fn DES_is_weak_key
344returns 1 is the passed key is a weak key, 0 if it is ok.
345.Pp
346The following routines mostly operate on an input and output stream of
347.Vt DES_cblock Ns s.
348.Pp
349.Fn DES_ecb_encrypt
350is the basic DES encryption routine that encrypts or decrypts a single
3518-byte
352.Vt DES_cblock
353in electronic code book (ECB) mode.
354It always transforms the input data, pointed to by
355.Fa input ,
356into the output data, pointed to by the
357.Fa output
358argument.
359If the
360.Fa enc
361argument is non-zero
362.Pq Dv DES_ENCRYPT ,
363the
364.Fa input
365(cleartext) is encrypted in to the
366.Fa output
367(ciphertext) using the key_schedule specified by the
368.Fa schedule
369argument, previously set via
370.Fn DES_set_key .
371If
372.Fa enc
373is zero
374.Pq Dv DES_DECRYPT ,
375the
376.Fa input
377(now ciphertext) is decrypted into the
378.Fa output
379(now cleartext).
380Input and output may overlap.
381.Fn DES_ecb_encrypt
382does not return a value.
383.Pp
384.Fn DES_ecb3_encrypt
385encrypts/decrypts the
386.Fa input
387block by using three-key Triple-DES encryption in ECB mode.
388This involves encrypting the input with
389.Fa ks1 ,
390decrypting with the key schedule
391.Fa ks2 ,
392and then encrypting with
393.Fa ks3 .
394This routine greatly reduces the chances of brute force breaking of DES
395and has the advantage of if
396.Fa ks1 ,
397.Fa ks2 ,
398and
399.Fa ks3
400are the same, it is equivalent to just encryption using ECB mode and
401.Fa ks1
402as the key.
403.Pp
404The macro
405.Fn DES_ecb2_encrypt
406is provided to perform two-key Triple-DES encryption by using
407.Fa ks1
408for the final encryption.
409.Pp
410.Fn DES_ncbc_encrypt
411encrypts/decrypts using the cipher-block-chaining (CBC) mode of DES.
412If the
413.Fa enc
414argument is non-zero, the routine cipher-block-chain encrypts the
415cleartext data pointed to by the
416.Fa input
417argument into the ciphertext pointed to by the
418.Fa output
419argument, using the key schedule provided by the
420.Fa schedule
421argument, and initialization vector provided by the
422.Fa ivec
423argument.
424If the
425.Fa length
426argument is not an integral multiple of eight bytes, the last block is
427copied to a temporary area and zero filled.
428The output is always an integral multiple of eight bytes.
429.Pp
430.Fn DES_xcbc_encrypt
431is RSA's DESX mode of DES.
432It uses
433.Fa inw
434and
435.Fa outw
436to 'whiten' the encryption.
437.Fa inw
438and
439.Fa outw
440are secret (unlike the iv) and are as such, part of the key.
441So the key is sort of 24 bytes.
442This is much better than CBC DES.
443.Pp
444.Fn DES_ede3_cbc_encrypt
445implements outer triple CBC DES encryption with three keys.
446This means that each DES operation inside the CBC mode is really an
447.Qq Li C=E(ks3,D(ks2,E(ks1,M))) .
448This mode is used by SSL.
449.Pp
450The
451.Fn DES_ede2_cbc_encrypt
452macro implements two-key Triple-DES by reusing
453.Fa ks1
454for the final encryption.
455.Qq Li C=E(ks1,D(ks2,E(ks1,M))) .
456This form of Triple-DES is used by the RSAREF library.
457.Pp
458.Fn DES_pcbc_encrypt
459encrypt/decrypts using the propagating cipher block chaining mode used
460by Kerberos v4.
461Its parameters are the same as
462.Fn DES_ncbc_encrypt .
463.Pp
464.Fn DES_cfb_encrypt
465encrypt/decrypts using cipher feedback mode.
466This method takes an array of characters as input and outputs and array
467of characters.
468It does not require any padding to 8 character groups.
469Note: the
470.Fa ivec
471variable is changed and the new changed value needs to be passed to the
472next call to this function.
473Since this function runs a complete DES ECB encryption per
474.Fa numbits ,
475this function is only suggested for use when sending small numbers of
476characters.
477.Pp
478.Fn DES_cfb64_encrypt
479implements CFB mode of DES with 64bit feedback.
480Why is this useful you ask?
481Because this routine will allow you to encrypt an arbitrary number of
482bytes, no 8 byte padding.
483Each call to this routine will encrypt the input bytes to output and
484then update ivec and num.
485num contains 'how far' we are though ivec.
486If this does not make much sense, read more about cfb mode of DES :-).
487.Pp
488.Fn DES_ede3_cfb64_encrypt
489and
490.Fn DES_ede2_cfb64_encrypt
491is the same as
492.Fn DES_cfb64_encrypt
493except that Triple-DES is used.
494.Pp
495.Fn DES_ofb_encrypt
496encrypts using output feedback mode.
497This method takes an array of characters as input and outputs and array
498of characters.
499It does not require any padding to 8 character groups.
500Note: the
501.Fa ivec
502variable is changed and the new changed value needs to be passed to the
503next call to this function.
504Since this function runs a complete DES ECB encryption per numbits, this
505function is only suggested for use when sending small numbers of
506characters.
507.Pp
508.Fn DES_ofb64_encrypt
509is the same as
510.Fn DES_cfb64_encrypt
511using Output Feed Back mode.
512.Pp
513.Fn DES_ede3_ofb64_encrypt
514and
515.Fn DES_ede2_ofb64_encrypt
516is the same as
517.Fn DES_ofb64_encrypt ,
518using Triple-DES.
519.Pp
520The following functions are included in the DES library for
521compatibility with the MIT Kerberos library.
522.Pp
523.Fn DES_cbc_cksum
524produces an 8 byte checksum based on the input stream (via CBC
525encryption).
526The last 4 bytes of the checksum are returned and the complete 8 bytes
527are placed in
528.Fa output .
529This function is used by Kerberos v4.
530Other applications should use
531.Xr EVP_DigestInit 3
532etc. instead.
533.Pp
534.Fn DES_quad_cksum
535is a Kerberos v4 function.
536It returns a 4 byte checksum from the input bytes.
537The algorithm can be iterated over the input, depending on
538.Fa out_count ,
5391, 2, 3 or 4 times.
540If
541.Fa output
542is
543.Pf non- Dv NULL ,
544the 8 bytes generated by each pass are written into
545.Fa output .
546.Pp
547The following are DES-based transformations:
548.Pp
549.Fn DES_fcrypt
550is a fast version of the Unix
551.Xr crypt 3
552function.
553This version takes only a small amount of space relative to other
554fast crypt implementations.
555This is different to the normal crypt in that the third parameter is the
556buffer that the return value is written into.
557It needs to be at least 14 bytes long.
558This function is thread safe, unlike the normal crypt.
559.Pp
560.Fn DES_crypt
561is a faster replacement for the normal system
562.Xr crypt 3 .
563This function calls
564.Fn DES_fcrypt
565with a static array passed as the third parameter.
566This emulates the normal non-thread safe semantics of
567.Xr crypt 3 .
568.Pp
569.Fn DES_enc_write
570writes
571.Fa len
572bytes to file descriptor
573.Fa fd
574from buffer
575.Fa buf .
576The data is encrypted via
577.Em pcbc_encrypt
578(default) using
579.Fa sched
580for the key and
581.Fa iv
582as a starting vector.
583The actual data send down
584.Fa fd
585consists of 4 bytes (in network byte order) containing the length of the
586following encrypted data.
587The encrypted data then follows, padded with random data out to a
588multiple of 8 bytes.
589.Pp
590.Fn DES_enc_read
591is used to read
592.Fa len
593bytes from file descriptor
594.Fa fd
595into buffer
596.Fa buf .
597The data being read from
598.Fa fd
599is assumed to have come from
600.Fn DES_enc_write
601and is decrypted using
602.Fa sched
603for the key schedule and
604.Fa iv
605for the initial vector.
606.Pp
607.Sy Warning:
608The data format used by
609.Fn DES_enc_write
610and
611.Fn DES_enc_read
612has a cryptographic weakness: When asked to write more than
613.Dv MAXWRITE
614bytes,
615.Fn DES_enc_write
616will split the data into several chunks that are all encrypted using the
617same IV.
618So don't use these functions unless you are sure you know what
619you do (in which case you might not want to use them anyway).
620They cannot handle non-blocking sockets.
621.Fn DES_enc_read
622uses an internal state and thus cannot be used on multiple files.
623.Pp
624.Em DES_rw_mode
625is used to specify the encryption mode to use with
626.Fn DES_enc_read .
627If set to
628.Dv DES_PCBC_MODE
629(the default), DES_pcbc_encrypt is used.
630If set to
631.Dv DES_CBC_MODE
632DES_cbc_encrypt is used.
633.Sh SEE ALSO
634.Xr crypt 3 ,
635.Xr rand 3
636.Pp
637The
638.Xr evp 3
639library provides higher-level encryption functions.
640.Sh STANDARDS
641ANSI X3.106
642.Pp
643The DES library was initially written to be source code compatible
644with the MIT Kerberos library.
645.Sh HISTORY
646In OpenSSL 0.9.7, all des_ functions were renamed to DES_ to avoid
647clashes with older versions of libdes.
648.Pp
649.Fn DES_set_key_checked
650and
651.Fn DES_set_key_unchecked
652were added in OpenSSL 0.9.5.
653.Pp
654.Fn des_generate_random_block ,
655.Fn des_init_random_number_generator ,
656.Fn des_new_random_key ,
657.Fn des_set_random_generator_seed ,
658.Xr des_set_sequence_number ,
659and
660.Fn des_rand_data 3
661are used in newer versions of Kerberos but are not implemented here.
662.Pp
663.Fn DES_random_key
664generated cryptographically weak random data in SSLeay and in OpenSSL
665prior version 0.9.5, as well as in the original MIT library.
666.Sh AUTHORS
667.An Eric Young Aq Mt eay@cryptsoft.com
668.Sh CAVEATS
669Single-key DES is insecure due to its short key size.
670ECB mode is not suitable for most applications.
671.Sh BUGS
672.Xr DES_cbc_encrypt 3
673does not modify
674.Fa ivec ;
675use
676.Fn DES_ncbc_encrypt
677instead.
678.Pp
679.Fn DES_cfb_encrypt
680and
681.Fn DES_ofb_encrypt
682operates on input of 8 bits.
683What this means is that if you set numbits to 12, and length to 2, the
684first 12 bits will come from the 1st input byte and the low half of the
685second input byte.
686The second 12 bits will have the low 8 bits taken from the 3rd input
687byte and the top 4 bits taken from the 4th input byte.
688The same holds for output.
689This function has been implemented this way because most people will be
690using a multiple of 8 and because once you get into pulling bytes input
691bytes apart things get ugly!
692.Pp
693.Fn DES_string_to_key
694is available for backward compatibility with the MIT library.
695New applications should use a cryptographic hash function.
696The same applies for
697.Fn DES_string_to_2key .