From 4c5376ce0b2db7babc2343ace74e336b9b8a3ff2 Mon Sep 17 00:00:00 2001 From: noisyfox Date: Tue, 30 Aug 2016 16:46:16 +1000 Subject: [PATCH] Remove unnecessary call to InitKey. --- shadowsocks-csharp/Encryption/IVEncryptor.cs | 8 +++----- shadowsocks-csharp/Encryption/MbedTLSEncryptor.cs | 1 - shadowsocks-csharp/Encryption/SodiumEncryptor.cs | 1 - 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/shadowsocks-csharp/Encryption/IVEncryptor.cs b/shadowsocks-csharp/Encryption/IVEncryptor.cs index e5f21717..8376073f 100755 --- a/shadowsocks-csharp/Encryption/IVEncryptor.cs +++ b/shadowsocks-csharp/Encryption/IVEncryptor.cs @@ -22,7 +22,7 @@ namespace Shadowsocks.Encryption public const int CLEN_BYTES = 2; public const int AUTH_BYTES = ONETIMEAUTH_BYTES + CLEN_BYTES; - protected static byte[] tempbuf = new byte[MAX_INPUT_SIZE]; + protected static readonly byte[] tempbuf = new byte[MAX_INPUT_SIZE]; protected Dictionary> ciphers; protected Dictionary ciphersDetail; @@ -51,7 +51,7 @@ namespace Shadowsocks.Encryption protected abstract Dictionary> getCiphers(); - protected void InitKey(string method, string password) + private void InitKey(string method, string password) { method = method.ToLower(); _method = method; @@ -71,13 +71,12 @@ namespace Shadowsocks.Encryption { byte[] passbuf = Encoding.UTF8.GetBytes(password); byte[] key = new byte[32]; - byte[] iv = new byte[16]; bytesToKey(passbuf, key); return key; }); } - protected void bytesToKey(byte[] password, byte[] key) + protected static void bytesToKey(byte[] password, byte[] key) { byte[] result = new byte[password.Length + 16]; int i = 0; @@ -239,7 +238,6 @@ namespace Shadowsocks.Encryption { randBytes(outbuf, ivLen); initCipher(outbuf, true); - outlength = length + ivLen; reactBuffer(buf, ref length); _encryptIVSent = true; lock (tempbuf) diff --git a/shadowsocks-csharp/Encryption/MbedTLSEncryptor.cs b/shadowsocks-csharp/Encryption/MbedTLSEncryptor.cs index ccbd926f..9931991d 100644 --- a/shadowsocks-csharp/Encryption/MbedTLSEncryptor.cs +++ b/shadowsocks-csharp/Encryption/MbedTLSEncryptor.cs @@ -18,7 +18,6 @@ namespace Shadowsocks.Encryption public MbedTLSEncryptor(string method, string password, bool onetimeauth, bool isudp) : base(method, password, onetimeauth, isudp) { - InitKey(method, password); } private static Dictionary> _ciphers = new Dictionary> { diff --git a/shadowsocks-csharp/Encryption/SodiumEncryptor.cs b/shadowsocks-csharp/Encryption/SodiumEncryptor.cs index ce8f55b3..476df828 100755 --- a/shadowsocks-csharp/Encryption/SodiumEncryptor.cs +++ b/shadowsocks-csharp/Encryption/SodiumEncryptor.cs @@ -22,7 +22,6 @@ namespace Shadowsocks.Encryption public SodiumEncryptor(string method, string password, bool onetimeauth, bool isudp) : base(method, password, onetimeauth, isudp) { - InitKey(method, password); } private static Dictionary> _ciphers = new Dictionary> {