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.

CryptoBase.cs 1.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. namespace Shadowsocks.Crypto
  3. {
  4. public abstract class CryptoBase : ICrypto
  5. {
  6. private static int _currentId = 0;
  7. public const int MaxInputSize = 32768;
  8. public const int MAX_DOMAIN_LEN = 255;
  9. public const int ADDR_PORT_LEN = 2;
  10. public const int ADDR_ATYP_LEN = 1;
  11. public const int ATYP_IPv4 = 0x01;
  12. public const int ATYP_DOMAIN = 0x03;
  13. public const int ATYP_IPv6 = 0x04;
  14. public const int MD5Length = 16;
  15. // for debugging only, give it a number to trace data stream
  16. public readonly int instanceId;
  17. protected CryptoBase(string method, string password)
  18. {
  19. instanceId = _currentId;
  20. _currentId++;
  21. Method = method;
  22. Password = password;
  23. }
  24. protected string Method;
  25. protected string Password;
  26. public override string ToString()
  27. {
  28. return $"{instanceId}({Method},{Password})";
  29. }
  30. public abstract int Encrypt(ReadOnlySpan<byte> plain, Span<byte> cipher);
  31. public abstract int Decrypt(Span<byte> plain, ReadOnlySpan<byte> cipher);
  32. public abstract int EncryptUDP(ReadOnlySpan<byte> plain, Span<byte> cipher);
  33. public abstract int DecryptUDP(Span<byte> plain, ReadOnlySpan<byte> cipher);
  34. public int AddressBufferLength { get; set; } = -1;
  35. }
  36. }