diff --git a/shadowsocks-csharp/Encryption/Sodium.cs b/shadowsocks-csharp/Encryption/Sodium.cs index 5e0d20d1..96f3673a 100755 --- a/shadowsocks-csharp/Encryption/Sodium.cs +++ b/shadowsocks-csharp/Encryption/Sodium.cs @@ -42,9 +42,15 @@ static Sodium() [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] public extern static void crypto_stream_salsa20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k); + [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] + public extern static void crypto_stream_xsalsa20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k); + [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] public extern static void crypto_stream_chacha20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k); + [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] + public extern static void crypto_stream_xchacha20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k); + [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] public extern static int crypto_stream_chacha20_ietf_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, uint ic, byte[] k); } diff --git a/shadowsocks-csharp/Encryption/SodiumEncryptor.cs b/shadowsocks-csharp/Encryption/SodiumEncryptor.cs index b1e2f3f5..523e1276 100755 --- a/shadowsocks-csharp/Encryption/SodiumEncryptor.cs +++ b/shadowsocks-csharp/Encryption/SodiumEncryptor.cs @@ -10,6 +10,8 @@ public class SodiumEncryptor const int CIPHER_SALSA20 = 1; const int CIPHER_CHACHA20 = 2; const int CIPHER_CHACHA20_IETF = 3; + const int CIPHER_XSALSA20 = 4 + 1; + const int CIPHER_XCHACHA20 = 4 + 2; const int SODIUM_BLOCK_SIZE = 64; @@ -37,6 +39,12 @@ public SodiumEncryptor(string method, string password) case CIPHER_CHACHA20: encryptor_delegate = Sodium.crypto_stream_chacha20_xor_ic; break; + case CIPHER_XSALSA20: + encryptor_delegate = Sodium.crypto_stream_xsalsa20_xor_ic; + break; + case CIPHER_XCHACHA20: + encryptor_delegate = Sodium.crypto_stream_xchacha20_xor_ic; + break; case CIPHER_CHACHA20_IETF: encryptor_delegate = crypto_stream_chacha20_ietf_xor_ic; break; @@ -46,6 +54,8 @@ public SodiumEncryptor(string method, string password) private static Dictionary _ciphers = new Dictionary { {"salsa20", new EncryptorInfo(32, 8, true, CIPHER_SALSA20)}, {"chacha20", new EncryptorInfo(32, 8, true, CIPHER_CHACHA20)}, + {"xsalsa20", new EncryptorInfo(32, 24, true, CIPHER_XSALSA20)}, + {"xchacha20", new EncryptorInfo(32, 24, true, CIPHER_XCHACHA20)}, {"chacha20-ietf", new EncryptorInfo(32, 12, true, CIPHER_CHACHA20_IETF)}, };