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.

Sodium.cs 1.7 kB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.IO;
  3. using System.Runtime.InteropServices;
  4. using Shadowsocks.Controller;
  5. using Shadowsocks.Properties;
  6. using Shadowsocks.Util;
  7. namespace Shadowsocks.Encryption
  8. {
  9. public class Sodium
  10. {
  11. const string DLLNAME = "libsscrypto";
  12. static Sodium()
  13. {
  14. string dllPath = Utils.GetTempPath("libsscrypto.dll");
  15. try
  16. {
  17. FileManager.UncompressFile(dllPath, Resources.libsscrypto_dll);
  18. }
  19. catch (IOException)
  20. {
  21. }
  22. catch (Exception e)
  23. {
  24. Logging.LogUsefulException(e);
  25. }
  26. LoadLibrary(dllPath);
  27. }
  28. [DllImport("Kernel32.dll")]
  29. private static extern IntPtr LoadLibrary(string path);
  30. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  31. public extern static int crypto_stream_salsa20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k);
  32. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  33. public extern static int crypto_stream_chacha20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k);
  34. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  35. public extern static int crypto_stream_chacha20_ietf_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, uint ic, byte[] k);
  36. [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
  37. public extern static void ss_sha1_hmac_ex(byte[] key, uint keylen,
  38. byte[] input, int ioff, uint ilen,
  39. byte[] output);
  40. }
  41. }