Browse Source

Merge pull request #1725 from celeron533/master

add xchacha20-ietf-poly1305
tags/4.0.9
Allen Zhu GitHub 6 years ago
parent
commit
c168af6975
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 33 additions and 21 deletions
  1. BIN
      shadowsocks-csharp/Data/libcrypto-1_1.dll.gz
  2. BIN
      shadowsocks-csharp/Data/libsscrypto.dll.gz
  3. +17
    -1
      shadowsocks-csharp/Encryption/AEAD/AEADSodiumEncryptor.cs
  4. +3
    -2
      shadowsocks-csharp/Encryption/MbedTLS.cs
  5. +2
    -2
      shadowsocks-csharp/Encryption/OpenSSL.cs
  6. +8
    -0
      shadowsocks-csharp/Encryption/Sodium.cs
  7. +0
    -10
      shadowsocks-csharp/Properties/Resources.Designer.cs
  8. +1
    -4
      shadowsocks-csharp/Properties/Resources.resx
  9. +2
    -1
      shadowsocks-csharp/View/ConfigForm.Designer.cs
  10. +0
    -1
      shadowsocks-csharp/shadowsocks-csharp.csproj

BIN
shadowsocks-csharp/Data/libcrypto-1_1.dll.gz View File


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


+ 17
- 1
shadowsocks-csharp/Encryption/AEAD/AEADSodiumEncryptor.cs View File

