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