Merge pull request #405 from wongsyrone/chacha20-ietf
add chacha20-ietf support with updated libsscrypto
This commit is contained in:
Binary file not shown.
@@ -40,6 +40,9 @@ namespace Shadowsocks.Encryption
|
||||
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static int 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 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 extern static void ss_sha1_hmac_ex(byte[] key, uint keylen,
|
||||
byte[] input, int ioff, uint ilen,
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Shadowsocks.Encryption
|
||||
{
|
||||
const int CIPHER_SALSA20 = 1;
|
||||
const int CIPHER_CHACHA20 = 2;
|
||||
const int CIPHER_CHACHA20_IETF = 3;
|
||||
|
||||
const int SODIUM_BLOCK_SIZE = 64;
|
||||
|
||||
@@ -29,6 +30,7 @@ namespace Shadowsocks.Encryption
|
||||
private static Dictionary<string, int[]> _ciphers = new Dictionary<string, int[]> {
|
||||
{"salsa20", new int[]{32, 8, CIPHER_SALSA20, PolarSSL.AES_CTX_SIZE}},
|
||||
{"chacha20", new int[]{32, 8, CIPHER_CHACHA20, PolarSSL.AES_CTX_SIZE}},
|
||||
{"chacha20-ietf", new int[]{32, 12, CIPHER_CHACHA20_IETF, PolarSSL.AES_CTX_SIZE}},
|
||||
};
|
||||
|
||||
protected override Dictionary<string, int[]> getCiphers()
|
||||
@@ -75,6 +77,9 @@ namespace Shadowsocks.Encryption
|
||||
case CIPHER_CHACHA20:
|
||||
Sodium.crypto_stream_chacha20_xor_ic(sodiumBuf, sodiumBuf, (ulong)(padding + length), iv, ic, _key);
|
||||
break;
|
||||
case CIPHER_CHACHA20_IETF:
|
||||
Sodium.crypto_stream_chacha20_ietf_xor_ic(sodiumBuf, sodiumBuf, (ulong)(padding + length), iv, (uint)ic, _key);
|
||||
break;
|
||||
}
|
||||
Buffer.BlockCopy(sodiumBuf, padding, outbuf, 0, length);
|
||||
padding += length;
|
||||
|
||||
+1
@@ -201,6 +201,7 @@
|
||||
"rc4-md5",
|
||||
"salsa20",
|
||||
"chacha20",
|
||||
"chacha20-ietf",
|
||||
"aes-256-cfb",
|
||||
"aes-192-cfb",
|
||||
"aes-128-cfb"});
|
||||
|
||||
Reference in New Issue
Block a user