- update mbedtls to 2.7.0, use new md5 api - update libsodium to 1.0.16 - static link to openssl 1.1.0g, check libsscrypto repo for detailtags/4.0.9
@@ -10,7 +10,8 @@ namespace Shadowsocks.Encryption.AEAD | |||||
: AEADEncryptor, IDisposable | : AEADEncryptor, IDisposable | ||||
{ | { | ||||
private const int CIPHER_CHACHA20IETFPOLY1305 = 1; | 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[] _sodiumEncSubkey; | ||||
private byte[] _sodiumDecSubkey; | private byte[] _sodiumDecSubkey; | ||||
@@ -25,6 +26,7 @@ namespace Shadowsocks.Encryption.AEAD | |||||
private static readonly Dictionary<string, EncryptorInfo> _ciphers = new Dictionary<string, EncryptorInfo> | private static readonly Dictionary<string, EncryptorInfo> _ciphers = new Dictionary<string, EncryptorInfo> | ||||
{ | { | ||||
{"chacha20-ietf-poly1305", new EncryptorInfo(32, 32, 12, 16, CIPHER_CHACHA20IETFPOLY1305)}, | {"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)}, | {"aes-256-gcm", new EncryptorInfo(32, 32, 12, 16, CIPHER_AES256GCM)}, | ||||
}; | }; | ||||
@@ -65,6 +67,13 @@ namespace Shadowsocks.Encryption.AEAD | |||||
null, _encNonce, | null, _encNonce, | ||||
_sodiumEncSubkey); | _sodiumEncSubkey); | ||||
break; | 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: | case CIPHER_AES256GCM: | ||||
ret = Sodium.crypto_aead_aes256gcm_encrypt(ciphertext, ref encClen, | ret = Sodium.crypto_aead_aes256gcm_encrypt(ciphertext, ref encClen, | ||||
plaintext, (ulong)plen, | plaintext, (ulong)plen, | ||||
@@ -99,6 +108,13 @@ namespace Shadowsocks.Encryption.AEAD | |||||
null, 0, | null, 0, | ||||
_decNonce, _sodiumDecSubkey); | _decNonce, _sodiumDecSubkey); | ||||
break; | 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: | case CIPHER_AES256GCM: | ||||
ret = Sodium.crypto_aead_aes256gcm_decrypt(plaintext, ref decPlen, | ret = Sodium.crypto_aead_aes256gcm_decrypt(plaintext, ref decPlen, | ||||
null, | null, | ||||
@@ -34,7 +34,8 @@ namespace Shadowsocks.Encryption | |||||
public static byte[] MD5(byte[] input) | public static byte[] MD5(byte[] input) | ||||
{ | { | ||||
byte[] output = new byte[16]; | 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; | return output; | ||||
} | } | ||||
@@ -42,7 +43,7 @@ namespace Shadowsocks.Encryption | |||||
private static extern IntPtr LoadLibrary(string path); | private static extern IntPtr LoadLibrary(string path); | ||||
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] | [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> | /// <summary> | ||||
/// Get cipher ctx size for unmanaged memory allocation | /// Get cipher ctx size for unmanaged memory allocation | ||||
@@ -13,7 +13,7 @@ namespace Shadowsocks.Encryption | |||||
// XXX: only for OpenSSL 1.1.0 and higher | // XXX: only for OpenSSL 1.1.0 and higher | ||||
public static class OpenSSL | 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_ENCRYPT = 1; | ||||
public const int OPENSSL_DECRYPT = 0; | public const int OPENSSL_DECRYPT = 0; | ||||
@@ -27,7 +27,7 @@ namespace Shadowsocks.Encryption | |||||
string dllPath = Utils.GetTempPath(DLLNAME); | string dllPath = Utils.GetTempPath(DLLNAME); | ||||
try | try | ||||
{ | { | ||||
FileManager.UncompressFile(dllPath, Resources.libcrypto_1_1_dll); | |||||
FileManager.UncompressFile(dllPath, Resources.libsscrypto_dll); | |||||
} | } | ||||
catch (IOException) | catch (IOException) | ||||
{ | { | ||||
@@ -73,6 +73,14 @@ namespace Shadowsocks.Encryption | |||||
public static extern int crypto_aead_chacha20poly1305_ietf_decrypt(byte[] m, ref ulong mlen_p, | 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); | 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)] | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] | ||||
public static extern int crypto_aead_aes256gcm_encrypt(byte[] c, ref ulong clen_p, byte[] m, ulong mlen, | 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); | byte[] ad, ulong adlen, byte[] nsec, byte[] npub, byte[] k); | ||||
@@ -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> | /// <summary> | ||||
/// 查找 System.Byte[] 类型的本地化资源。 | /// 查找 System.Byte[] 类型的本地化资源。 | ||||
/// </summary> | /// </summary> | ||||
@@ -124,11 +124,8 @@ | |||||
<data name="ja" type="System.Resources.ResXFileRef, System.Windows.Forms"> | <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> | <value>..\Data\ja.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value> | ||||
</data> | </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"> | <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> | ||||
<data name="mgwz_dll" type="System.Resources.ResXFileRef, System.Windows.Forms"> | <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> | <value>..\data\mgwz.dll.gz;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||||
@@ -252,7 +252,8 @@ | |||||
"aes-128-gcm", | "aes-128-gcm", | ||||
"aes-192-gcm", | "aes-192-gcm", | ||||
"aes-256-gcm", | "aes-256-gcm", | ||||
"chacha20-ietf-poly1305"}); | |||||
"chacha20-ietf-poly1305", | |||||
"xchacha20-ietf-poly1305"}); | |||||
this.EncryptionSelect.Location = new System.Drawing.Point(101, 109); | this.EncryptionSelect.Location = new System.Drawing.Point(101, 109); | ||||
this.EncryptionSelect.Name = "EncryptionSelect"; | this.EncryptionSelect.Name = "EncryptionSelect"; | ||||
this.EncryptionSelect.Size = new System.Drawing.Size(160, 20); | this.EncryptionSelect.Size = new System.Drawing.Size(160, 20); | ||||
@@ -253,7 +253,6 @@ | |||||
<SubType>Designer</SubType> | <SubType>Designer</SubType> | ||||
</None> | </None> | ||||
<None Include="Data\abp.js.gz" /> | <None Include="Data\abp.js.gz" /> | ||||
<None Include="Data\libcrypto-1_1.dll.gz" /> | |||||
<None Include="Data\libsscrypto.dll.gz" /> | <None Include="Data\libsscrypto.dll.gz" /> | ||||
<None Include="Data\mgwz.dll.gz" /> | <None Include="Data\mgwz.dll.gz" /> | ||||
<None Include="Data\privoxy.exe.gz" /> | <None Include="Data\privoxy.exe.gz" /> | ||||