Browse Source

add chacha20-ietf support with updated libsscrypto

ChaCha20 with an extended (96 bit) nonce and a 32-bit counter has
been implemented as crypto_stream_chacha20_ietf() from LibSodium 1.0.4

Please refer to https://tools.ietf.org/html/rfc7539 for details.

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
tags/3.0
Syrone Wong 8 years ago
parent
commit
131c4940c6
4 changed files with 9 additions and 0 deletions
  1. BIN
      shadowsocks-csharp/Data/libsscrypto.dll.gz
  2. +3
    -0
      shadowsocks-csharp/Encryption/Sodium.cs
  3. +5
    -0
      shadowsocks-csharp/Encryption/SodiumEncryptor.cs
  4. +1
    -0
      shadowsocks-csharp/View/ConfigForm.Designer.cs

BIN
shadowsocks-csharp/Data/libsscrypto.dll.gz View File


+ 3
- 0
shadowsocks-csharp/Encryption/Sodium.cs View File

@@ -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,


+ 5
- 0
shadowsocks-csharp/Encryption/SodiumEncryptor.cs View File

@@ -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
- 0
shadowsocks-csharp/View/ConfigForm.Designer.cs View File

@@ -201,6 +201,7 @@
"rc4-md5",
"salsa20",
"chacha20",
"chacha20-ietf",
"aes-256-cfb",
"aes-192-cfb",
"aes-128-cfb"});


Loading…
Cancel
Save