Note about des_ncbc_encrypt.
[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 Be aware that des_cbc_encrypt() is not really DES CBC (it does
51 not update the IV); use des_ncbc_encrypt() instead.
52
53 =over 2
54
55 =item *
56
57 a multiple of 64 bits are enciphered at a time.
58
59 =item *
60
61 The CBC mode produces the same ciphertext whenever the same
62 plaintext is encrypted using the same key and starting variable.
63
64 =item *
65
66 The chaining operation makes the ciphertext blocks dependent on the
67 current and all preceding plaintext blocks and therefore blocks can not
68 be rearranged.
69
70 =item *
71
72 The use of different starting variables prevents the same plaintext
73 enciphering to the same ciphertext.
74
75 =item *
76
77 An error will affect the current and the following ciphertext blocks.
78
79 =back
80
81 =head2 Cipher Feedback Mode (CFB)
82
83 Normally, this is found as the function I<algorithm>_cfb_encrypt().
84
85 =over 2
86
87 =item *
88
89 a number of bits (j) <= 64 are enciphered at a time.
90
91 =item *
92
93 The CFB mode produces the same ciphertext whenever the same
94 plaintext is encrypted using the same key and starting variable.
95
96 =item *
97
98 The chaining operation makes the ciphertext variables dependent on the
99 current and all preceding variables and therefore j-bit variables are
100 chained together and can not be rearranged.
101
102 =item *
103
104 The use of different starting variables prevents the same plaintext
105 enciphering to the same ciphertext.
106
107 =item *
108
109 The strength of the CFB mode depends on the size of k (maximal if
110 j == k).  In my implementation this is always the case.
111
112 =item *
113
114 Selection of a small value for j will require more cycles through
115 the encipherment algorithm per unit of plaintext and thus cause
116 greater processing overheads.
117
118 =item *
119
120 Only multiples of j bits can be enciphered.
121
122 =item *
123
124 An error will affect the current and the following ciphertext variables.
125
126 =back
127
128 =head2 Output Feedback Mode (OFB)
129
130 Normally, this is found as the function I<algorithm>_ofb_encrypt().
131
132 =over 2
133
134
135 =item *
136
137 a number of bits (j) <= 64 are enciphered at a time.
138
139 =item *
140
141 The OFB mode produces the same ciphertext whenever the same
142 plaintext enciphered using the same key and starting variable.  More
143 over, in the OFB mode the same key stream is produced when the same
144 key and start variable are used.  Consequently, for security reasons
145 a specific start variable should be used only once for a given key.
146
147 =item *
148
149 The absence of chaining makes the OFB more vulnerable to specific attacks.
150
151 =item *
152
153 The use of different start variables values prevents the same
154 plaintext enciphering to the same ciphertext, by producing different
155 key streams.
156
157 =item *
158
159 Selection of a small value for j will require more cycles through
160 the encipherment algorithm per unit of plaintext and thus cause
161 greater processing overheads.
162
163 =item *
164
165 Only multiples of j bits can be enciphered.
166
167 =item *
168
169 OFB mode of operation does not extend ciphertext errors in the
170 resultant plaintext output.  Every bit error in the ciphertext causes
171 only one bit to be in error in the deciphered plaintext.
172
173 =item *
174
175 OFB mode is not self-synchronising.  If the two operation of
176 encipherment and decipherment get out of synchronism, the system needs
177 to be re-initialised.
178
179 =item *
180
181 Each re-initialisation should use a value of the start variable
182 different from the start variable values used before with the same
183 key.  The reason for this is that an identical bit stream would be
184 produced each time from the same parameters.  This would be
185 susceptible to a 'known plaintext' attack.
186
187 =back
188
189 =head2 Triple ECB Mode
190
191 Normally, this is found as the function I<algorithm>_ecb3_encrypt().
192
193 =over 2
194
195 =item *
196
197 Encrypt with key1, decrypt with key2 and encrypt with key3 again.
198
199 =item *
200
201 As for ECB encryption but increases the key length to 168 bits.
202 There are theoretic attacks that can be used that make the effective
203 key length 112 bits, but this attack also requires 2^56 blocks of
204 memory, not very likely, even for the NSA.
205
206 =item *
207
208 If both keys are the same it is equivalent to encrypting once with
209 just one key.
210
211 =item *
212
213 If the first and last key are the same, the key length is 112 bits.
214 There are attacks that could reduce the key space to 55 bit's but it
215 requires 2^56 blocks of memory.
216
217 =item *
218
219 If all 3 keys are the same, this is effectively the same as normal
220 ecb mode.
221
222 =back
223
224 =head2 Triple CBC Mode
225
226 Normally, this is found as the function I<algorithm>_ede3_cbc_encrypt().
227
228 =over 2
229
230
231 =item *
232
233 Encrypt with key1, decrypt with key2 and then encrypt with key3.
234
235 =item *
236
237 As for CBC encryption but increases the key length to 168 bits with
238 the same restrictions as for triple ecb mode.
239
240 =back
241
242 =head1 SEE ALSO
243
244 L<blowfish(3)|blowfish(3)>, L<des(3)|des(3)>, L<idea(3)|idea(3)>,
245 L<rc2(3)|rc2(3)>