3 =for comment openssl_manual_section:7
7 des_modes - the variants of DES and other crypto algorithms of OpenSSL
11 Several crypto algorithms for OpenSSL can be used in a number of modes. Those
12 are used for using block ciphers in a way similar to stream ciphers, among
17 =head2 Electronic Codebook Mode (ECB)
19 Normally, this is found as the function I<algorithm>_ecb_encrypt().
25 64 bits are enciphered at a time.
29 The order of the blocks can be rearranged without detection.
33 The same plaintext block always produces the same ciphertext block
34 (for the same key) making it vulnerable to a 'dictionary attack'.
38 An error will only affect one ciphertext block.
42 =head2 Cipher Block Chaining Mode (CBC)
44 Normally, this is found as the function I<algorithm>_cbc_encrypt().
45 Be aware that des_cbc_encrypt() is not really DES CBC (it does
46 not update the IV); use des_ncbc_encrypt() instead.
52 a multiple of 64 bits are enciphered at a time.
56 The CBC mode produces the same ciphertext whenever the same
57 plaintext is encrypted using the same key and starting variable.
61 The chaining operation makes the ciphertext blocks dependent on the
62 current and all preceding plaintext blocks and therefore blocks can not
67 The use of different starting variables prevents the same plaintext
68 enciphering to the same ciphertext.
72 An error will affect the current and the following ciphertext blocks.
76 =head2 Cipher Feedback Mode (CFB)
78 Normally, this is found as the function I<algorithm>_cfb_encrypt().
84 a number of bits (j) <= 64 are enciphered at a time.
88 The CFB mode produces the same ciphertext whenever the same
89 plaintext is encrypted using the same key and starting variable.
93 The chaining operation makes the ciphertext variables dependent on the
94 current and all preceding variables and therefore j-bit variables are
95 chained together and can not be rearranged.
99 The use of different starting variables prevents the same plaintext
100 enciphering to the same ciphertext.
104 The strength of the CFB mode depends on the size of k (maximal if
105 j == k). In my implementation this is always the case.
109 Selection of a small value for j will require more cycles through
110 the encipherment algorithm per unit of plaintext and thus cause
111 greater processing overheads.
115 Only multiples of j bits can be enciphered.
119 An error will affect the current and the following ciphertext variables.
123 =head2 Output Feedback Mode (OFB)
125 Normally, this is found as the function I<algorithm>_ofb_encrypt().
132 a number of bits (j) <= 64 are enciphered at a time.
136 The OFB mode produces the same ciphertext whenever the same
137 plaintext enciphered using the same key and starting variable. More
138 over, in the OFB mode the same key stream is produced when the same
139 key and start variable are used. Consequently, for security reasons
140 a specific start variable should be used only once for a given key.
144 The absence of chaining makes the OFB more vulnerable to specific attacks.
148 The use of different start variables values prevents the same
149 plaintext enciphering to the same ciphertext, by producing different
154 Selection of a small value for j will require more cycles through
155 the encipherment algorithm per unit of plaintext and thus cause
156 greater processing overheads.
160 Only multiples of j bits can be enciphered.
164 OFB mode of operation does not extend ciphertext errors in the
165 resultant plaintext output. Every bit error in the ciphertext causes
166 only one bit to be in error in the deciphered plaintext.
170 OFB mode is not self-synchronizing. If the two operation of
171 encipherment and decipherment get out of synchronism, the system needs
172 to be re-initialized.
176 Each re-initialization should use a value of the start variable
177 different from the start variable values used before with the same
178 key. The reason for this is that an identical bit stream would be
179 produced each time from the same parameters. This would be
180 susceptible to a 'known plaintext' attack.
184 =head2 Triple ECB Mode
186 Normally, this is found as the function I<algorithm>_ecb3_encrypt().
192 Encrypt with key1, decrypt with key2 and encrypt with key3 again.
196 As for ECB encryption but increases the key length to 168 bits.
197 There are theoretic attacks that can be used that make the effective
198 key length 112 bits, but this attack also requires 2^56 blocks of
199 memory, not very likely, even for the NSA.
203 If both keys are the same it is equivalent to encrypting once with
208 If the first and last key are the same, the key length is 112 bits.
209 There are attacks that could reduce the effective key strength
210 to only slightly more than 56 bits, but these require a lot of memory.
214 If all 3 keys are the same, this is effectively the same as normal
219 =head2 Triple CBC Mode
221 Normally, this is found as the function I<algorithm>_ede3_cbc_encrypt().
228 Encrypt with key1, decrypt with key2 and then encrypt with key3.
232 As for CBC encryption but increases the key length to 168 bits with
233 the same restrictions as for triple ecb mode.
239 This text was been written in large parts by Eric Young in his original
240 documentation for SSLeay, the predecessor of OpenSSL. In turn, he attributed
245 Electronic funds transfer - Requirements for interfaces,
246 Part 5.2: Modes of operation for an n-bit block cipher algorithm
251 L<blowfish(3)|blowfish(3)>, L<des(3)|des(3)>, L<idea(3)|idea(3)>,