- Drop redundant code. I should read code carefully, mbed TLS will set operation when invoking mbedtls_cipher_setkey(), the last param const mbedtls_operation_t operation is what we want. - minor changes Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
51 lines
1.7 KiB
C#
Executable File
51 lines
1.7 KiB
C#
Executable File
using System;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
|
|
using Shadowsocks.Controller;
|
|
using Shadowsocks.Properties;
|
|
using Shadowsocks.Util;
|
|
|
|
namespace Shadowsocks.Encryption
|
|
{
|
|
public class Sodium
|
|
{
|
|
const string DLLNAME = "libsscrypto";
|
|
|
|
static Sodium()
|
|
{
|
|
string dllPath = Utils.GetTempPath("libsscrypto.dll");
|
|
try
|
|
{
|
|
FileManager.UncompressFile(dllPath, Resources.libsscrypto_dll);
|
|
}
|
|
catch (IOException)
|
|
{
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Logging.LogUsefulException(e);
|
|
}
|
|
LoadLibrary(dllPath);
|
|
}
|
|
|
|
[DllImport("Kernel32.dll")]
|
|
private static extern IntPtr LoadLibrary(string path);
|
|
|
|
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
|
|
public static extern int crypto_stream_salsa20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k);
|
|
|
|
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
|
|
public static extern int crypto_stream_chacha20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k);
|
|
|
|
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
|
|
public static extern int crypto_stream_chacha20_ietf_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, uint ic, byte[] k);
|
|
|
|
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
|
|
public static extern void ss_sha1_hmac_ex(byte[] key, uint keylen,
|
|
byte[] input, int ioff, uint ilen,
|
|
byte[] output);
|
|
}
|
|
}
|
|
|