@@ -10,7 +10,8 @@ namespace Shadowsocks.Encryption.AEAD
: AEADEncryptor, IDisposable
{
private const int CIPHER_CHACHA20IETFPOLY1305 = 1;
private const int CIPHER_AES256GCM = 2;
private const int CIPHER_XCHACHA20IETFPOLY1305 = 2;
private const int CIPHER_AES256GCM = 3;
private byte[] _sodiumEncSubkey;
private byte[] _sodiumDecSubkey;
@@ -25,6 +26,7 @@ namespace Shadowsocks.Encryption.AEAD
private static readonly Dictionary<string, EncryptorInfo> _ciphers = new Dictionary<string, EncryptorInfo>
{
{"chacha20-ietf-poly1305", new EncryptorInfo(32, 32, 12, 16, CIPHER_CHACHA20IETFPOLY1305)},
{"xchacha20-ietf-poly1305", new EncryptorInfo(32, 32, 24, 16, CIPHER_XCHACHA20IETFPOLY1305)},
{"aes-256-gcm", new EncryptorInfo(32, 32, 12, 16, CIPHER_AES256GCM)},
};
@@ -65,6 +67,13 @@ namespace Shadowsocks.Encryption.AEAD
null, _encNonce,
_sodiumEncSubkey);
break;
case CIPHER_XCHACHA20IETFPOLY1305:
ret = Sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(ciphertext, ref encClen,
plaintext, (ulong)plen,
null, 0,
null, _encNonce,
_sodiumEncSubkey);
break;
case CIPHER_AES256GCM:
ret = Sodium.crypto_aead_aes256gcm_encrypt(ciphertext, ref encClen,
plaintext, (ulong)plen,
@@ -99,6 +108,13 @@ namespace Shadowsocks.Encryption.AEAD
null, 0,
_decNonce, _sodiumDecSubkey);
break;
case CIPHER_XCHACHA20IETFPOLY1305:
ret = Sodium.crypto_aead_xchacha20poly1305_ietf_decrypt(plaintext, ref decPlen,
null,
ciphertext, (ulong)clen,
null, 0,
_decNonce, _sodiumDecSubkey);
break;
case CIPHER_AES256GCM:
ret = Sodium.crypto_aead_aes256gcm_decrypt(plaintext, ref decPlen,
null,


+ 3
- 2
shadowsocks-csharp/Encryption/MbedTLS.cs View File

@@ -34,7 +34,8 @@ namespace Shadowsocks.Encryption
public static byte[] MD5(byte[] input)
{
byte[] output = new byte[16];
md5(input, (uint) input.Length, output);
if (md5_ret(input, (uint) input.Length, output) != 0)
throw new System.Exception("mbedtls: MD5 failure");
return output;
}
@@ -42,7 +43,7 @@ namespace Shadowsocks.Encryption
private static extern IntPtr LoadLibrary(string path);
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void md5(byte[] input, uint ilen, byte[] output);
public static extern int md5_ret(byte[] input, uint ilen, byte[] output);
/// <summary>
/// Get cipher ctx size for unmanaged memory allocation


+ 2
- 2
shadowsocks-csharp/Encryption/OpenSSL.cs View File

@@ -13,7 +13,7 @@ namespace Shadowsocks.Encryption
// XXX: only for OpenSSL 1.1.0 and higher
public static class OpenSSL
{
private const string DLLNAME = "libcrypto-1_1.dll";
private const string DLLNAME = "libsscrypto.dll";
public const int OPENSSL_ENCRYPT = 1;
public const int OPENSSL_DECRYPT = 0;
@@ -27,7 +27,7 @@ namespace Shadowsocks.Encryption
string dllPath = Utils.GetTempPath(DLLNAME);
try
{
FileManager.UncompressFile(dllPath, Resources.libcrypto_1_1_dll);
FileManager.UncompressFile(dllPath, Resources.libsscrypto_dll);
}
catch (IOException)
{


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

@@ -73,6 +73,14 @@ namespace Shadowsocks.Encryption
public static extern int crypto_aead_chacha20poly1305_ietf_decrypt(byte[] m, ref ulong mlen_p,
byte[] nsec, byte[] c, ulong clen, byte[] ad, ulong adlen, byte[] npub, byte[] k);
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int crypto_aead_xchacha20poly1305_ietf_encrypt(byte[] c, ref ulong clen_p, byte[] m, ulong mlen,
byte[] ad, ulong adlen, byte[] nsec, byte[] npub, byte[] k);
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int crypto_aead_xchacha20poly1305_ietf_decrypt(byte[] m, ref ulong mlen_p, byte[] nsec, byte[] c,
ulong clen, byte[] ad, ulong adlen, byte[] npub, byte[] k);
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int crypto_aead_aes256gcm_encrypt(byte[] c, ref ulong clen_p, byte[] m, ulong mlen,
byte[] ad, ulong adlen, byte[] nsec, byte[] npub, byte[] k);


+ 0
- 10
shadowsocks-csharp/Properties/Resources.Designer.cs View File

@@ -100,16 +100,6 @@ namespace Shadowsocks.Properties {
}
}
/// <summary>
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>
internal static byte[] libcrypto_1_1_dll {
get {
object obj = ResourceManager.GetObject("libcrypto_1_1_dll", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// 查找 System.Byte[] 类型的本地化资源。
/// </summary>


+ 1
- 4
shadowsocks-csharp/Properties/Resources.resx View File

@@ -124,11 +124,8 @@
<data name="ja" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Data\ja.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="libcrypto_1_1_dll" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Data\libcrypto-1_1.dll.gz;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="libsscrypto_dll" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\data\libsscrypto.dll.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>..\Data\libsscrypto.dll.gz;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="mgwz_dll" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\data\mgwz.dll.gz;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>


+ 2
- 1
shadowsocks-csharp/View/ConfigForm.Designer.cs View File

@@ -252,7 +252,8 @@
"aes-128-gcm",
"aes-192-gcm",
"aes-256-gcm",
"chacha20-ietf-poly1305"});
"chacha20-ietf-poly1305",
"xchacha20-ietf-poly1305"});
this.EncryptionSelect.Location = new System.Drawing.Point(101, 109);
this.EncryptionSelect.Name = "EncryptionSelect";
this.EncryptionSelect.Size = new System.Drawing.Size(160, 20);


+ 0
- 1
shadowsocks-csharp/shadowsocks-csharp.csproj View File

@@ -253,7 +253,6 @@
<SubType>Designer</SubType>
</None>
<None Include="Data\abp.js.gz" />
<None Include="Data\libcrypto-1_1.dll.gz" />
<None Include="Data\libsscrypto.dll.gz" />
<None Include="Data\mgwz.dll.gz" />
<None Include="Data\privoxy.exe.gz" />


Loading…
Cancel
Save