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.

PolarSSL.cs 2.5 kB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. namespace Shadowsocks.Encrypt
  6. {
  7. public class PolarSSL
  8. {
  9. const string DLLNAME = "polarssl";
  10. public const int AES_CTX_SIZE = 8 + 4 * 68;
  11. public const int AES_ENCRYPT = 1;
  12. public const int AES_DECRYPT = 0;
  13. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  14. public extern static void aes_init(byte[] ctx);
  15. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  16. public extern static void aes_free(byte[] ctx);
  17. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  18. public extern static int aes_setkey_enc(byte[] ctx, byte[] key, int keysize);
  19. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  20. public extern static int aes_crypt_cfb128(byte[] ctx, int mode, int length, ref int iv_off, byte[] iv, byte[] input, byte[] output);
  21. public const int ARC4_CTX_SIZE = 264;
  22. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  23. public extern static void arc4_init(byte[] ctx);
  24. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  25. public extern static void arc4_free(byte[] ctx);
  26. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  27. public extern static void arc4_setup(byte[] ctx, byte[] key, int keysize);
  28. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  29. public extern static int arc4_crypt(byte[] ctx, int length, byte[] input, byte[] output);
  30. public const int BLOWFISH_CTX_SIZE = 4168;
  31. public const int BLOWFISH_ENCRYPT = 1;
  32. public const int BLOWFISH_DECRYPT = 0;
  33. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  34. public extern static void blowfish_init(byte[] ctx);
  35. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  36. public extern static void blowfish_free(byte[] ctx);
  37. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  38. public extern static int blowfish_setkey(byte[] ctx, byte[] key, int keysize);
  39. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  40. public extern static int blowfish_crypt_cfb64(byte[] ctx, int mode, int length, ref int iv_off, byte[] iv, byte[] input, byte[] output);
  41. }
  42. }