Skip to content

Commit 70a88b5

Browse files
committed
🚱 Remove infrastructure of stream ciphers
1 parent 78915d8 commit 70a88b5

File tree

9 files changed

+18
-649
lines changed

9 files changed

+18
-649
lines changed

‎shadowsocks-csharp/Encryption/AEAD/AEADEncryptor.cs‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Shadowsocks.Encryption.CircularBuffer;
88
using Shadowsocks.Controller;
99
using Shadowsocks.Encryption.Exception;
10-
using Shadowsocks.Encryption.Stream;
1110

1211
namespace Shadowsocks.Encryption.AEAD
1312
{
@@ -98,7 +97,24 @@ protected void InitKey(string password)
9897

9998
public void DeriveKey(byte[] password, byte[] key, int keylen)
10099
{
101-
StreamEncryptor.LegacyDeriveKey(password, key, keylen);
100+
byte[] result = new byte[password.Length + MD5_LEN];
101+
int i = 0;
102+
byte[] md5sum = null;
103+
while (i < keylen)
104+
{
105+
if (i == 0)
106+
{
107+
md5sum = MbedTLS.MD5(password);
108+
}
109+
else
110+
{
111+
Array.Copy(md5sum, 0, result, 0, MD5_LEN);
112+
Array.Copy(password, 0, result, MD5_LEN, password.Length);
113+
md5sum = MbedTLS.MD5(result);
114+
}
115+
Array.Copy(md5sum, 0, key, i, Math.Min(MD5_LEN, keylen - i));
116+
i += MD5_LEN;
117+
}
102118
}
103119

104120
public void DeriveSessionKey(byte[] salt, byte[] masterKey, byte[] sessionKey)

‎shadowsocks-csharp/Encryption/EncryptorFactory.cs‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Reflection;
44
using System.Text;
55
using Shadowsocks.Encryption.AEAD;
6-
using Shadowsocks.Encryption.Stream;
76

87
namespace Shadowsocks.Encryption
98
{
@@ -26,27 +25,7 @@ static EncryptorFactory()
2625
{
2726
AEADSodiumEncryptorSupportedCiphers.Remove("aes-256-gcm");
2827
}
29-
#if I_KNOW_STREAM_CIPHER_IS_UNSAFE
30-
// XXX: sequence matters, OpenSSL > Sodium > MbedTLS
31-
foreach (string method in StreamOpenSSLEncryptor.SupportedCiphers())
32-
{
33-
if (!_registeredEncryptors.ContainsKey(method))
34-
_registeredEncryptors.Add(method, typeof(StreamOpenSSLEncryptor));
35-
}
36-
37-
foreach (string method in StreamSodiumEncryptor.SupportedCiphers())
38-
{
39-
if (!_registeredEncryptors.ContainsKey(method))
40-
_registeredEncryptors.Add(method, typeof(StreamSodiumEncryptor));
41-
}
4228

43-
foreach (string method in StreamMbedTLSEncryptor.SupportedCiphers())
44-
{
45-
if (!_registeredEncryptors.ContainsKey(method))
46-
_registeredEncryptors.Add(method, typeof(StreamMbedTLSEncryptor));
47-
}
48-
#endif
49-
5029
foreach (string method in AEADOpenSSLEncryptor.SupportedCiphers())
5130
{
5231
if (!_registeredEncryptors.ContainsKey(method))

‎shadowsocks-csharp/Encryption/Stream/StreamEncryptor.cs‎

Lines changed: 0 additions & 182 deletions
This file was deleted.

0 commit comments

Comments
 (0)