xref: /onnv-gate/usr/src/common/openssl/doc/crypto/des_modes.pod (revision 2175:b0b2f052a486)
1*2175Sjp161948=pod
2*2175Sjp161948
3*2175Sjp161948=for comment openssl_manual_section:7
4*2175Sjp161948
5*2175Sjp161948=head1 NAME
6*2175Sjp161948
7*2175Sjp161948Modes of DES - the variants of DES and other crypto algorithms of OpenSSL
8*2175Sjp161948
9*2175Sjp161948=head1 DESCRIPTION
10*2175Sjp161948
11*2175Sjp161948Several crypto algorithms for OpenSSL can be used in a number of modes.  Those
12*2175Sjp161948are used for using block ciphers in a way similar to stream ciphers, among
13*2175Sjp161948other things.
14*2175Sjp161948
15*2175Sjp161948=head1 OVERVIEW
16*2175Sjp161948
17*2175Sjp161948=head2 Electronic Codebook Mode (ECB)
18*2175Sjp161948
19*2175Sjp161948Normally, this is found as the function I<algorithm>_ecb_encrypt().
20*2175Sjp161948
21*2175Sjp161948=over 2
22*2175Sjp161948
23*2175Sjp161948=item *
24*2175Sjp161948
25*2175Sjp16194864 bits are enciphered at a time.
26*2175Sjp161948
27*2175Sjp161948=item *
28*2175Sjp161948
29*2175Sjp161948The order of the blocks can be rearranged without detection.
30*2175Sjp161948
31*2175Sjp161948=item *
32*2175Sjp161948
33*2175Sjp161948The same plaintext block always produces the same ciphertext block
34*2175Sjp161948(for the same key) making it vulnerable to a 'dictionary attack'.
35*2175Sjp161948
36*2175Sjp161948=item *
37*2175Sjp161948
38*2175Sjp161948An error will only affect one ciphertext block.
39*2175Sjp161948
40*2175Sjp161948=back
41*2175Sjp161948
42*2175Sjp161948=head2 Cipher Block Chaining Mode (CBC)
43*2175Sjp161948
44*2175Sjp161948Normally, this is found as the function I<algorithm>_cbc_encrypt().
45*2175Sjp161948Be aware that des_cbc_encrypt() is not really DES CBC (it does
46*2175Sjp161948not update the IV); use des_ncbc_encrypt() instead.
47*2175Sjp161948
48*2175Sjp161948=over 2
49*2175Sjp161948
50*2175Sjp161948=item *
51*2175Sjp161948
52*2175Sjp161948a multiple of 64 bits are enciphered at a time.
53*2175Sjp161948
54*2175Sjp161948=item *
55*2175Sjp161948
56*2175Sjp161948The CBC mode produces the same ciphertext whenever the same
57*2175Sjp161948plaintext is encrypted using the same key and starting variable.
58*2175Sjp161948
59*2175Sjp161948=item *
60*2175Sjp161948
61*2175Sjp161948The chaining operation makes the ciphertext blocks dependent on the
62*2175Sjp161948current and all preceding plaintext blocks and therefore blocks can not
63*2175Sjp161948be rearranged.
64*2175Sjp161948
65*2175Sjp161948=item *
66*2175Sjp161948
67*2175Sjp161948The use of different starting variables prevents the same plaintext
68*2175Sjp161948enciphering to the same ciphertext.
69*2175Sjp161948
70*2175Sjp161948=item *
71*2175Sjp161948
72*2175Sjp161948An error will affect the current and the following ciphertext blocks.
73*2175Sjp161948
74*2175Sjp161948=back
75*2175Sjp161948
76*2175Sjp161948=head2 Cipher Feedback Mode (CFB)
77*2175Sjp161948
78*2175Sjp161948Normally, this is found as the function I<algorithm>_cfb_encrypt().
79*2175Sjp161948
80*2175Sjp161948=over 2
81*2175Sjp161948
82*2175Sjp161948=item *
83*2175Sjp161948
84*2175Sjp161948a number of bits (j) <= 64 are enciphered at a time.
85*2175Sjp161948
86*2175Sjp161948=item *
87*2175Sjp161948
88*2175Sjp161948The CFB mode produces the same ciphertext whenever the same
89*2175Sjp161948plaintext is encrypted using the same key and starting variable.
90*2175Sjp161948
91*2175Sjp161948=item *
92*2175Sjp161948
93*2175Sjp161948The chaining operation makes the ciphertext variables dependent on the
94*2175Sjp161948current and all preceding variables and therefore j-bit variables are
95*2175Sjp161948chained together and can not be rearranged.
96*2175Sjp161948
97*2175Sjp161948=item *
98*2175Sjp161948
99*2175Sjp161948The use of different starting variables prevents the same plaintext
100*2175Sjp161948enciphering to the same ciphertext.
101*2175Sjp161948
102*2175Sjp161948=item *
103*2175Sjp161948
104*2175Sjp161948The strength of the CFB mode depends on the size of k (maximal if
105*2175Sjp161948j == k).  In my implementation this is always the case.
106*2175Sjp161948
107*2175Sjp161948=item *
108*2175Sjp161948
109*2175Sjp161948Selection of a small value for j will require more cycles through
110*2175Sjp161948the encipherment algorithm per unit of plaintext and thus cause
111*2175Sjp161948greater processing overheads.
112*2175Sjp161948
113*2175Sjp161948=item *
114*2175Sjp161948
115*2175Sjp161948Only multiples of j bits can be enciphered.
116*2175Sjp161948
117*2175Sjp161948=item *
118*2175Sjp161948
119*2175Sjp161948An error will affect the current and the following ciphertext variables.
120*2175Sjp161948
121*2175Sjp161948=back
122*2175Sjp161948
123*2175Sjp161948=head2 Output Feedback Mode (OFB)
124*2175Sjp161948
125*2175Sjp161948Normally, this is found as the function I<algorithm>_ofb_encrypt().
126*2175Sjp161948
127*2175Sjp161948=over 2
128*2175Sjp161948
129*2175Sjp161948
130*2175Sjp161948=item *
131*2175Sjp161948
132*2175Sjp161948a number of bits (j) <= 64 are enciphered at a time.
133*2175Sjp161948
134*2175Sjp161948=item *
135*2175Sjp161948
136*2175Sjp161948The OFB mode produces the same ciphertext whenever the same
137*2175Sjp161948plaintext enciphered using the same key and starting variable.  More
138*2175Sjp161948over, in the OFB mode the same key stream is produced when the same
139*2175Sjp161948key and start variable are used.  Consequently, for security reasons
140*2175Sjp161948a specific start variable should be used only once for a given key.
141*2175Sjp161948
142*2175Sjp161948=item *
143*2175Sjp161948
144*2175Sjp161948The absence of chaining makes the OFB more vulnerable to specific attacks.
145*2175Sjp161948
146*2175Sjp161948=item *
147*2175Sjp161948
148*2175Sjp161948The use of different start variables values prevents the same
149*2175Sjp161948plaintext enciphering to the same ciphertext, by producing different
150*2175Sjp161948key streams.
151*2175Sjp161948
152*2175Sjp161948=item *
153*2175Sjp161948
154*2175Sjp161948Selection of a small value for j will require more cycles through
155*2175Sjp161948the encipherment algorithm per unit of plaintext and thus cause
156*2175Sjp161948greater processing overheads.
157*2175Sjp161948
158*2175Sjp161948=item *
159*2175Sjp161948
160*2175Sjp161948Only multiples of j bits can be enciphered.
161*2175Sjp161948
162*2175Sjp161948=item *
163*2175Sjp161948
164*2175Sjp161948OFB mode of operation does not extend ciphertext errors in the
165*2175Sjp161948resultant plaintext output.  Every bit error in the ciphertext causes
166*2175Sjp161948only one bit to be in error in the deciphered plaintext.
167*2175Sjp161948
168*2175Sjp161948=item *
169*2175Sjp161948
170*2175Sjp161948OFB mode is not self-synchronizing.  If the two operation of
171*2175Sjp161948encipherment and decipherment get out of synchronism, the system needs
172*2175Sjp161948to be re-initialized.
173*2175Sjp161948
174*2175Sjp161948=item *
175*2175Sjp161948
176*2175Sjp161948Each re-initialization should use a value of the start variable
177*2175Sjp161948different from the start variable values used before with the same
178*2175Sjp161948key.  The reason for this is that an identical bit stream would be
179*2175Sjp161948produced each time from the same parameters.  This would be
180*2175Sjp161948susceptible to a 'known plaintext' attack.
181*2175Sjp161948
182*2175Sjp161948=back
183*2175Sjp161948
184*2175Sjp161948=head2 Triple ECB Mode
185*2175Sjp161948
186*2175Sjp161948Normally, this is found as the function I<algorithm>_ecb3_encrypt().
187*2175Sjp161948
188*2175Sjp161948=over 2
189*2175Sjp161948
190*2175Sjp161948=item *
191*2175Sjp161948
192*2175Sjp161948Encrypt with key1, decrypt with key2 and encrypt with key3 again.
193*2175Sjp161948
194*2175Sjp161948=item *
195*2175Sjp161948
196*2175Sjp161948As for ECB encryption but increases the key length to 168 bits.
197*2175Sjp161948There are theoretic attacks that can be used that make the effective
198*2175Sjp161948key length 112 bits, but this attack also requires 2^56 blocks of
199*2175Sjp161948memory, not very likely, even for the NSA.
200*2175Sjp161948
201*2175Sjp161948=item *
202*2175Sjp161948
203*2175Sjp161948If both keys are the same it is equivalent to encrypting once with
204*2175Sjp161948just one key.
205*2175Sjp161948
206*2175Sjp161948=item *
207*2175Sjp161948
208*2175Sjp161948If the first and last key are the same, the key length is 112 bits.
209*2175Sjp161948There are attacks that could reduce the effective key strength
210*2175Sjp161948to only slightly more than 56 bits, but these require a lot of memory.
211*2175Sjp161948
212*2175Sjp161948=item *
213*2175Sjp161948
214*2175Sjp161948If all 3 keys are the same, this is effectively the same as normal
215*2175Sjp161948ecb mode.
216*2175Sjp161948
217*2175Sjp161948=back
218*2175Sjp161948
219*2175Sjp161948=head2 Triple CBC Mode
220*2175Sjp161948
221*2175Sjp161948Normally, this is found as the function I<algorithm>_ede3_cbc_encrypt().
222*2175Sjp161948
223*2175Sjp161948=over 2
224*2175Sjp161948
225*2175Sjp161948
226*2175Sjp161948=item *
227*2175Sjp161948
228*2175Sjp161948Encrypt with key1, decrypt with key2 and then encrypt with key3.
229*2175Sjp161948
230*2175Sjp161948=item *
231*2175Sjp161948
232*2175Sjp161948As for CBC encryption but increases the key length to 168 bits with
233*2175Sjp161948the same restrictions as for triple ecb mode.
234*2175Sjp161948
235*2175Sjp161948=back
236*2175Sjp161948
237*2175Sjp161948=head1 NOTES
238*2175Sjp161948
239*2175Sjp161948This text was been written in large parts by Eric Young in his original
240*2175Sjp161948documentation for SSLeay, the predecessor of OpenSSL.  In turn, he attributed
241*2175Sjp161948it to:
242*2175Sjp161948
243*2175Sjp161948	AS 2805.5.2
244*2175Sjp161948	Australian Standard
245*2175Sjp161948	Electronic funds transfer - Requirements for interfaces,
246*2175Sjp161948	Part 5.2: Modes of operation for an n-bit block cipher algorithm
247*2175Sjp161948	Appendix A
248*2175Sjp161948
249*2175Sjp161948=head1 SEE ALSO
250*2175Sjp161948
251*2175Sjp161948L<blowfish(3)|blowfish(3)>, L<des(3)|des(3)>, L<idea(3)|idea(3)>,
252*2175Sjp161948L<rc2(3)|rc2(3)>
253*2175Sjp161948
254*2175Sjp161948=cut
255*2175Sjp161948
256