CipherModeEx.cs 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Renci.SshNet.Security.Cryptography
  6. {
  7. /// <summary>
  8. /// Provides additional cipher modes
  9. /// </summary>
  10. public enum CipherModeEx
  11. {
  12. /// <summary>
  13. /// The Cipher Block Chaining (CBC) mode introduces feedback. Before each plain
  14. /// text block is encrypted, it is combined with the cipher text of the previous
  15. /// block by a bitwise exclusive OR operation. This ensures that even if the
  16. /// plain text contains many identical blocks, they will each encrypt to a different
  17. /// cipher text block. The initialization vector is combined with the first plain
  18. /// text block by a bitwise exclusive OR operation before the block is encrypted.
  19. /// If a single bit of the cipher text block is mangled, the corresponding plain
  20. /// text block will also be mangled. In addition, a bit in the subsequent block,
  21. /// in the same position as the original mangled bit, will be mangled.
  22. /// </summary>
  23. CBC = 1,
  24. /// <summary>
  25. /// The Electronic Codebook (ECB) mode encrypts each block individually. This
  26. /// means that any blocks of plain text that are identical and are in the same
  27. /// message, or in a different message encrypted with the same key, will be transformed
  28. /// into identical cipher text blocks. If the plain text to be encrypted contains
  29. /// substantial repetition, it is feasible for the cipher text to be broken one
  30. /// block at a time. Also, it is possible for an active adversary to substitute
  31. /// and exchange individual blocks without detection. If a single bit of the
  32. /// cipher text block is mangled, the entire corresponding plain text block will
  33. /// also be mangled.
  34. /// </summary>
  35. ECB = 2,
  36. /// <summary>
  37. /// The Output Feedback (OFB) mode processes small increments of plain text into
  38. /// cipher text instead of processing an entire block at a time. This mode is
  39. /// similar to CFB; the only difference between the two modes is the way that
  40. /// the shift register is filled. If a bit in the cipher text is mangled, the
  41. /// corresponding bit of plain text will be mangled. However, if there are extra
  42. /// or missing bits from the cipher text, the plain text will be mangled from
  43. /// that point on.
  44. /// </summary>
  45. OFB = 3,
  46. /// <summary>
  47. /// The Cipher Feedback (CFB) mode processes small increments of plain text into
  48. /// cipher text, instead of processing an entire block at a time. This mode uses
  49. /// a shift register that is one block in length and is divided into sections.
  50. /// For example, if the block size is eight bytes, with one byte processed at
  51. /// a time, the shift register is divided into eight sections. If a bit in the
  52. /// cipher text is mangled, one plain text bit is mangled and the shift register
  53. /// is corrupted. This results in the next several plain text increments being
  54. /// mangled until the bad bit is shifted out of the shift register.
  55. /// </summary>
  56. CFB = 4,
  57. /// <summary>
  58. /// The Cipher Text Stealing (CTS) mode handles any length of plain text and
  59. /// produces cipher text whose length matches the plain text length. This mode
  60. /// behaves like the CBC mode for all but the last two blocks of the plain text.
  61. /// </summary>
  62. CTS = 5,
  63. /// <summary>
  64. /// Counter Block Cipher mode
  65. /// </summary>
  66. CTR = 10,
  67. }
  68. }