@@ -10,6 +10,7 @@ namespace Shadowsocks.Encryption
{
{
const int CIPHER_SALSA20 = 1;
const int CIPHER_SALSA20 = 1;
const int CIPHER_CHACHA20 = 2;
const int CIPHER_CHACHA20 = 2;
const int CIPHER_CHACHA20_IETF = 3;
const int SODIUM_BLOCK_SIZE = 64;
const int SODIUM_BLOCK_SIZE = 64;
@@ -29,6 +30,7 @@ namespace Shadowsocks.Encryption
private static Dictionary<string, int[]> _ciphers = new Dictionary<string, int[]> {
private static Dictionary<string, int[]> _ciphers = new Dictionary<string, int[]> {
{"salsa20", new int[]{32, 8, CIPHER_SALSA20, PolarSSL.AES_CTX_SIZE}},
{"salsa20", new int[]{32, 8, CIPHER_SALSA20, PolarSSL.AES_CTX_SIZE}},
{"chacha20", new int[]{32, 8, CIPHER_CHACHA20, 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()
protected override Dictionary<string, int[]> getCiphers()
@@ -75,6 +77,9 @@ namespace Shadowsocks.Encryption
case CIPHER_CHACHA20:
case CIPHER_CHACHA20:
Sodium.crypto_stream_chacha20_xor_ic(sodiumBuf, sodiumBuf, (ulong)(padding + length), iv, ic, _key);
Sodium.crypto_stream_chacha20_xor_ic(sodiumBuf, sodiumBuf, (ulong)(padding + length), iv, ic, _key);
break;
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);
Buffer.BlockCopy(sodiumBuf, padding, outbuf, 0, length);
padding += length;
padding += length;