Refine encryption

introduce a constructor to store inner method name

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
This commit is contained in:
Syrone Wong
2016-09-28 10:46:19 +08:00
parent 4acae9de9b
commit 1dc992e806
4 changed files with 31 additions and 21 deletions
+8 -8
View File
@@ -25,9 +25,9 @@ namespace Shadowsocks.Encryption
protected bool _encryptIVSent;
protected string _method;
protected int _cipher;
// cipher name in MbedTLS, useless when using LibSodium
protected string _cipherMbedName;
protected EncryptorInfo _cipherInfo;
// internal name in the crypto library
protected string _innerLibName;
protected EncryptorInfo CipherInfo;
protected byte[] _key;
protected int keyLen;
protected int ivLen;
@@ -46,15 +46,15 @@ namespace Shadowsocks.Encryption
_method = method;
string k = method + ":" + password;
ciphers = getCiphers();
_cipherInfo = ciphers[_method];
_cipherMbedName = _cipherInfo.name;
_cipher = _cipherInfo.type;
CipherInfo = ciphers[_method];
_innerLibName = CipherInfo.InnerLibName;
_cipher = CipherInfo.Type;
if (_cipher == 0)
{
throw new Exception("method not found");
}
keyLen = _cipherInfo.key_size;
ivLen = _cipherInfo.iv_size;
keyLen = CipherInfo.KeySize;
ivLen = CipherInfo.IvSize;
_key = CachedKeys.GetOrAdd(k, (nk) =>
{
byte[] passbuf = Encoding.UTF8.GetBytes(password);