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