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.

EncryptorBase.cs 2.9 kB

11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. namespace Shadowsocks.Encryption
  2. {
  3. public class EncryptorInfo
  4. {
  5. public int KeySize;
  6. public int IvSize;
  7. public int SaltSize;
  8. public int TagSize;
  9. public int NonceSize;
  10. public int Type;
  11. public string InnerLibName;
  12. // For those who make use of internal crypto method name
  13. // e.g. mbed TLS
  14. #region Stream ciphers
  15. public EncryptorInfo(string innerLibName, int keySize, int ivSize, int type)
  16. {
  17. this.KeySize = keySize;
  18. this.IvSize = ivSize;
  19. this.Type = type;
  20. this.InnerLibName = innerLibName;
  21. }
  22. public EncryptorInfo(int keySize, int ivSize, int type)
  23. {
  24. this.KeySize = keySize;
  25. this.IvSize = ivSize;
  26. this.Type = type;
  27. this.InnerLibName = string.Empty;
  28. }
  29. #endregion
  30. #region AEAD ciphers
  31. public EncryptorInfo(string innerLibName, int keySize, int saltSize, int nonceSize, int tagSize, int type)
  32. {
  33. this.KeySize = keySize;
  34. this.SaltSize = saltSize;
  35. this.NonceSize = nonceSize;
  36. this.TagSize = tagSize;
  37. this.Type = type;
  38. this.InnerLibName = innerLibName;
  39. }
  40. public EncryptorInfo(int keySize, int saltSize, int nonceSize, int tagSize, int type)
  41. {
  42. this.KeySize = keySize;
  43. this.SaltSize = saltSize;
  44. this.NonceSize = nonceSize;
  45. this.TagSize = tagSize;
  46. this.Type = type;
  47. this.InnerLibName = string.Empty;
  48. }
  49. #endregion
  50. }
  51. public abstract class EncryptorBase
  52. : IEncryptor
  53. {
  54. public const int MAX_INPUT_SIZE = 32768;
  55. public const int MAX_DOMAIN_LEN = 255;
  56. public const int ADDR_PORT_LEN = 2;
  57. public const int ADDR_ATYP_LEN = 1;
  58. public const int ATYP_IPv4 = 0x01;
  59. public const int ATYP_DOMAIN = 0x03;
  60. public const int ATYP_IPv6 = 0x04;
  61. public const int MD5_LEN = 16;
  62. protected EncryptorBase(string method, string password)
  63. {
  64. Method = method;
  65. Password = password;
  66. }
  67. protected string Method;
  68. protected string Password;
  69. public abstract void Encrypt(byte[] buf, int length, byte[] outbuf, out int outlength);
  70. public abstract void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength);
  71. public abstract void EncryptUDP(byte[] buf, int length, byte[] outbuf, out int outlength);
  72. public abstract void DecryptUDP(byte[] buf, int length, byte[] outbuf, out int outlength);
  73. public abstract void Dispose();
  74. public int AddrBufLength { get; set; } = - 1;
  75. }
  76. }