des_modes.pod 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. =pod
  2. =head1 NAME
  3. des_modes - the variants of DES and other crypto algorithms of OpenSSL
  4. =head1 DESCRIPTION
  5. Several crypto algorithms for OpenSSL can be used in a number of modes. Those
  6. are used for using block ciphers in a way similar to stream ciphers, among
  7. other things.
  8. =head1 OVERVIEW
  9. =head2 Electronic Codebook Mode (ECB)
  10. Normally, this is found as the function I<algorithm>_ecb_encrypt().
  11. =over 2
  12. =item *
  13. 64 bits are enciphered at a time.
  14. =item *
  15. The order of the blocks can be rearranged without detection.
  16. =item *
  17. The same plaintext block always produces the same ciphertext block
  18. (for the same key) making it vulnerable to a 'dictionary attack'.
  19. =item *
  20. An error will only affect one ciphertext block.
  21. =back
  22. =head2 Cipher Block Chaining Mode (CBC)
  23. Normally, this is found as the function I<algorithm>_cbc_encrypt().
  24. Be aware that des_cbc_encrypt() is not really DES CBC (it does
  25. not update the IV); use des_ncbc_encrypt() instead.
  26. =over 2
  27. =item *
  28. a multiple of 64 bits are enciphered at a time.
  29. =item *
  30. The CBC mode produces the same ciphertext whenever the same
  31. plaintext is encrypted using the same key and starting variable.
  32. =item *
  33. The chaining operation makes the ciphertext blocks dependent on the
  34. current and all preceding plaintext blocks and therefore blocks can not
  35. be rearranged.
  36. =item *
  37. The use of different starting variables prevents the same plaintext
  38. enciphering to the same ciphertext.
  39. =item *
  40. An error will affect the current and the following ciphertext blocks.
  41. =back
  42. =head2 Cipher Feedback Mode (CFB)
  43. Normally, this is found as the function I<algorithm>_cfb_encrypt().
  44. =over 2
  45. =item *
  46. a number of bits (j) <= 64 are enciphered at a time.
  47. =item *
  48. The CFB mode produces the same ciphertext whenever the same
  49. plaintext is encrypted using the same key and starting variable.
  50. =item *
  51. The chaining operation makes the ciphertext variables dependent on the
  52. current and all preceding variables and therefore j-bit variables are
  53. chained together and can not be rearranged.
  54. =item *
  55. The use of different starting variables prevents the same plaintext
  56. enciphering to the same ciphertext.
  57. =item *
  58. The strength of the CFB mode depends on the size of k (maximal if
  59. j == k). In my implementation this is always the case.
  60. =item *
  61. Selection of a small value for j will require more cycles through
  62. the encipherment algorithm per unit of plaintext and thus cause
  63. greater processing overheads.
  64. =item *
  65. Only multiples of j bits can be enciphered.
  66. =item *
  67. An error will affect the current and the following ciphertext variables.
  68. =back
  69. =head2 Output Feedback Mode (OFB)
  70. Normally, this is found as the function I<algorithm>_ofb_encrypt().
  71. =over 2
  72. =item *
  73. a number of bits (j) <= 64 are enciphered at a time.
  74. =item *
  75. The OFB mode produces the same ciphertext whenever the same
  76. plaintext enciphered using the same key and starting variable. More
  77. over, in the OFB mode the same key stream is produced when the same
  78. key and start variable are used. Consequently, for security reasons
  79. a specific start variable should be used only once for a given key.
  80. =item *
  81. The absence of chaining makes the OFB more vulnerable to specific attacks.
  82. =item *
  83. The use of different start variables values prevents the same
  84. plaintext enciphering to the same ciphertext, by producing different
  85. key streams.
  86. =item *
  87. Selection of a small value for j will require more cycles through
  88. the encipherment algorithm per unit of plaintext and thus cause
  89. greater processing overheads.
  90. =item *
  91. Only multiples of j bits can be enciphered.
  92. =item *
  93. OFB mode of operation does not extend ciphertext errors in the
  94. resultant plaintext output. Every bit error in the ciphertext causes
  95. only one bit to be in error in the deciphered plaintext.
  96. =item *
  97. OFB mode is not self-synchronizing. If the two operation of
  98. encipherment and decipherment get out of synchronism, the system needs
  99. to be re-initialized.
  100. =item *
  101. Each re-initialization should use a value of the start variable
  102. different from the start variable values used before with the same
  103. key. The reason for this is that an identical bit stream would be
  104. produced each time from the same parameters. This would be
  105. susceptible to a 'known plaintext' attack.
  106. =back
  107. =head2 Triple ECB Mode
  108. Normally, this is found as the function I<algorithm>_ecb3_encrypt().
  109. =over 2
  110. =item *
  111. Encrypt with key1, decrypt with key2 and encrypt with key3 again.
  112. =item *
  113. As for ECB encryption but increases the key length to 168 bits.
  114. There are theoretic attacks that can be used that make the effective
  115. key length 112 bits, but this attack also requires 2^56 blocks of
  116. memory, not very likely, even for the NSA.
  117. =item *
  118. If both keys are the same it is equivalent to encrypting once with
  119. just one key.
  120. =item *
  121. If the first and last key are the same, the key length is 112 bits.
  122. There are attacks that could reduce the effective key strength
  123. to only slightly more than 56 bits, but these require a lot of memory.
  124. =item *
  125. If all 3 keys are the same, this is effectively the same as normal
  126. ecb mode.
  127. =back
  128. =head2 Triple CBC Mode
  129. Normally, this is found as the function I<algorithm>_ede3_cbc_encrypt().
  130. =over 2
  131. =item *
  132. Encrypt with key1, decrypt with key2 and then encrypt with key3.
  133. =item *
  134. As for CBC encryption but increases the key length to 168 bits with
  135. the same restrictions as for triple ecb mode.
  136. =back
  137. =head1 NOTES
  138. This text was been written in large parts by Eric Young in his original
  139. documentation for SSLeay, the predecessor of OpenSSL. In turn, he attributed
  140. it to:
  141. AS 2805.5.2
  142. Australian Standard
  143. Electronic funds transfer - Requirements for interfaces,
  144. Part 5.2: Modes of operation for an n-bit block cipher algorithm
  145. Appendix A
  146. =head1 SEE ALSO
  147. L<BF_encrypt(3)>, L<DES_crypt(3)>
  148. =head1 COPYRIGHT
  149. Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved.
  150. Licensed under the Apache License 2.0 (the "License"). You may not use
  151. this file except in compliance with the License. You can obtain a copy
  152. in the file LICENSE in the source distribution or at
  153. L<https://www.openssl.org/source/license.html>.
  154. =cut