You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

CipherInfo.cs 2.8 kB

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using Shadowsocks.Controller;
  2. namespace Shadowsocks.Encryption
  3. {
  4. public enum CipherFamily
  5. {
  6. Plain,
  7. Table,
  8. AesGcm,
  9. AesCfb,
  10. AesCtr,
  11. Chacha20,
  12. Chacha20Poly1305,
  13. XChacha20Poly1305,
  14. Rc4,
  15. Rc4Md5,
  16. }
  17. public enum CipherStandardState
  18. {
  19. InUse,
  20. Deprecated, // popup warning when updated
  21. Hidden, // enabled by hidden flag in config file
  22. Unstable, // not in standard list or wip, only gui info
  23. }
  24. public class CipherParameter
  25. {
  26. public int KeySize;
  27. }
  28. public class StreamCipherParameter : CipherParameter
  29. {
  30. public int IvSize;
  31. public override string ToString()
  32. {
  33. return $"stream (key:{KeySize * 8}, iv:{IvSize * 8})";
  34. }
  35. }
  36. public class AEADCipherParameter : CipherParameter
  37. {
  38. public int SaltSize;
  39. public int TagSize;
  40. public int NonceSize;
  41. public override string ToString()
  42. {
  43. return $"aead (key:{KeySize * 8}, salt:{SaltSize * 8}, tag:{TagSize * 8}, nonce:{NonceSize * 8})";
  44. }
  45. }
  46. public class CipherInfo
  47. {
  48. public string Name;
  49. public CipherFamily Type;
  50. public CipherParameter CipherParameter;
  51. public CipherStandardState StandardState = CipherStandardState.InUse;
  52. #region Stream ciphers
  53. public CipherInfo(string name, int keySize, int ivSize, CipherFamily type, CipherStandardState state = CipherStandardState.Hidden)
  54. {
  55. Type = type;
  56. Name = name;
  57. StandardState = state;
  58. CipherParameter = new StreamCipherParameter
  59. {
  60. KeySize = keySize,
  61. IvSize = ivSize,
  62. };
  63. }
  64. #endregion
  65. #region AEAD ciphers
  66. public CipherInfo(string name, int keySize, int saltSize, int nonceSize, int tagSize, CipherFamily type, CipherStandardState state = CipherStandardState.InUse)
  67. {
  68. Type = type;
  69. Name = name;
  70. StandardState = state;
  71. CipherParameter = new AEADCipherParameter
  72. {
  73. KeySize = keySize,
  74. SaltSize = saltSize,
  75. NonceSize = nonceSize,
  76. TagSize = tagSize,
  77. };
  78. }
  79. #endregion
  80. public override string ToString()
  81. {
  82. return StandardState == CipherStandardState.InUse ? Name : $"{Name} ({I18N.GetString(StandardState.ToString().ToLower())})";
  83. }
  84. public string ToString(bool verbose)
  85. {
  86. if (!verbose)
  87. {
  88. return ToString();
  89. }
  90. return $"{Name} {StandardState} {CipherParameter}";
  91. }
  92. }
  93. }